Updated SCSS compiler to v1.9

This commit is contained in:
Matias Griese
2021-12-14 17:13:12 +02:00
parent 3f39a7768d
commit de0747a41b
6 changed files with 264 additions and 75 deletions

View File

@@ -1,3 +1,9 @@
# v1.10.26
## mm/dd/2021
1. [](#new)
* Updated SCSS compiler to v1.9
# v1.10.25
## 11/16/2021

36
composer.lock generated
View File

@@ -128,16 +128,16 @@
},
{
"name": "scssphp/scssphp",
"version": "v1.8.1",
"version": "v1.9.0",
"source": {
"type": "git",
"url": "https://github.com/scssphp/scssphp.git",
"reference": "5e37759a63caf54392a4b709358a39ac7425a69f"
"reference": "bc8bece4e5e176973a832f3763049ddbba16e6fd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/scssphp/scssphp/zipball/5e37759a63caf54392a4b709358a39ac7425a69f",
"reference": "5e37759a63caf54392a4b709358a39ac7425a69f",
"url": "https://api.github.com/repos/scssphp/scssphp/zipball/bc8bece4e5e176973a832f3763049ddbba16e6fd",
"reference": "bc8bece4e5e176973a832f3763049ddbba16e6fd",
"shasum": ""
},
"require": {
@@ -196,9 +196,9 @@
],
"support": {
"issues": "https://github.com/scssphp/scssphp/issues",
"source": "https://github.com/scssphp/scssphp/tree/v1.8.1"
"source": "https://github.com/scssphp/scssphp/tree/v1.9.0"
},
"time": "2021-09-18T21:20:53+00:00"
"time": "2021-12-13T11:55:16+00:00"
}
],
"packages-dev": [
@@ -1227,16 +1227,16 @@
},
{
"name": "phpspec/prophecy",
"version": "1.14.0",
"version": "v1.15.0",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e"
"reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
"reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13",
"reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13",
"shasum": ""
},
"require": {
@@ -1288,9 +1288,9 @@
],
"support": {
"issues": "https://github.com/phpspec/prophecy/issues",
"source": "https://github.com/phpspec/prophecy/tree/1.14.0"
"source": "https://github.com/phpspec/prophecy/tree/v1.15.0"
},
"time": "2021-09-10T09:02:12+00:00"
"time": "2021-12-08T12:19:24+00:00"
},
{
"name": "phpunit/php-code-coverage",
@@ -1361,16 +1361,16 @@
},
{
"name": "phpunit/php-file-iterator",
"version": "2.0.4",
"version": "2.0.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "28af674ff175d0768a5a978e6de83f697d4a7f05"
"reference": "42c5ba5220e6904cbfe8b1a1bda7c0cfdc8c12f5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/28af674ff175d0768a5a978e6de83f697d4a7f05",
"reference": "28af674ff175d0768a5a978e6de83f697d4a7f05",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/42c5ba5220e6904cbfe8b1a1bda7c0cfdc8c12f5",
"reference": "42c5ba5220e6904cbfe8b1a1bda7c0cfdc8c12f5",
"shasum": ""
},
"require": {
@@ -1409,7 +1409,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
"source": "https://github.com/sebastianbergmann/php-file-iterator/tree/2.0.4"
"source": "https://github.com/sebastianbergmann/php-file-iterator/tree/2.0.5"
},
"funding": [
{
@@ -1417,7 +1417,7 @@
"type": "github"
}
],
"time": "2021-07-19T06:46:01+00:00"
"time": "2021-12-02T12:42:26+00:00"
},
{
"name": "phpunit/php-text-template",

View File

@@ -128,17 +128,17 @@
},
{
"name": "scssphp/scssphp",
"version": "v1.8.1",
"version_normalized": "1.8.1.0",
"version": "v1.9.0",
"version_normalized": "1.9.0.0",
"source": {
"type": "git",
"url": "https://github.com/scssphp/scssphp.git",
"reference": "5e37759a63caf54392a4b709358a39ac7425a69f"
"reference": "bc8bece4e5e176973a832f3763049ddbba16e6fd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/scssphp/scssphp/zipball/5e37759a63caf54392a4b709358a39ac7425a69f",
"reference": "5e37759a63caf54392a4b709358a39ac7425a69f",
"url": "https://api.github.com/repos/scssphp/scssphp/zipball/bc8bece4e5e176973a832f3763049ddbba16e6fd",
"reference": "bc8bece4e5e176973a832f3763049ddbba16e6fd",
"shasum": ""
},
"require": {
@@ -161,7 +161,7 @@
"ext-iconv": "Can be used as fallback when ext-mbstring is not available",
"ext-mbstring": "For best performance, mbstring should be installed as it is faster than ext-iconv"
},
"time": "2021-09-18T21:20:53+00:00",
"time": "2021-12-13T11:55:16+00:00",
"bin": [
"bin/pscss"
],
@@ -199,7 +199,7 @@
],
"support": {
"issues": "https://github.com/scssphp/scssphp/issues",
"source": "https://github.com/scssphp/scssphp/tree/v1.8.1"
"source": "https://github.com/scssphp/scssphp/tree/v1.9.0"
},
"install-path": "../scssphp/scssphp"
}

View File

@@ -5,7 +5,7 @@
'type' => 'grav-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '31ffe6574e13028e9bd1717bd63a6b589434de21',
'reference' => '3f39a7768da93e73acd1116389392478e93c0bd4',
'name' => 'getgrav/grav-plugin-admin',
'dev' => false,
),
@@ -16,7 +16,7 @@
'type' => 'grav-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '31ffe6574e13028e9bd1717bd63a6b589434de21',
'reference' => '3f39a7768da93e73acd1116389392478e93c0bd4',
'dev_requirement' => false,
),
'laminas/laminas-xml' => array(
@@ -44,12 +44,12 @@
'dev_requirement' => false,
),
'scssphp/scssphp' => array(
'pretty_version' => 'v1.8.1',
'version' => '1.8.1.0',
'pretty_version' => 'v1.9.0',
'version' => '1.9.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../scssphp/scssphp',
'aliases' => array(),
'reference' => '5e37759a63caf54392a4b709358a39ac7425a69f',
'reference' => 'bc8bece4e5e176973a832f3763049ddbba16e6fd',
'dev_requirement' => false,
),
'symfony/polyfill-php72' => array(

View File

@@ -137,6 +137,7 @@ class Compiler
public static $emptyString = [Type::T_STRING, '"', []];
public static $with = [Type::T_KEYWORD, 'with'];
public static $without = [Type::T_KEYWORD, 'without'];
private static $emptyArgumentList = [Type::T_LIST, '', [], []];
/**
* @var array<int, string|callable>
@@ -1587,6 +1588,8 @@ class Compiler
* @param array $withCondition
*
* @return array
*
* @phpstan-return array{array<string, bool>, array<string, bool>}
*/
protected function compileWith($withCondition)
{
@@ -1606,9 +1609,10 @@ class Compiler
}
}
if ($this->mapHasKey($withCondition, static::$with)) {
$withConfig = $this->mapGet($withCondition, static::$with);
if ($withConfig !== null) {
$without = []; // cancel the default
$list = $this->coerceList($this->libMapGet([$withCondition, static::$with]));
$list = $this->coerceList($withConfig);
foreach ($list[2] as $item) {
$keyword = $this->compileStringContent($this->coerceString($item));
@@ -1617,9 +1621,10 @@ class Compiler
}
}
if ($this->mapHasKey($withCondition, static::$without)) {
$withoutConfig = $this->mapGet($withCondition, static::$without);
if ($withoutConfig !== null) {
$without = []; // cancel the default
$list = $this->coerceList($this->libMapGet([$withCondition, static::$without]));
$list = $this->coerceList($withoutConfig);
foreach ($list[2] as $item) {
$keyword = $this->compileStringContent($this->coerceString($item));
@@ -6929,14 +6934,18 @@ EOL;
}
/**
* Coerce something to map
* Tries to convert an item to a Sass map
*
* @param array|Number $item
* @param Number|array $item
*
* @return array|Number
* @return array|null
*/
protected function coerceMap($item)
private function tryMap($item)
{
if ($item instanceof Number) {
return null;
}
if ($item[0] === Type::T_MAP) {
return $item;
}
@@ -6948,6 +6957,24 @@ EOL;
return static::$emptyMap;
}
return null;
}
/**
* Coerce something to map
*
* @param array|Number $item
*
* @return array|Number
*/
protected function coerceMap($item)
{
$map = $this->tryMap($item);
if ($map !== null) {
return $map;
}
return $item;
}
@@ -6984,18 +7011,6 @@ EOL;
$key = $keys[$i];
$value = $values[$i];
switch ($key[0]) {
case Type::T_LIST:
case Type::T_MAP:
case Type::T_STRING:
case Type::T_NULL:
break;
default:
$key = [Type::T_KEYWORD, $this->compileStringContent($this->coerceString($key))];
break;
}
$list[] = [
Type::T_LIST,
'',
@@ -7294,15 +7309,15 @@ EOL;
*/
public function assertMap($value, $varName = null)
{
$value = $this->coerceMap($value);
$map = $this->tryMap($value);
if ($value[0] !== Type::T_MAP) {
if ($map === null) {
$value = $this->compileValue($value);
throw SassScriptException::forArgument("$value is not a map.", $varName);
}
return $value;
return $map;
}
/**
@@ -8696,23 +8711,72 @@ will be an error in future versions of Sass.\n on line $line of $fname";
return $list;
}
protected static $libMapGet = ['map', 'key'];
protected static $libMapGet = ['map', 'key', 'keys...'];
protected function libMapGet($args)
{
$map = $this->assertMap($args[0], 'map');
$key = $args[1];
if (!isset($args[2])) {
// BC layer for usages of the function from PHP code rather than from the Sass function
$args[2] = self::$emptyArgumentList;
}
$keys = array_merge([$args[1]], $args[2][2]);
$value = static::$null;
if (! \is_null($key)) {
$key = $this->compileStringContent($this->coerceString($key));
foreach ($keys as $key) {
if (!\is_array($map) || $map[0] !== Type::T_MAP) {
return static::$null;
}
for ($i = \count($map[1]) - 1; $i >= 0; $i--) {
if ($key === $this->compileStringContent($this->coerceString($map[1][$i]))) {
return $map[2][$i];
}
$map = $this->mapGet($map, $key);
if ($map === null) {
return static::$null;
}
$value = $map;
}
return $value;
}
/**
* Gets the value corresponding to that key in the map
*
* @param array $map
* @param Number|array $key
*
* @return Number|array|null
*/
private function mapGet(array $map, $key)
{
$index = $this->mapGetEntryIndex($map, $key);
if ($index !== null) {
return $map[2][$index];
}
return null;
}
/**
* Gets the index corresponding to that key in the map entries
*
* @param array $map
* @param Number|array $key
*
* @return int|null
*/
private function mapGetEntryIndex(array $map, $key)
{
$key = $this->compileStringContent($this->coerceString($key));
for ($i = \count($map[1]) - 1; $i >= 0; $i--) {
if ($key === $this->compileStringContent($this->coerceString($map[1][$i]))) {
return $i;
}
}
return static::$null;
return null;
}
protected static $libMapKeys = ['map'];
@@ -8762,12 +8826,28 @@ will be an error in future versions of Sass.\n on line $line of $fname";
return $map;
}
protected static $libMapHasKey = ['map', 'key'];
protected static $libMapHasKey = ['map', 'key', 'keys...'];
protected function libMapHasKey($args)
{
$map = $this->assertMap($args[0], 'map');
if (!isset($args[2])) {
// BC layer for usages of the function from PHP code rather than from the Sass function
$args[2] = self::$emptyArgumentList;
}
$keys = array_merge([$args[1]], $args[2][2]);
$lastKey = array_pop($keys);
return $this->toBool($this->mapHasKey($map, $args[1]));
foreach ($keys as $key) {
$value = $this->mapGet($map, $key);
if ($value === null || $value instanceof Number || $value[0] !== Type::T_MAP) {
return self::$false;
}
$map = $value;
}
return $this->toBool($this->mapHasKey($map, $lastKey));
}
/**
@@ -8790,24 +8870,127 @@ will be an error in future versions of Sass.\n on line $line of $fname";
protected static $libMapMerge = [
['map1', 'map2'],
['map-1', 'map-2']
['map-1', 'map-2'],
['map1', 'args...']
];
protected function libMapMerge($args)
{
$map1 = $this->assertMap($args[0], 'map1');
$map2 = $this->assertMap($args[1], 'map2');
$map2 = $args[1];
$keys = [];
if ($map2[0] === Type::T_LIST && isset($map2[3]) && \is_array($map2[3])) {
// This is an argument list for the variadic signature
if (\count($map2[2]) === 0) {
throw new SassScriptException('Expected $args to contain a key.');
}
if (\count($map2[2]) === 1) {
throw new SassScriptException('Expected $args to contain a value.');
}
$keys = $map2[2];
$map2 = array_pop($keys);
}
$map2 = $this->assertMap($map2, 'map2');
foreach ($map2[1] as $i2 => $key2) {
$key = $this->compileStringContent($this->coerceString($key2));
return $this->modifyMap($map1, $keys, function ($oldValue) use ($map2) {
$nestedMap = $this->tryMap($oldValue);
foreach ($map1[1] as $i1 => $key1) {
if ($key === $this->compileStringContent($this->coerceString($key1))) {
$map1[2][$i1] = $map2[2][$i2];
continue 2;
}
if ($nestedMap === null) {
return $map2;
}
$map1[1][] = $map2[1][$i2];
return $this->mergeMaps($nestedMap, $map2);
});
}
/**
* @param array $map
* @param array $keys
* @param callable $modify
* @param bool $addNesting
*
* @return Number|array
*
* @phpstan-param array<Number|array> $keys
* @phpstan-param callable(Number|array): (Number|array) $modify
*/
private function modifyMap(array $map, array $keys, callable $modify, $addNesting = true)
{
if ($keys === []) {
return $modify($map);
}
return $this->modifyNestedMap($map, $keys, $modify, $addNesting);
}
/**
* @param array $map
* @param array $keys
* @param callable $modify
* @param bool $addNesting
*
* @return array
*
* @phpstan-param non-empty-array<Number|array> $keys
* @phpstan-param callable(Number|array): (Number|array) $modify
*/
private function modifyNestedMap(array $map, array $keys, callable $modify, $addNesting)
{
$key = array_shift($keys);
$nestedValueIndex = $this->mapGetEntryIndex($map, $key);
if ($keys === []) {
if ($nestedValueIndex !== null) {
$map[2][$nestedValueIndex] = $modify($map[2][$nestedValueIndex]);
} else {
$map[1][] = $key;
$map[2][] = $modify(self::$null);
}
return $map;
}
$nestedMap = $nestedValueIndex !== null ? $this->tryMap($map[2][$nestedValueIndex]) : null;
if ($nestedMap === null && !$addNesting) {
return $map;
}
if ($nestedMap === null) {
$nestedMap = self::$emptyMap;
}
$newNestedMap = $this->modifyNestedMap($nestedMap, $keys, $modify, $addNesting);
if ($nestedValueIndex !== null) {
$map[2][$nestedValueIndex] = $newNestedMap;
} else {
$map[1][] = $key;
$map[2][] = $newNestedMap;
}
return $map;
}
/**
* Merges 2 Sass maps together
*
* @param array $map1
* @param array $map2
*
* @return array
*/
private function mergeMaps(array $map1, array $map2)
{
foreach ($map2[1] as $i2 => $key2) {
$map1EntryIndex = $this->mapGetEntryIndex($map1, $key2);
if ($map1EntryIndex !== null) {
$map1[2][$map1EntryIndex] = $map2[2][$i2];
continue;
}
$map1[1][] = $key2;
$map1[2][] = $map2[2][$i2];
}

View File

@@ -19,5 +19,5 @@ namespace ScssPhp\ScssPhp;
*/
class Version
{
const VERSION = '1.8.1';
const VERSION = '1.9.0';
}