Skip to content

Commit 2e50006

Browse files
authored
Merge pull request #697 from Cerdic/Issue/leafo/542
Issue/leafo/542
2 parents e30c215 + c0ba191 commit 2e50006

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/Parser.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,10 @@ protected function expression(&$out)
12701270
}
12711271

12721272
if ($this->matchChar('[')) {
1273-
if ($this->parenExpression($out, $s, "]")) {
1273+
if ($this->parenExpression($out, $s, "]", [Type::T_LIST, Type::T_KEYWORD])) {
1274+
if ($out[0] !== Type::T_LIST && $out[0] !== Type::T_MAP) {
1275+
$out = [Type::T_STRING, '', [ '[', $out, ']' ]];
1276+
}
12741277
return true;
12751278
}
12761279

@@ -1292,24 +1295,25 @@ protected function expression(&$out)
12921295
* @param array $out
12931296
* @param integer $s
12941297
* @param string $closingParen
1298+
* @param array $allowedTypes
12951299
*
12961300
* @return boolean
12971301
*/
1298-
protected function parenExpression(&$out, $s, $closingParen = ")")
1302+
protected function parenExpression(&$out, $s, $closingParen = ")", $allowedTypes = [Type::T_LIST, Type::T_MAP])
12991303
{
13001304
if ($this->matchChar($closingParen)) {
13011305
$out = [Type::T_LIST, '', []];
13021306

13031307
return true;
13041308
}
13051309

1306-
if ($this->valueList($out) && $this->matchChar($closingParen) && $out[0] === Type::T_LIST) {
1310+
if ($this->valueList($out) && $this->matchChar($closingParen) && in_array($out[0], $allowedTypes)) {
13071311
return true;
13081312
}
13091313

13101314
$this->seek($s);
13111315

1312-
if ($this->map($out)) {
1316+
if (in_array(Type::T_MAP, $allowedTypes) && $this->map($out)) {
13131317
return true;
13141318
}
13151319

tests/inputs/values.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ multiline block \
1515
content: "This is a \
1616
multiline string.";
1717
border-radius: -1px -1px -1px black;
18+
grid-template-columns: [avatar] 2fr [body] 6fr;
1819
}
1920

2021
#subtraction {

tests/outputs/values.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ multiline block \
1313
margin: 4, 3, 1;
1414
content: "This is a \
1515
multiline string.";
16-
border-radius: -1px -1px -1px black; }
16+
border-radius: -1px -1px -1px black;
17+
grid-template-columns: [avatar] 2fr [body] 6fr; }
1718
1819
#subtraction {
1920
lit: 10 -11;

tests/outputs_numbered/values.css

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ multiline block \
1414
margin: 4, 3, 1;
1515
content: "This is a \
1616
multiline string.";
17-
border-radius: -1px -1px -1px black; }
18-
/* line 20, inputs/values.scss */
17+
border-radius: -1px -1px -1px black;
18+
grid-template-columns: [avatar] 2fr [body] 6fr; }
19+
/* line 21, inputs/values.scss */
1920
#subtraction {
2021
lit: 10 -11;
2122
lit: -1;
@@ -25,14 +26,14 @@ multiline string.";
2526
var: -90;
2627
var: -90;
2728
var: -90; }
28-
/* line 34, inputs/values.scss */
29+
/* line 35, inputs/values.scss */
2930
#special {
3031
a: 12px expression(1 + (3 / Foo.bar("baz" + "bang") + function() {return 12;}) % 12); }
31-
/* line 38, inputs/values.scss */
32+
/* line 39, inputs/values.scss */
3233
#unary {
3334
b: 0.5em;
3435
c: -foo(12px);
3536
d: +foo(12px); }
36-
/* line 44, inputs/values.scss */
37+
/* line 45, inputs/values.scss */
3738
#self {
3839
content: "#self"; }

0 commit comments

Comments
 (0)