N°2696 - Upgrade SCSSPHP to v1.0.6 (PHP 7.4 compatibility)

This commit is contained in:
Molkobain
2020-01-14 09:48:43 +01:00
parent 460836852e
commit cc887c29fd
20 changed files with 2233 additions and 1029 deletions

View File

@@ -14,7 +14,7 @@
"nikic/php-parser": "^3.1",
"pear/archive_tar": "1.4.7",
"pelago/emogrifier": "2.1.0",
"scssphp/scssphp": "1.0.0",
"scssphp/scssphp": "1.0.6",
"swiftmailer/swiftmailer": "5.4.12",
"symfony/console": "3.4.*",
"symfony/dotenv": "3.4.*",

18
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "fad30bc7d8ddf9c9cb9c70ab7c3ce385",
"content-hash": "fa67ef7539c664354f726be04d0d044c",
"packages": [
{
"name": "combodo/tcpdf",
@@ -639,23 +639,25 @@
},
{
"name": "scssphp/scssphp",
"version": "1.0.0",
"version": "1.0.6",
"source": {
"type": "git",
"url": "https://github.com/scssphp/scssphp.git",
"reference": "6c8734b6edcf6c2fa785ad874b998fa854a7d030"
"reference": "5b3c9d704950d8f9637f5110c36c281ec47dc13c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/scssphp/scssphp/zipball/6c8734b6edcf6c2fa785ad874b998fa854a7d030",
"reference": "6c8734b6edcf6c2fa785ad874b998fa854a7d030",
"url": "https://api.github.com/repos/scssphp/scssphp/zipball/5b3c9d704950d8f9637f5110c36c281ec47dc13c",
"reference": "5b3c9d704950d8f9637f5110c36c281ec47dc13c",
"shasum": ""
},
"require": {
"php": "^5.6.0 || ^7"
"ext-ctype": "*",
"ext-json": "*",
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "~4.6",
"phpunit/phpunit": "^5.7 || ^6.5 || ^7.5 || ^8.3",
"squizlabs/php_codesniffer": "~2.5",
"twbs/bootstrap": "~4.3",
"zurb/foundation": "~6.5"
@@ -694,7 +696,7 @@
"scss",
"stylesheet"
],
"time": "2019-06-05T01:22:01+00:00"
"time": "2019-12-12T05:00:52+00:00"
},
{
"name": "swiftmailer/swiftmailer",

View File

@@ -2,9 +2,13 @@
dir=$(cd "${0%[/\\]*}" > /dev/null; cd "../scssphp/scssphp/bin" && pwd)
if [ -d /proc/cygdrive ] && [[ $(which php) == $(readlink -n /proc/cygdrive)/* ]]; then
# We are in Cgywin using Windows php, so the path must be translated
dir=$(cygpath -m "$dir");
if [ -d /proc/cygdrive ]; then
case $(which php) in
$(readlink -n /proc/cygdrive)/*)
# We are in Cygwin using Windows php, so the path must be translated
dir=$(cygpath -m "$dir");
;;
esac
fi
"${dir}/pscss" "$@"

View File

@@ -656,7 +656,6 @@ return array(
'ScssPhp\\ScssPhp\\Parser' => $vendorDir . '/scssphp/scssphp/src/Parser.php',
'ScssPhp\\ScssPhp\\SourceMap\\Base64' => $vendorDir . '/scssphp/scssphp/src/SourceMap/Base64.php',
'ScssPhp\\ScssPhp\\SourceMap\\Base64VLQ' => $vendorDir . '/scssphp/scssphp/src/SourceMap/Base64VLQ.php',
'ScssPhp\\ScssPhp\\SourceMap\\Base64VLQEncoder' => $vendorDir . '/scssphp/scssphp/src/SourceMap/Base64VLQEncoder.php',
'ScssPhp\\ScssPhp\\SourceMap\\SourceMapGenerator' => $vendorDir . '/scssphp/scssphp/src/SourceMap/SourceMapGenerator.php',
'ScssPhp\\ScssPhp\\Type' => $vendorDir . '/scssphp/scssphp/src/Type.php',
'ScssPhp\\ScssPhp\\Util' => $vendorDir . '/scssphp/scssphp/src/Util.php',

View File

@@ -886,7 +886,6 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b
'ScssPhp\\ScssPhp\\Parser' => __DIR__ . '/..' . '/scssphp/scssphp/src/Parser.php',
'ScssPhp\\ScssPhp\\SourceMap\\Base64' => __DIR__ . '/..' . '/scssphp/scssphp/src/SourceMap/Base64.php',
'ScssPhp\\ScssPhp\\SourceMap\\Base64VLQ' => __DIR__ . '/..' . '/scssphp/scssphp/src/SourceMap/Base64VLQ.php',
'ScssPhp\\ScssPhp\\SourceMap\\Base64VLQEncoder' => __DIR__ . '/..' . '/scssphp/scssphp/src/SourceMap/Base64VLQEncoder.php',
'ScssPhp\\ScssPhp\\SourceMap\\SourceMapGenerator' => __DIR__ . '/..' . '/scssphp/scssphp/src/SourceMap/SourceMapGenerator.php',
'ScssPhp\\ScssPhp\\Type' => __DIR__ . '/..' . '/scssphp/scssphp/src/Type.php',
'ScssPhp\\ScssPhp\\Util' => __DIR__ . '/..' . '/scssphp/scssphp/src/Util.php',

View File

@@ -656,29 +656,31 @@
},
{
"name": "scssphp/scssphp",
"version": "1.0.0",
"version_normalized": "1.0.0.0",
"version": "1.0.6",
"version_normalized": "1.0.6.0",
"source": {
"type": "git",
"url": "https://github.com/scssphp/scssphp.git",
"reference": "6c8734b6edcf6c2fa785ad874b998fa854a7d030"
"reference": "5b3c9d704950d8f9637f5110c36c281ec47dc13c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/scssphp/scssphp/zipball/6c8734b6edcf6c2fa785ad874b998fa854a7d030",
"reference": "6c8734b6edcf6c2fa785ad874b998fa854a7d030",
"url": "https://api.github.com/repos/scssphp/scssphp/zipball/5b3c9d704950d8f9637f5110c36c281ec47dc13c",
"reference": "5b3c9d704950d8f9637f5110c36c281ec47dc13c",
"shasum": ""
},
"require": {
"php": "^5.6.0 || ^7"
"ext-ctype": "*",
"ext-json": "*",
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "~4.6",
"phpunit/phpunit": "^5.7 || ^6.5 || ^7.5 || ^8.3",
"squizlabs/php_codesniffer": "~2.5",
"twbs/bootstrap": "~4.3",
"zurb/foundation": "~6.5"
},
"time": "2019-06-05T01:22:01+00:00",
"time": "2019-12-12T05:00:52+00:00",
"bin": [
"bin/pscss"
],

View File

@@ -2,7 +2,7 @@
### <http://scssphp.github.io/scssphp>
[![Build](https://travis-ci.org/scssphp/scssphp.svg?branch=master)](http://travis-ci.org/scssphp/scssphp)
[![License](https://poser.pugx.org/scssphp/scssphp/license.svg)](https://packagist.org/packages/scssphp/scssphp)
[![License](https://poser.pugx.org/scssphp/scssphp/license)](https://packagist.org/packages/scssphp/scssphp)
`scssphp` is a compiler for SCSS written in PHP.

View File

@@ -12,8 +12,8 @@
error_reporting(E_ALL);
if (version_compare(PHP_VERSION, '5.4') < 0) {
die('Requires PHP 5.4 or above');
if (version_compare(PHP_VERSION, '5.6') < 0) {
die('Requires PHP 5.6 or above');
}
include __DIR__ . '/../scss.inc.php';
@@ -62,7 +62,7 @@ function parseArgument(&$i, $options) {
}
for ($i = 1; $i < $argc; $i++) {
if ($argv[$i] === '-h' || $argv[$i] === '--help') {
if ($argv[$i] === '-?' || $argv[$i] === '-h' || $argv[$i] === '--help') {
$exe = $argv[0];
$HELP = <<<EOT
@@ -70,17 +70,17 @@ Usage: $exe [options] [input-file]
Options include:
-h, --help Show this message
--help Show this message [-h, -?]
--continue-on-error Continue compilation (as best as possible) when error encountered
--debug-info Annotate selectors with CSS referring to the source file and line number
-f=format Set the output format (compact, compressed, crunched, expanded, or nested)
-i=path Set import path
--iso8859-1 Use iso8859-1 encoding instead of utf-8 (default utf-8)
--line-numbers Annotate selectors with comments referring to the source file and line number
-p=precision Set decimal number precision (default 10)
--debug-info Annotate selectors with CSS referring to the source file and line number [-g]
--dump-tree Dump formatted parse tree [-T]
--iso8859-1 Use iso8859-1 encoding instead of default utf-8
--line-numbers Annotate selectors with comments referring to the source file and line number [--line-comments]
--load-path=PATH Set import path [-I]
--precision=N Set decimal number precision (default 10) [-p]
--sourcemap Create source map file
-T Dump formatted parse tree
-v, --version Print the version
--style=FORMAT Set the output format (compact, compressed, crunched, expanded, or nested) [-s, -t]
--version Print the version [-v]
EOT;
exit($HELP);
@@ -95,7 +95,7 @@ EOT;
continue;
}
if ($argv[$i] === '--debug-info') {
if ($argv[$i] === '-g' || $argv[$i] === '--debug-info') {
$debugInfo = true;
continue;
}
@@ -115,19 +115,19 @@ EOT;
continue;
}
if ($argv[$i] === '-T') {
if ($argv[$i] === '-T' || $argv[$i] === '--dump-tree') {
$dumpTree = true;
continue;
}
$value = parseArgument($i, array('-f', '--style'));
$value = parseArgument($i, array('-t', '-s', '--style'));
if (isset($value)) {
$style = $value;
continue;
}
$value = parseArgument($i, array('-i', '--load_paths'));
$value = parseArgument($i, array('-I', '--load-path'));
if (isset($value)) {
$loadPaths = $value;

View File

@@ -23,17 +23,20 @@
"psr-4": { "ScssPhp\\ScssPhp\\": "src/" }
},
"autoload-dev": {
"psr-4": { "ScssPhp\\ScssPhp\\Test\\": "tests/" }
"psr-4": { "ScssPhp\\ScssPhp\\Tests\\": "tests/" }
},
"require": {
"php": "^5.6.0 || ^7"
"php": ">=5.6.0",
"ext-json": "*",
"ext-ctype": "*"
},
"require-dev": {
"squizlabs/php_codesniffer": "~2.5",
"phpunit/phpunit": "~4.6",
"phpunit/phpunit": "^5.7 || ^6.5 || ^7.5 || ^8.3",
"twbs/bootstrap": "~4.3",
"zurb/foundation": "~6.5"
},
"minimum-stability": "dev",
"bin": ["bin/pscss"],
"archive": {
"exclude": [

View File

@@ -32,7 +32,7 @@ use Exception;
*/
class Cache
{
const CACHE_VERSION = 0;
const CACHE_VERSION = 1;
// directory used for storing data
public static $cacheDir = false;
@@ -41,12 +41,12 @@ class Cache
public static $prefix = 'scssphp_';
// force a refresh : 'once' for refreshing the first hit on a cache only, true to never use the cache in this hit
public static $forceFefresh = false;
public static $forceRefresh = false;
// specifies the number of seconds after which data cached will be seen as 'garbage' and potentially cleaned up
public static $gcLifetime = 604800;
// array of already refreshed cache if $forceFefresh==='once'
// array of already refreshed cache if $forceRefresh==='once'
protected static $refreshed = [];
/**
@@ -57,12 +57,12 @@ class Cache
public function __construct($options)
{
// check $cacheDir
if (isset($options['cache_dir'])) {
self::$cacheDir = $options['cache_dir'];
if (isset($options['cacheDir'])) {
self::$cacheDir = $options['cacheDir'];
}
if (empty(self::$cacheDir)) {
throw new Exception('cache_dir not set');
throw new Exception('cacheDir not set');
}
if (isset($options['prefix'])) {
@@ -74,7 +74,7 @@ class Cache
}
if (isset($options['forceRefresh'])) {
self::$forceFefresh = $options['force_refresh'];
self::$forceRefresh = $options['forceRefresh'];
}
self::checkCacheDir();
@@ -97,13 +97,13 @@ class Cache
{
$fileCache = self::$cacheDir . self::cacheName($operation, $what, $options);
if ((! self::$forceRefresh || (self::$forceRefresh === 'once' && isset(self::$refreshed[$fileCache])))
&& file_exists($fileCache)
if (((self::$forceRefresh === false) || (self::$forceRefresh === 'once' &&
isset(self::$refreshed[$fileCache]))) && file_exists($fileCache)
) {
$cacheTime = filemtime($fileCache);
if ((is_null($lastModified) || $cacheTime > $lastModified)
&& $cacheTime + self::$gcLifetime > time()
if ((is_null($lastModified) || $cacheTime > $lastModified) &&
$cacheTime + self::$gcLifetime > time()
) {
$c = file_get_contents($fileCache);
$c = unserialize($c);
@@ -176,13 +176,13 @@ class Cache
self::$cacheDir = str_replace('\\', '/', self::$cacheDir);
self::$cacheDir = rtrim(self::$cacheDir, '/') . '/';
if (! file_exists(self::$cacheDir)) {
if (! is_dir(self::$cacheDir)) {
if (! mkdir(self::$cacheDir)) {
throw new Exception('Cache directory couldn\'t be created: ' . self::$cacheDir);
}
} elseif (! is_dir(self::$cacheDir)) {
throw new Exception('Cache directory doesn\'t exist: ' . self::$cacheDir);
} elseif (! is_writable(self::$cacheDir)) {
}
if (! is_writable(self::$cacheDir)) {
throw new Exception('Cache directory isn\'t writable: ' . self::$cacheDir);
}
}

View File

@@ -25,7 +25,7 @@ class Colors
*
* @var array
*/
public static $cssColors = [
protected static $cssColors = [
'aliceblue' => '240,248,255',
'antiquewhite' => '250,235,215',
'aqua' => '0,255,255',
@@ -176,4 +176,71 @@ class Colors
'yellow' => '255,255,0',
'yellowgreen' => '154,205,50',
];
/**
* Convert named color in a [r,g,b[,a]] array
*
* @param string $colorName
*
* @return array|null
*/
public static function colorNameToRGBa($colorName)
{
if (is_string($colorName) && isset(static::$cssColors[$colorName])) {
$rgba = explode(',', static::$cssColors[$colorName]);
// only case with opacity is transparent, with opacity=0, so we can intval on opacity also
$rgba = array_map('intval', $rgba);
return $rgba;
}
return null;
}
/**
* Reverse conversion : from RGBA to a color name if possible
*
* @param integer $r
* @param integer $g
* @param integer $b
* @param integer $a
*
* @return string|null
*/
public static function RGBaToColorName($r, $g, $b, $a = 1)
{
static $reverseColorTable = null;
if (! is_numeric($r) || ! is_numeric($g) || ! is_numeric($b) || ! is_numeric($a)) {
return null;
}
if ($a < 1) {
# specific case we dont' revert according to spec
#if (! $a && ! $r && ! $g && ! $b) {
# return 'transparent';
#}
return null;
}
if (is_null($reverseColorTable)) {
$reverseColorTable = [];
foreach (static::$cssColors as $name => $rgb_str) {
$rgb_str = explode(',', $rgb_str);
if (count($rgb_str) == 3) {
$reverseColorTable[intval($rgb_str[0])][intval($rgb_str[1])][intval($rgb_str[2])] = $name;
}
}
}
if (isset($reverseColorTable[intval($r)][intval($g)][intval($b)])) {
return $reverseColorTable[intval($r)][intval($g)][intval($b)];
}
return null;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -81,6 +81,11 @@ abstract class Formatter
*/
protected $sourceMapGenerator;
/**
* @var string
*/
protected $strippedSemicolon;
/**
* Initialize formatter
*
@@ -113,26 +118,6 @@ abstract class Formatter
return rtrim($name) . $this->assignSeparator . $value . ';';
}
/**
* Strip semi-colon appended by property(); it's a separator, not a terminator
*
* @api
*
* @param array $lines
*/
public function stripSemicolon(&$lines)
{
if ($this->keepSemicolons) {
return;
}
if (($count = count($lines))
&& substr($lines[$count - 1], -1) === ';'
) {
$lines[$count - 1] = substr($lines[$count - 1], 0, -1);
}
}
/**
* Output lines inside a block
*
@@ -209,6 +194,10 @@ abstract class Formatter
if (! empty($block->selectors)) {
$this->indentLevel--;
if (! $this->keepSemicolons) {
$this->strippedSemicolon = '';
}
if (empty($block->children)) {
$this->write($this->break);
}
@@ -217,6 +206,34 @@ abstract class Formatter
}
}
/**
* Test and clean safely empty children
*
* @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
*
* @return boolean
*/
protected function testEmptyChildren($block)
{
$isEmpty = empty($block->lines);
if ($block->children) {
foreach ($block->children as $k => &$child) {
if (! $this->testEmptyChildren($child)) {
$isEmpty = false;
continue;
}
if ($child->type === Type::T_MEDIA || $child->type === Type::T_DIRECTIVE) {
$child->children = [];
$child->selectors = null;
}
}
}
return $isEmpty;
}
/**
* Entry point to formatting a block
*
@@ -232,11 +249,13 @@ abstract class Formatter
$this->sourceMapGenerator = null;
if ($sourceMapGenerator) {
$this->currentLine = 1;
$this->currentColumn = 0;
$this->currentLine = 1;
$this->currentColumn = 0;
$this->sourceMapGenerator = $sourceMapGenerator;
}
$this->testEmptyChildren($block);
ob_start();
$this->block($block);
@@ -247,10 +266,32 @@ abstract class Formatter
}
/**
* Output content
*
* @param string $str
*/
protected function write($str)
{
if (! empty($this->strippedSemicolon)) {
echo $this->strippedSemicolon;
$this->strippedSemicolon = '';
}
/*
* Maybe Strip semi-colon appended by property(); it's a separator, not a terminator
* will be striped for real before a closing, otherwise displayed unchanged starting the next write
*/
if (! $this->keepSemicolons &&
$str &&
(strpos($str, ';') !== false) &&
(substr($str, -1) === ';')
) {
$str = substr($str, 0, -1);
$this->strippedSemicolon = ';';
}
if ($this->sourceMapGenerator) {
$this->sourceMapGenerator->addMapping(
$this->currentLine,

View File

@@ -55,7 +55,7 @@ class Expanded extends Formatter
foreach ($block->lines as $index => $line) {
if (substr($line, 0, 2) === '/*') {
$block->lines[$index] = preg_replace('/(\r|\n)+/', $glue, $line);
$block->lines[$index] = preg_replace('/[\r\n]+/', $glue, $line);
}
}

View File

@@ -13,6 +13,7 @@ namespace ScssPhp\ScssPhp\Formatter;
use ScssPhp\ScssPhp\Formatter;
use ScssPhp\ScssPhp\Formatter\OutputBlock;
use ScssPhp\ScssPhp\Type;
/**
* Nested formatter
@@ -62,49 +63,11 @@ class Nested extends Formatter
foreach ($block->lines as $index => $line) {
if (substr($line, 0, 2) === '/*') {
$block->lines[$index] = preg_replace('/(\r|\n)+/', $glue, $line);
$block->lines[$index] = preg_replace('/[\r\n]+/', $glue, $line);
}
}
$this->write($inner . implode($glue, $block->lines));
if (! empty($block->children)) {
$this->write($this->break);
}
}
/**
* {@inheritdoc}
*/
protected function blockSelectors(OutputBlock $block)
{
$inner = $this->indentStr();
$this->write($inner
. implode($this->tagSeparator, $block->selectors)
. $this->open . $this->break);
}
/**
* {@inheritdoc}
*/
protected function blockChildren(OutputBlock $block)
{
foreach ($block->children as $i => $child) {
$this->block($child);
if ($i < count($block->children) - 1) {
$this->write($this->break);
if (isset($block->children[$i + 1])) {
$next = $block->children[$i + 1];
if ($next->depth === max($block->depth, 1) && $child->depth >= $next->depth) {
$this->write($this->break);
}
}
}
}
}
/**
@@ -112,8 +75,38 @@ class Nested extends Formatter
*/
protected function block(OutputBlock $block)
{
static $depths;
static $downLevel;
static $closeBlock;
static $previousEmpty;
static $previousHasSelector;
if ($block->type === 'root') {
$this->adjustAllChildren($block);
$depths = [ 0 ];
$downLevel = '';
$closeBlock = '';
$this->depth = 0;
$previousEmpty = false;
$previousHasSelector = false;
}
$isMediaOrDirective = in_array($block->type, [Type::T_DIRECTIVE, Type::T_MEDIA]);
$isSupport = ($block->type === Type::T_DIRECTIVE
&& $block->selectors && strpos(implode('', $block->selectors), '@supports') !== false);
while ($block->depth < end($depths) || ($block->depth == 1 && end($depths) == 1)) {
array_pop($depths);
$this->depth--;
if (! $this->depth && ($block->depth <= 1 || (! $this->indentLevel && $block->type === Type::T_COMMENT)) &&
(($block->selectors && ! $isMediaOrDirective) || $previousHasSelector)
) {
$downLevel = $this->break;
}
if (empty($block->lines) && empty($block->children)) {
$previousEmpty = true;
}
}
if (empty($block->lines) && empty($block->children)) {
@@ -122,27 +115,92 @@ class Nested extends Formatter
$this->currentBlock = $block;
if (! empty($block->lines) || (! empty($block->children) && ($this->depth < 1 || $isSupport))) {
if ($block->depth > end($depths)) {
if (! $previousEmpty || $this->depth < 1) {
$this->depth++;
$depths[] = $block->depth;
} else {
// keep the current depth unchanged but take the block depth as a new reference for following blocks
array_pop($depths);
$depths[] = $block->depth;
}
}
}
$this->depth = $block->depth;
$previousEmpty = ($block->type === Type::T_COMMENT);
$previousHasSelector = false;
if (! empty($block->selectors)) {
if ($closeBlock) {
$this->write($closeBlock);
$closeBlock = '';
}
if ($downLevel) {
$this->write($downLevel);
$downLevel = '';
}
$this->blockSelectors($block);
$this->indentLevel++;
}
if (! empty($block->lines)) {
if ($closeBlock) {
$this->write($closeBlock);
$closeBlock = '';
}
if ($downLevel) {
$this->write($downLevel);
$downLevel = '';
}
$this->blockLines($block);
$closeBlock = $this->break;
}
if (! empty($block->children)) {
$this->blockChildren($block);
if ($this->depth > 0 && ($isMediaOrDirective || ! $this->hasFlatChild($block))) {
array_pop($depths);
$this->depth--;
$this->blockChildren($block);
$this->depth++;
$depths[] = $block->depth;
} else {
$this->blockChildren($block);
}
}
// reclear to not be spoiled by children if T_DIRECTIVE
if ($block->type === Type::T_DIRECTIVE) {
$previousHasSelector = false;
}
if (! empty($block->selectors)) {
$this->indentLevel--;
if (! $this->keepSemicolons) {
$this->strippedSemicolon = '';
}
$this->write($this->close);
$closeBlock = $this->break;
if ($this->depth > 1 && ! empty($block->children)) {
array_pop($depths);
$this->depth--;
}
if (! $isMediaOrDirective) {
$previousHasSelector = true;
}
}
if ($block->type === 'root') {
@@ -151,51 +209,20 @@ class Nested extends Formatter
}
/**
* Adjust the depths of all children, depth first
* Block has flat child
*
* @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
*
* @return boolean
*/
private function adjustAllChildren(OutputBlock $block)
private function hasFlatChild($block)
{
// flatten empty nested blocks
$children = [];
foreach ($block->children as $i => $child) {
if (empty($child->lines) && empty($child->children)) {
if (isset($block->children[$i + 1])) {
$block->children[$i + 1]->depth = $child->depth;
}
continue;
}
$children[] = $child;
}
$count = count($children);
for ($i = 0; $i < $count; $i++) {
$depth = $children[$i]->depth;
$j = $i + 1;
if (isset($children[$j]) && $depth < $children[$j]->depth) {
$childDepth = $children[$j]->depth;
for (; $j < $count; $j++) {
if ($depth < $children[$j]->depth && $childDepth >= $children[$j]->depth) {
$children[$j]->depth = $depth + 1;
}
}
}
}
$block->children = $children;
// make relative to parent
foreach ($block->children as $child) {
$this->adjustAllChildren($child);
$child->depth = $child->depth - $block->depth;
if (empty($child->selectors)) {
return true;
}
}
return false;
}
}

View File

@@ -141,17 +141,17 @@ class Number extends Node implements \ArrayAccess
public function offsetExists($offset)
{
if ($offset === -3) {
return $this->sourceColumn !== null;
return ! is_null($this->sourceColumn);
}
if ($offset === -2) {
return $this->sourceLine !== null;
return ! is_null($this->sourceLine);
}
if ($offset === -1
|| $offset === 0
|| $offset === 1
|| $offset === 2
if ($offset === -1 ||
$offset === 0 ||
$offset === 1 ||
$offset === 2
) {
return true;
}

File diff suppressed because it is too large Load Diff

View File

@@ -130,8 +130,17 @@ class Base64VLQ
private static function fromVLQSigned($value)
{
$negate = ($value & 1) === 1;
$value = $value >> 1;
$value = ($value >> 1) & ~(1<<(8 * PHP_INT_SIZE - 1)); // unsigned right shift
return $negate ? -$value : $value;
if (! $negate) {
return $value;
}
// We need to OR 0x80000000 here to ensure the 32nd bit (the sign bit) is
// always set for negative numbers. If `value` were 1, (meaning `negate` is
// true and all other bits were zeros), `value` would now be 0. -0 is just
// 0, and doesn't flip the 32nd bit as intended. All positive numbers will
// successfully flip the 32nd bit without issue, so it's a noop for them.
return -$value | 0x80000000;
}
}

View File

@@ -1,217 +0,0 @@
<?php
/**
* SCSSPHP
*
* @copyright 2012-2019 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
* @link http://scssphp.github.io/scssphp
*/
namespace ScssPhp\ScssPhp\SourceMap;
/**
* Base64 VLQ Encoder
*
* {@internal Derivative of oyejorge/less.php's lib/SourceMap/Base64VLQ.php, relicensed with permission. }}
*
* @author Josh Schmidt <oyejorge@gmail.com>
* @author Nicolas FRANÇOIS <nicolas.francois@frog-labs.com>
*/
class Base64VLQEncoder
{
/**
* Shift
*
* @var integer
*/
private $shift = 5;
/**
* Mask
*
* @var integer
*/
private $mask = 0x1F; // == (1 << shift) == 0b00011111
/**
* Continuation bit
*
* @var integer
*/
private $continuationBit = 0x20; // == (mask - 1 ) == 0b00100000
/**
* Char to integer map
*
* @var array
*/
private $charToIntMap = [
'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7,
'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15,
'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23,
'Y' => 24, 'Z' => 25, 'a' => 26, 'b' => 27, 'c' => 28, 'd' => 29, 'e' => 30, 'f' => 31,
'g' => 32, 'h' => 33, 'i' => 34, 'j' => 35, 'k' => 36, 'l' => 37, 'm' => 38, 'n' => 39,
'o' => 40, 'p' => 41, 'q' => 42, 'r' => 43, 's' => 44, 't' => 45, 'u' => 46, 'v' => 47,
'w' => 48, 'x' => 49, 'y' => 50, 'z' => 51, 0 => 52, 1 => 53, 2 => 54, 3 => 55,
4 => 56, 5 => 57, 6 => 58, 7 => 59, 8 => 60, 9 => 61, '+' => 62, '/' => 63,
];
/**
* Integer to char map
*
* @var array
*/
private $intToCharMap = [
0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E', 5 => 'F', 6 => 'G', 7 => 'H',
8 => 'I', 9 => 'J', 10 => 'K', 11 => 'L', 12 => 'M', 13 => 'N', 14 => 'O', 15 => 'P',
16 => 'Q', 17 => 'R', 18 => 'S', 19 => 'T', 20 => 'U', 21 => 'V', 22 => 'W', 23 => 'X',
24 => 'Y', 25 => 'Z', 26 => 'a', 27 => 'b', 28 => 'c', 29 => 'd', 30 => 'e', 31 => 'f',
32 => 'g', 33 => 'h', 34 => 'i', 35 => 'j', 36 => 'k', 37 => 'l', 38 => 'm', 39 => 'n',
40 => 'o', 41 => 'p', 42 => 'q', 43 => 'r', 44 => 's', 45 => 't', 46 => 'u', 47 => 'v',
48 => 'w', 49 => 'x', 50 => 'y', 51 => 'z', 52 => '0', 53 => '1', 54 => '2', 55 => '3',
56 => '4', 57 => '5', 58 => '6', 59 => '7', 60 => '8', 61 => '9', 62 => '+', 63 => '/',
];
/**
* Constructor
*/
public function __construct()
{
// I leave it here for future reference
// foreach (str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/') as $i => $char)
// {
// $this->charToIntMap[$char] = $i;
// $this->intToCharMap[$i] = $char;
// }
}
/**
* Convert from a two-complement value to a value where the sign bit is
* is placed in the least significant bit. For example, as decimals:
* 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
* 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
* We generate the value for 32 bit machines, hence -2147483648 becomes 1, not 4294967297,
* even on a 64 bit machine.
*
* @param string $aValue
*/
public function toVLQSigned($aValue)
{
return 0xffffffff & ($aValue < 0 ? ((-$aValue) << 1) + 1 : ($aValue << 1) + 0);
}
/**
* Convert to a two-complement value from a value where the sign bit is
* is placed in the least significant bit. For example, as decimals:
* 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
* 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
* We assume that the value was generated with a 32 bit machine in mind.
* Hence
* 1 becomes -2147483648
* even on a 64 bit machine.
*
* @param integer $aValue
*/
public function fromVLQSigned($aValue)
{
return $aValue & 1 ? $this->zeroFill(~$aValue + 2, 1) | (-1 - 0x7fffffff) : $this->zeroFill($aValue, 1);
}
/**
* Return the base 64 VLQ encoded value.
*
* @param string $aValue The value to encode
*
* @return string The encoded value
*/
public function encode($aValue)
{
$encoded = '';
$vlq = $this->toVLQSigned($aValue);
do {
$digit = $vlq & $this->mask;
$vlq = $this->zeroFill($vlq, $this->shift);
if ($vlq > 0) {
$digit |= $this->continuationBit;
}
$encoded .= $this->base64Encode($digit);
} while ($vlq > 0);
return $encoded;
}
/**
* Return the value decoded from base 64 VLQ.
*
* @param string $encoded The encoded value to decode
*
* @return integer The decoded value
*/
public function decode($encoded)
{
$vlq = 0;
$i = 0;
do {
$digit = $this->base64Decode($encoded[$i]);
$vlq |= ($digit & $this->mask) << ($i * $this->shift);
$i++;
} while ($digit & $this->continuationBit);
return $this->fromVLQSigned($vlq);
}
/**
* Right shift with zero fill.
*
* @param integer $a number to shift
* @param integer $b number of bits to shift
*
* @return integer
*/
public function zeroFill($a, $b)
{
return ($a >= 0) ? ($a >> $b) : ($a >> $b) & (PHP_INT_MAX >> ($b - 1));
}
/**
* Encode single 6-bit digit as base64.
*
* @param integer $number
*
* @return string
*
* @throws \Exception If the number is invalid
*/
public function base64Encode($number)
{
if ($number < 0 || $number > 63) {
throw new \Exception(sprintf('Invalid number "%s" given. Must be between 0 and 63.', $number));
}
return $this->intToCharMap[$number];
}
/**
* Decode single 6-bit digit from base64
*
* @param string $char
*
* @return integer
*
* @throws \Exception If the number is invalid
*/
public function base64Decode($char)
{
if (! array_key_exists($char, $this->charToIntMap)) {
throw new \Exception(sprintf('Invalid base 64 digit "%s" given.', $char));
}
return $this->charToIntMap[$char];
}
}

View File

@@ -18,5 +18,5 @@ namespace ScssPhp\ScssPhp;
*/
class Version
{
const VERSION = 'v1.0.0';
const VERSION = 'v1.0.6';
}