Skip to content

Commit

Permalink
Update scssphp 1.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
crftwrk committed Feb 21, 2024
1 parent ab0e12f commit d9e1a96
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
3 changes: 2 additions & 1 deletion inc/scssphp/src/Block/CallableBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use ScssPhp\ScssPhp\Block;
use ScssPhp\ScssPhp\Compiler\Environment;
use ScssPhp\ScssPhp\Node\Number;

/**
* @internal
Expand All @@ -26,7 +27,7 @@ class CallableBlock extends Block
public $name;

/**
* @var array|null
* @var list<array{string, array|Number|null, bool}>|null
*/
public $args;

Expand Down
41 changes: 22 additions & 19 deletions inc/scssphp/src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ public function compileString($source, $path = null)

$sourceMap = null;

if (! empty($out) && $this->sourceMap && $this->sourceMap !== self::SOURCE_MAP_NONE) {
if (! empty($out) && $this->sourceMap !== self::SOURCE_MAP_NONE && $this->sourceMap) {
assert($sourceMapGenerator !== null);
$sourceMap = $sourceMapGenerator->generateJson($prefix);
$sourceMapUrl = null;
Expand Down Expand Up @@ -5841,13 +5841,13 @@ public function findImport($url, $currentDir = null)

if (! \is_null($file)) {
if (\is_array($dir)) {
$callableDescription = (\is_object($dir[0]) ? \get_class($dir[0]) : $dir[0]).'::'.$dir[1];
$callableDescription = (\is_object($dir[0]) ? \get_class($dir[0]) : $dir[0]) . '::' . $dir[1];
} elseif ($dir instanceof \Closure) {
$r = new \ReflectionFunction($dir);
if (false !== strpos($r->name, '{closure}')) {
$callableDescription = sprintf('closure{%s:%s}', $r->getFileName(), $r->getStartLine());
} elseif ($class = $r->getClosureScopeClass()) {
$callableDescription = $class->name.'::'.$r->name;
$callableDescription = $class->name . '::' . $r->name;
} else {
$callableDescription = $r->name;
}
Expand Down Expand Up @@ -5960,15 +5960,15 @@ private function checkImportPathConflicts(array $paths)
private function tryImportPathWithExtensions($path)
{
$result = array_merge(
$this->tryImportPath($path.'.sass'),
$this->tryImportPath($path.'.scss')
$this->tryImportPath($path . '.sass'),
$this->tryImportPath($path . '.scss')
);

if ($result) {
return $result;
}

return $this->tryImportPath($path.'.css');
return $this->tryImportPath($path . '.css');
}

/**
Expand All @@ -5978,7 +5978,7 @@ private function tryImportPathWithExtensions($path)
*/
private function tryImportPath($path)
{
$partial = dirname($path).'/_'.basename($path);
$partial = dirname($path) . '/_' . basename($path);

$candidates = [];

Expand All @@ -6004,7 +6004,7 @@ private function tryImportPathAsDirectory($path)
return null;
}

return $this->checkImportPathConflicts($this->tryImportPathWithExtensions($path.'/index'));
return $this->checkImportPathConflicts($this->tryImportPathWithExtensions($path . '/index'));
}

/**
Expand All @@ -6019,7 +6019,7 @@ private function getPrettyPath($path)
}

$normalizedPath = $path;
$normalizedRootDirectory = $this->rootDirectory.'/';
$normalizedRootDirectory = $this->rootDirectory . '/';

if (\DIRECTORY_SEPARATOR === '\\') {
$normalizedRootDirectory = str_replace('\\', '/', $normalizedRootDirectory);
Expand Down Expand Up @@ -6406,8 +6406,6 @@ public static function isNativeFunction($name)
*/
protected function sortNativeFunctionArgs($functionName, $prototypes, $args)
{
static $parser = null;

if (! isset($prototypes)) {
$keyArgs = [];
$posArgs = [];
Expand Down Expand Up @@ -6561,7 +6559,7 @@ private function parseFunctionPrototype(array $prototype)
*
* @return array
*
* @phpstan-param non-empty-list<array{arguments: list<array{0: string, 1: string, 2: array|Number|null}>, rest_argument: string|null}> $prototypes
* @phpstan-param non-empty-array<array{arguments: list<array{0: string, 1: string, 2: array|Number|null}>, rest_argument: string|null}> $prototypes
* @phpstan-return array{arguments: list<array{0: string, 1: string, 2: array|Number|null}>, rest_argument: string|null}
*/
private function selectFunctionPrototype(array $prototypes, $positional, array $names)
Expand Down Expand Up @@ -7714,9 +7712,9 @@ private function HWBtoRGB($hue, $whiteness, $blackness)
$b = min(1.0 - $w, $b);

$rgb = $this->toRGB($hue, 100, 50);
for($i = 1; $i < 4; $i++) {
$rgb[$i] *= (1.0 - $w - $b);
$rgb[$i] = round($rgb[$i] + 255 * $w + 0.0001);
for ($i = 1; $i < 4; $i++) {
$rgb[$i] *= (1.0 - $w - $b);
$rgb[$i] = round($rgb[$i] + 255 * $w + 0.0001);
}

return $rgb;
Expand All @@ -7743,7 +7741,6 @@ private function RGBtoHWB($red, $green, $blue)
if ((int) $d === 0) {
$h = 0;
} else {

if ($red == $max) {
$h = 60 * ($green - $blue) / $d;
} elseif ($green == $max) {
Expand All @@ -7753,7 +7750,7 @@ private function RGBtoHWB($red, $green, $blue)
}
}

return [Type::T_HWB, fmod($h, 360), $min / 255 * 100, 100 - $max / 255 *100];
return [Type::T_HWB, fmod($h, 360), $min / 255 * 100, 100 - $max / 255 * 100];
}


Expand Down Expand Up @@ -7962,7 +7959,13 @@ protected function alterColor(array $args, $operation, $fn)
$scale = $operation === 'scale';
$change = $operation === 'change';

/** @phpstan-var callable(string, float|int, bool=, bool=): (float|int|null) $getParam */
/**
* @param string $name
* @param float|int $max
* @param bool $checkPercent
* @param bool $assertPercent
* @return float|int|null
*/
$getParam = function ($name, $max, $checkPercent = false, $assertPercent = false) use (&$kwargs, $scale, $change) {
if (!isset($kwargs[$name])) {
return null;
Expand Down Expand Up @@ -8104,7 +8107,7 @@ protected function libAdjustColor($args)
protected static $libChangeColor = ['color', 'kwargs...'];
protected function libChangeColor($args)
{
return $this->alterColor($args,'change', function ($base, $alter, $max) {
return $this->alterColor($args, 'change', function ($base, $alter, $max) {
if ($alter === null) {
return $base;
}
Expand Down
18 changes: 14 additions & 4 deletions inc/scssphp/src/Node/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @template-implements \ArrayAccess<int, mixed>
*/
class Number extends Node implements \ArrayAccess
class Number extends Node implements \ArrayAccess, \JsonSerializable
{
const PRECISION = 10;

Expand Down Expand Up @@ -131,21 +131,31 @@ public function getDimension()
}

/**
* @return string[]
* @return list<string>
*/
public function getNumeratorUnits()
{
return $this->numeratorUnits;
}

/**
* @return string[]
* @return list<string>
*/
public function getDenominatorUnits()
{
return $this->denominatorUnits;
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
// Passing a compiler instance makes the method output a Sass representation instead of a CSS one, supporting full units.
return $this->output(new Compiler());
}

/**
* @return bool
*/
Expand Down Expand Up @@ -554,7 +564,7 @@ public function equals(Number $other)

try {
return $this->coerceUnits($other, function ($num1, $num2) {
return round($num1,self::PRECISION) == round($num2, self::PRECISION);
return round($num1, self::PRECISION) == round($num2, self::PRECISION);
});
} catch (SassScriptException $e) {
return false;
Expand Down
3 changes: 3 additions & 0 deletions inc/scssphp/src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,13 @@ public function parseMediaQueryList($buffer, &$out)
$this->inParens = false;
$this->eatWhiteDefault = true;
$this->buffer = (string) $buffer;
$this->discardComments = true;

$this->saveEncoding();
$this->extractLineNumbers($this->buffer);

$this->whitespace();

$isMediaQuery = $this->mediaQueryList($out);

$this->restoreEncoding();
Expand Down
2 changes: 1 addition & 1 deletion inc/scssphp/src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
*/
class Version
{
const VERSION = '1.12.0';
const VERSION = '1.12.1';
}

0 comments on commit d9e1a96

Please sign in to comment.