Skip to content

Commit

Permalink
update scssphp to v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dleffler committed Aug 8, 2019
1 parent 65a5801 commit 25e87aa
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 46 deletions.
4 changes: 2 additions & 2 deletions external/ExtPrograms.csv
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SimplePie,1.5.2,github.com/simplepie/simplepie,1.5.2,
pixidou,0.1exp,github.com/asvinb/pixidou,0.1,"placed in Pixidou module, heavily modified at this point"
class.upload,0.33,github.com/verot/class.upload.php,0.34,Correct flip operation where flip vertical & horizontal were inverted/swapped
iCalCreator,2.27.21,github.com/iCalcreator/iCalcreator,2.27.21,uncomment load utilities
scssphp,1.0.0exp,github.com/scssphp/scssphp,1.0.0,hacked to compile newui
scssphp,1.0.3exp,github.com/scssphp/scssphp,1.0.3,hacked to compile newui
lessphp,0.5.0,github.com/leafo/lessphp,0.5.0,will not compile bootstrap v3+
less.php,1.7.0.14,github.com/oyejorge/less.php,1.7.0.14,
Twitter-Bootstrap2,2.3.2,twitter.github.com/bootstrap,2.3.2,"patched bootstrap.less includes swatches, fontawesome & exp variables"
Expand All @@ -45,7 +45,7 @@ Respond,1.4.2,github.com/scottjehl/Respond,1.4.2,IE6-8 shim
html5shiv,3.7.3,github.com/aFarkas/html5shiv,3.7.3,IE6-8 shim
csshover.htc,3.11,peterned.home.xs4all.nl/csshover.html,3.11,IE6 shim
CKEditor,4.12.1,ckeditor.com,4.12.1/12.3.0,"add fieldinsert (exp), tableresize, sourcedialog, image2 fileupload & imageupload widgets & kama skin"
TinyMCE,4.9.5,tinymce.com,4.9.4/5.0.12,"add fieldinsert (exp) & quickupload (exp) plugins, & xenmce skin"
TinyMCE,4.9.5,tinymce.com,4.9.5/5.0.13,"add fieldinsert (exp) & quickupload (exp) plugins, & xenmce skin"
PLUpload,2.3.6,github.com/moxiecode/plupload,2.3.6/3.1.2,"needed for TinyMCE Quick Upload, placed in that plugin folder"
elFinder,2.1.49,elfinder.org,2.1.49,customized in /framework with Exponent php classes and .js files
jQuery1,1.12.4,jquery.com,1.12.4,v1.11.3 still needed for old firefox
Expand Down
124 changes: 91 additions & 33 deletions external/scssphp/src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,13 +979,15 @@ protected function compileAtRoot(Block $block)
protected function filterScopeWithWithout($scope, $with, $without)
{
$filteredScopes = [];
$childStash = [];

if ($scope->type === TYPE::T_ROOT) {
return $scope;
}

// start from the root
while ($scope->parent && $scope->parent->type !== TYPE::T_ROOT) {
array_unshift($childStash, $scope);
$scope = $scope->parent;
}

Expand All @@ -1007,7 +1009,9 @@ protected function filterScopeWithWithout($scope, $with, $without)
$filteredScopes[] = $s;
}

if ($scope->children) {
if (count($childStash)) {
$scope = array_shift($childStash);
} elseif ($scope->children) {
$scope = end($scope->children);
} else {
$scope = null;
Expand All @@ -1028,8 +1032,9 @@ protected function filterScopeWithWithout($scope, $with, $without)
while (count($filteredScopes)) {
$s = array_shift($filteredScopes);
$s->parent = $p;
$p->children[] = &$s;
$p = $s;
$p->children[] = $s;
$newScope = &$p->children[0];
$p = &$p->children[0];
}

return $newScope;
Expand Down Expand Up @@ -1170,16 +1175,23 @@ protected function isWith($block, $with, $without)
if ($block->type === Type::T_DIRECTIVE) {
if (isset($block->name)) {
return $this->testWithWithout($block->name, $with, $without);
}
elseif (isset($block->selectors) && preg_match(',@(\w+),ims', json_encode($block->selectors), $m)) {
} elseif (isset($block->selectors) && preg_match(',@(\w+),ims', json_encode($block->selectors), $m)) {
return $this->testWithWithout($m[1], $with, $without);
}
else {
} else {
return $this->testWithWithout('???', $with, $without);
}
}
}
elseif (isset($block->selectors)) {
} elseif (isset($block->selectors)) {
// a selector starting with number is a keyframe rule
if (count($block->selectors)) {
$s = reset($block->selectors);
while (is_array($s)) {
$s = reset($s);
}
if (is_object($s) && get_class($s) === 'ScssPhp\ScssPhp\Node\Number') {
return $this->testWithWithout('keyframes', $with, $without);
}
}
return $this->testWithWithout('rule', $with, $without);
}

Expand All @@ -1195,7 +1207,8 @@ protected function isWith($block, $with, $without)
* @return bool
* true if the block should be kept, false to reject
*/
protected function testWithWithout($what, $with, $without) {
protected function testWithWithout($what, $with, $without)
{

// if without, reject only if in the list (or 'all' is in the list)
if (count($without)) {
Expand Down Expand Up @@ -1730,7 +1743,7 @@ protected function compileChildrenNoReturn($stms, OutputBlock $out, $selfParent
$stm[1]->selfParent = $selfParent;
$ret = $this->compileChild($stm, $out);
$stm[1]->selfParent = null;
} elseif ($selfParent && $stm[0] === TYPE::T_INCLUDE) {
} elseif ($selfParent && in_array($stm[0], [TYPE::T_INCLUDE, TYPE::T_EXTEND])) {
$stm['selfParent'] = $selfParent;
$ret = $this->compileChild($stm, $out);
unset($stm['selfParent']);
Expand Down Expand Up @@ -2059,6 +2072,8 @@ protected function compileImport($rawPath, OutputBlock $out, $once = false)
return true;
}

$this->appendRootDirective('@import ' . $this->compileValue($rawPath). ';', $out);

return false;
}

Expand All @@ -2070,17 +2085,20 @@ protected function compileImport($rawPath, OutputBlock $out, $once = false)

foreach ($rawPath[2] as $path) {
if ($path[0] !== Type::T_STRING) {
$this->appendRootDirective('@import ' . $this->compileValue($rawPath) . ';', $out);
return false;
}
}

foreach ($rawPath[2] as $path) {
$this->compileImport($path, $out);
$this->compileImport($path, $out, $once);
}

return true;
}

$this->appendRootDirective('@import ' . $this->compileValue($rawPath) . ';', $out);

return false;
}

Expand Down Expand Up @@ -2151,6 +2169,10 @@ protected function appendOutputLine(OutputBlock $out, $type, $line)
if (end($parent->children) !== $out) {
$outWrite = &$parent->children[count($parent->children)-1];
}

if (!is_string($line)) {
$line = $this->compileValue($line);
}
}

// check if it's a flat output or not
Expand Down Expand Up @@ -2203,17 +2225,13 @@ protected function compileChild($child, OutputBlock $out)
case Type::T_SCSSPHP_IMPORT_ONCE:
$rawPath = $this->reduce($child[1]);

if (! $this->compileImport($rawPath, $out, true)) {
$this->appendRootDirective('@import ' . $this->compileValue($rawPath) . ';', $out);
}
$this->compileImport($rawPath, $out, true);
break;

case Type::T_IMPORT:
$rawPath = $this->reduce($child[1]);

if (! $this->compileImport($rawPath, $out)) {
$this->appendRootDirective('@import ' . $this->compileValue($rawPath) . ';', $out);
}
$this->compileImport($rawPath, $out);
break;

case Type::T_DIRECTIVE:
Expand Down Expand Up @@ -2333,8 +2351,11 @@ protected function compileChild($child, OutputBlock $out)
foreach ($results as $result) {
// only use the first one
$result = current($result);

$this->pushExtends($result, $out->selectors, $child);
$selectors = $out->selectors;
if (!$selectors && isset($child['selfParent'])) {
$selectors = $this->multiplySelectors($this->env, $child['selfParent']);
}
$this->pushExtends($result, $selectors, $child);
}
}
break;
Expand Down Expand Up @@ -2466,7 +2487,7 @@ protected function compileChild($child, OutputBlock $out)

case Type::T_INCLUDE:
// including a mixin
list(, $name, $argValues, $content) = $child;
list(, $name, $argValues, $content, $argUsing) = $child;

$mixin = $this->get(static::$namespaces['mixin'] . $name, false);

Expand Down Expand Up @@ -2509,13 +2530,20 @@ protected function compileChild($child, OutputBlock $out)
// i.e., recursive @include of the same mixin
if (isset($content)) {
$copyContent = clone $content;
$copyContent->scope = $callingScope;
$copyContent->scope = clone $callingScope;

$this->setRaw(static::$namespaces['special'] . 'content', $copyContent, $this->env);
} else {
$this->setRaw(static::$namespaces['special'] . 'content', null, $this->env);
}

// save the "using" argument list for applying it to when "@content" is invoked
if (isset($argUsing)) {
$this->setRaw(static::$namespaces['special'] . 'using', $argUsing, $this->env);
} else {
$this->setRaw(static::$namespaces['special'] . 'using', null, $this->env);
}

if (isset($mixin->args)) {
$this->applyArguments($mixin->args, $argValues);
}
Expand All @@ -2532,6 +2560,8 @@ protected function compileChild($child, OutputBlock $out)
case Type::T_MIXIN_CONTENT:
$env = isset($this->storeEnv) ? $this->storeEnv : $this->env;
$content = $this->get(static::$namespaces['special'] . 'content', false, $env);
$argUsing = $this->get(static::$namespaces['special'] . 'using', false, $env);
$argContent = $child[1];

if (! $content) {
$content = new \stdClass();
Expand All @@ -2541,7 +2571,21 @@ protected function compileChild($child, OutputBlock $out)
}

$storeEnv = $this->storeEnv;

$varsUsing = [];
if (isset($argUsing) && isset($argContent)) {
// Get the arguments provided for the content with the names provided in the "using" argument list
$this->storeEnv = $this->env;
$varsUsing = $this->applyArguments($argUsing, $argContent, false);
}

// restore the scope from the @content
$this->storeEnv = $content->scope;
// append the vars from using if any
foreach ($varsUsing as $name => $val) {
$this->set($name, $val, true, $this->storeEnv);
}

$this->compileChildrenNoReturn($content->children, $out);

$this->storeEnv = $storeEnv;
Expand Down Expand Up @@ -3428,11 +3472,19 @@ public function compileValue($value)
list(, $interpolate, $left, $right) = $value;
list(,, $whiteLeft, $whiteRight) = $interpolate;

$delim = $left[1];
if ($delim && $delim !== ' ' && !$whiteLeft) {
$delim .= ' ';
}
$left = count($left[2]) > 0 ?
$this->compileValue($left) . $whiteLeft : '';
$this->compileValue($left) . $delim . $whiteLeft: '';

$delim = $right[1];
if ($delim && $delim !== ' ') {
$delim .= ' ';
}
$right = count($right[2]) > 0 ?
$whiteRight . $this->compileValue($right) : '';
$whiteRight . $delim . $this->compileValue($right) : '';

return $left . $this->compileValue($interpolate) . $right;

Expand Down Expand Up @@ -4440,11 +4492,15 @@ protected function callNativeFunction($name, $args, &$returnValue)
return false;
}

@list($sorted, $kwargs) = $this->sortArgs($prototype, $args);
@list($sorted, $kwargs) = $this->sortNativeFunctionArgs($prototype, $args);

if ($name !== 'if' && $name !== 'call') {
$inExp = true;
if ($name === 'join') {
$inExp = false;
}
foreach ($sorted as &$val) {
$val = $this->reduce($val, true);
$val = $this->reduce($val, $inExp);
}
}

Expand Down Expand Up @@ -4487,7 +4543,7 @@ function ($m) {
*
* @return array
*/
protected function sortArgs($prototypes, $args)
protected function sortNativeFunctionArgs($prototypes, $args)
{
static $parser = null;

Expand Down Expand Up @@ -4557,7 +4613,7 @@ protected function sortArgs($prototypes, $args)
}

try {
$vars = $this->applyArguments($argDef, $args, false);
$vars = $this->applyArguments($argDef, $args, false, false);

// ensure all args are populated
foreach ($prototype as $i => $p) {
Expand Down Expand Up @@ -4607,10 +4663,12 @@ protected function sortArgs($prototypes, $args)
*
* @param array $argDef
* @param array $argValues
*
* @param bool $storeInEnv
* @param bool $reduce
* only used if $storeInEnv = false
* @throws \Exception
*/
protected function applyArguments($argDef, $argValues, $storeInEnv = true)
protected function applyArguments($argDef, $argValues, $storeInEnv = true, $reduce = true)
{
$output = [];

Expand Down Expand Up @@ -4746,7 +4804,7 @@ protected function applyArguments($argDef, $argValues, $storeInEnv = true)
if ($storeInEnv) {
$this->set($name, $this->reduce($val, true), true, $env);
} else {
$output[$name] = $val;
$output[$name] = ($reduce ? $this->reduce($val, true) : $val);
}
}

Expand All @@ -4764,7 +4822,7 @@ protected function applyArguments($argDef, $argValues, $storeInEnv = true)
if ($storeInEnv) {
$this->set($name, $this->reduce($default, true), true);
} else {
$output[$name] = $default;
$output[$name] = ($reduce ? $this->reduce($default, true) : $default);
}
}

Expand Down Expand Up @@ -5955,7 +6013,7 @@ protected function listSeparatorForJoin($list1, $sep)
return ',';

case 'space':
return '';
return ' ';

default:
return $list1[1];
Expand Down
Loading

0 comments on commit 25e87aa

Please sign in to comment.