Skip to content

Commit

Permalink
#569 attempt to fix call() with ellipsis
Browse files Browse the repository at this point in the history
  • Loading branch information
robocoder committed Jun 19, 2018
1 parent 585f6ae commit 4963903
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/Compiler.php
Expand Up @@ -3655,7 +3655,7 @@ protected function callNativeFunction($name, $args, &$returnValue)
return false;
}

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

if ($name !== 'if' && $name !== 'call') {
foreach ($sorted as &$val) {
Expand Down Expand Up @@ -3714,7 +3714,7 @@ protected function sortArgs($prototype, $args)
$key = $key[1];

if (empty($key)) {
$posArgs[] = $value;
$posArgs[] = empty($arg[2]) ? $value : $arg;
} else {
$keyArgs[$key] = $value;
}
Expand Down Expand Up @@ -4266,20 +4266,38 @@ protected function libCall($args, $kwargs)
{
$name = $this->compileStringContent($this->coerceString($this->reduce(array_shift($args), true)));

$args = array_map(
function ($a) {
return [null, $a, false];
},
$args
);
$posArgs = [];

foreach ($args as $arg) {
if (empty($arg[0])) {
if ($arg[2] === true) {
$tmp = $this->reduce($arg[1]);

if ($tmp[0] === Type::T_LIST) {
foreach ($tmp[2] as $item) {
$posArgs[] = [null, $item, false];
}
} else {
$posArgs[] = [null, $tmp, true];
}

continue;
}

$posArgs[] = [null, $this->reduce($arg), false];
continue;
}

$posArgs[] = [null, $arg, false];
}

if (count($kwargs)) {
foreach ($kwargs as $key => $value) {
$args[] = [[Type::T_VARIABLE, $key], $value, false];
$posArgs[] = [[Type::T_VARIABLE, $key], $value, false];
}
}

return $this->reduce([Type::T_FUNCTION_CALL, $name, $args]);
return $this->reduce([Type::T_FUNCTION_CALL, $name, $posArgs]);
}

protected static $libIf = ['condition', 'if-true', 'if-false'];
Expand Down
20 changes: 20 additions & 0 deletions tests/inputs/builtins.scss
Expand Up @@ -216,3 +216,23 @@ $type: text;
div.unquote-test {
a: unquote('[type=\'#{$type}\']');
}

.does-compile-1 {
color: call(lighten, #000, 40%);
}

.does-compile-2 {
$color: #000;
$percent: 40%;
color: call(lighten, $color, $percent);
}

.does-compile-3 {
$args: (#000, 40%);
color: call(lighten, nth($args, 1), nth($args, 2));
}

.does-compile-4 {
$args: (#000, 40%);
color: call(lighten, $args...);
}
12 changes: 12 additions & 0 deletions tests/outputs/builtins.css
Expand Up @@ -159,3 +159,15 @@ div.call-tests {

div.unquote-test {
a: [type='text']; }

.does-compile-1 {
color: #666; }

.does-compile-2 {
color: #666; }

.does-compile-3 {
color: #666; }

.does-compile-4 {
color: #666; }
12 changes: 12 additions & 0 deletions tests/outputs_numbered/builtins.css
Expand Up @@ -160,3 +160,15 @@ div.call-tests {
/* line 216, inputs/builtins.scss */
div.unquote-test {
a: [type='text']; }
/* line 220, inputs/builtins.scss */
.does-compile-1 {
color: #666; }
/* line 224, inputs/builtins.scss */
.does-compile-2 {
color: #666; }
/* line 230, inputs/builtins.scss */
.does-compile-3 {
color: #666; }
/* line 235, inputs/builtins.scss */
.does-compile-4 {
color: #666; }

0 comments on commit 4963903

Please sign in to comment.