-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #711 from stof/implement_functions
Implement global functions for the new evaluation system
- Loading branch information
Showing
16 changed files
with
2,397 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/** | ||
* SCSSPHP | ||
* | ||
* @copyright 2012-2020 Leaf Corcoran | ||
* | ||
* @license http://opensource.org/licenses/MIT MIT | ||
* | ||
* @link http://scssphp.github.io/scssphp | ||
*/ | ||
|
||
namespace ScssPhp\ScssPhp\Evaluation; | ||
|
||
use ScssPhp\ScssPhp\Deprecation; | ||
use ScssPhp\ScssPhp\SourceSpan\FileSpan; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
abstract class EvaluationContext | ||
{ | ||
private static ?EvaluationContext $evaluationContext = null; | ||
|
||
/** | ||
* The current evaluation context. | ||
* | ||
* @throws \LogicException if there isn't a Sass stylesheet currently being | ||
* evaluated. | ||
*/ | ||
public static function getCurrent(): EvaluationContext | ||
{ | ||
if (self::$evaluationContext !== null) { | ||
return self::$evaluationContext; | ||
} | ||
|
||
throw new \LogicException('No Sass stylesheet is currently being evaluated.'); | ||
} | ||
|
||
/** | ||
* Runs $callback with $context as {@see EvaluationContext::getCurrent()}. | ||
* | ||
* @template T | ||
* | ||
* @param callable(): T $callback | ||
* | ||
* @return T | ||
*/ | ||
public static function withEvaluationContext(EvaluationContext $context, callable $callback) | ||
{ | ||
$oldContext = self::$evaluationContext; | ||
self::$evaluationContext = $context; | ||
|
||
try { | ||
return $callback(); | ||
} finally { | ||
self::$evaluationContext = $oldContext; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the span for the currently executing callable. | ||
* | ||
* For normal exception reporting, this should be avoided in favor of | ||
* throwing {@see SassScriptException}s. It should only be used when calling APIs | ||
* that require spans. | ||
* | ||
* @throws \LogicException if there isn't a callable being invoked. | ||
*/ | ||
abstract public function getCurrentCallableSpan(): FileSpan; | ||
|
||
/** | ||
* Prints a warning message associated with the current `@import` or function | ||
* call. | ||
* | ||
* If $deprecation is non-null`, the warning is emitted as a deprecation | ||
* warning of that type. | ||
*/ | ||
abstract public function warn(string $message, ?Deprecation $deprecation = null): void; | ||
} |
Oops, something went wrong.