Skip to content

Commit 4963903

Browse files
committed
leafo#569 attempt to fix call() with ellipsis
1 parent 585f6ae commit 4963903

File tree

4 files changed

+72
-10
lines changed

4 files changed

+72
-10
lines changed

src/Compiler.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3655,7 +3655,7 @@ protected function callNativeFunction($name, $args, &$returnValue)
36553655
return false;
36563656
}
36573657

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

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

37163716
if (empty($key)) {
3717-
$posArgs[] = $value;
3717+
$posArgs[] = empty($arg[2]) ? $value : $arg;
37183718
} else {
37193719
$keyArgs[$key] = $value;
37203720
}
@@ -4266,20 +4266,38 @@ protected function libCall($args, $kwargs)
42664266
{
42674267
$name = $this->compileStringContent($this->coerceString($this->reduce(array_shift($args), true)));
42684268

4269-
$args = array_map(
4270-
function ($a) {
4271-
return [null, $a, false];
4272-
},
4273-
$args
4274-
);
4269+
$posArgs = [];
4270+
4271+
foreach ($args as $arg) {
4272+
if (empty($arg[0])) {
4273+
if ($arg[2] === true) {
4274+
$tmp = $this->reduce($arg[1]);
4275+
4276+
if ($tmp[0] === Type::T_LIST) {
4277+
foreach ($tmp[2] as $item) {
4278+
$posArgs[] = [null, $item, false];
4279+
}
4280+
} else {
4281+
$posArgs[] = [null, $tmp, true];
4282+
}
4283+
4284+
continue;
4285+
}
4286+
4287+
$posArgs[] = [null, $this->reduce($arg), false];
4288+
continue;
4289+
}
4290+
4291+
$posArgs[] = [null, $arg, false];
4292+
}
42754293

42764294
if (count($kwargs)) {
42774295
foreach ($kwargs as $key => $value) {
4278-
$args[] = [[Type::T_VARIABLE, $key], $value, false];
4296+
$posArgs[] = [[Type::T_VARIABLE, $key], $value, false];
42794297
}
42804298
}
42814299

4282-
return $this->reduce([Type::T_FUNCTION_CALL, $name, $args]);
4300+
return $this->reduce([Type::T_FUNCTION_CALL, $name, $posArgs]);
42834301
}
42844302

42854303
protected static $libIf = ['condition', 'if-true', 'if-false'];

tests/inputs/builtins.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,23 @@ $type: text;
216216
div.unquote-test {
217217
a: unquote('[type=\'#{$type}\']');
218218
}
219+
220+
.does-compile-1 {
221+
color: call(lighten, #000, 40%);
222+
}
223+
224+
.does-compile-2 {
225+
$color: #000;
226+
$percent: 40%;
227+
color: call(lighten, $color, $percent);
228+
}
229+
230+
.does-compile-3 {
231+
$args: (#000, 40%);
232+
color: call(lighten, nth($args, 1), nth($args, 2));
233+
}
234+
235+
.does-compile-4 {
236+
$args: (#000, 40%);
237+
color: call(lighten, $args...);
238+
}

tests/outputs/builtins.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,15 @@ div.call-tests {
159159

160160
div.unquote-test {
161161
a: [type='text']; }
162+
163+
.does-compile-1 {
164+
color: #666; }
165+
166+
.does-compile-2 {
167+
color: #666; }
168+
169+
.does-compile-3 {
170+
color: #666; }
171+
172+
.does-compile-4 {
173+
color: #666; }

tests/outputs_numbered/builtins.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,15 @@ div.call-tests {
160160
/* line 216, inputs/builtins.scss */
161161
div.unquote-test {
162162
a: [type='text']; }
163+
/* line 220, inputs/builtins.scss */
164+
.does-compile-1 {
165+
color: #666; }
166+
/* line 224, inputs/builtins.scss */
167+
.does-compile-2 {
168+
color: #666; }
169+
/* line 230, inputs/builtins.scss */
170+
.does-compile-3 {
171+
color: #666; }
172+
/* line 235, inputs/builtins.scss */
173+
.does-compile-4 {
174+
color: #666; }

0 commit comments

Comments
 (0)