Skip to content

Commit b190552

Browse files
committed
fixes leafo#412 - parsing multiple assignment flags
1 parent 0ac2848 commit b190552

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

src/Compiler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,9 +1460,9 @@ protected function compileChild($child, OutputBlock $out)
14601460
list(, $name, $value) = $child;
14611461

14621462
if ($name[0] === Type::T_VARIABLE) {
1463-
$flag = isset($child[3]) ? $child[3] : null;
1464-
$isDefault = $flag === '!default';
1465-
$isGlobal = $flag === '!global';
1463+
$flags = isset($child[3]) ? $child[3] : [];
1464+
$isDefault = in_array('!default', $flags);
1465+
$isGlobal = in_array('!global', $flags);
14661466

14671467
if ($isGlobal) {
14681468
$this->set($name[1], $this->reduce($value), false, $this->rootEnv);

src/Parser.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,8 @@ protected function parseChunk()
617617
$this->end()
618618
) {
619619
// check for '!flag'
620-
$assignmentFlag = $this->stripAssignmentFlag($value);
621-
$this->append([Type::T_ASSIGN, $name, $value, $assignmentFlag], $s);
620+
$assignmentFlags = $this->stripAssignmentFlags($value);
621+
$this->append([Type::T_ASSIGN, $name, $value, $assignmentFlags], $s);
622622

623623
return true;
624624
}
@@ -2287,25 +2287,28 @@ protected function end()
22872287
*
22882288
* @param array $value
22892289
*
2290-
* @return string
2290+
* @return array
22912291
*/
2292-
protected function stripAssignmentFlag(&$value)
2292+
protected function stripAssignmentFlags(&$value)
22932293
{
2294-
$token = &$value;
2294+
$flags = [];
22952295

22962296
for ($token = &$value; $token[0] === Type::T_LIST && ($s = count($token[2])); $token = &$lastNode) {
2297-
$lastNode = &$token[2][$s - 1];
2298-
2299-
if ($lastNode[0] === Type::T_KEYWORD && in_array($lastNode[1], ['!default', '!global'])) {
2297+
for ($lastNode = &$token[2][$s - 1];
2298+
$lastNode[0] === Type::T_KEYWORD && in_array($lastNode[1], ['!default', '!global']);
2299+
$lastNode = $node
2300+
) {
23002301
array_pop($token[2]);
23012302

2303+
$node = end($token[2]);
2304+
23022305
$token = $this->flattenList($token);
23032306

2304-
return $lastNode[1];
2307+
$flags[] = $lastNode[1];
23052308
}
23062309
}
23072310

2308-
return false;
2311+
return $flags;
23092312
}
23102313

23112314
/**

tests/inputs/variables.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@ body
8080
{
8181
color: $цвет;
8282
}
83+
84+
$test: 12 !default !global;
85+
86+
* {
87+
// Expected: 12
88+
data: $test;
89+
}

tests/outputs/variables.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ A {
3434

3535
body {
3636
color: #000; }
37+
38+
* {
39+
data: 12; }

tests/outputs_numbered/variables.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ A {
3737
/* line 79, inputs/variables.scss */
3838
body {
3939
color: #000; }
40+
/* line 86, inputs/variables.scss */
41+
* {
42+
data: 12; }

0 commit comments

Comments
 (0)