Skip to content

Commit 2cd9715

Browse files
anny21Krinkle
authored andcommitted
Support using rulesets as default values of a mixin parameter
Fix parser error: > could not understand value for named argument > in detached-rulesets.less on line 105, column 24 Less.js creates Detached rulesets even for empty arrays. The NameValue optimization was out of sync with parseRule(), failing to remove its position from the stack. This meant that when a MixinCall appears in the input, and the parser tries parseMixinDefinition (which in turn tries parsePrimary/parseNameValue/parseRule), it would stay "stuck" inside that parseMixinDefinition attempt instead of restoring fully back to the top-level parsePrimary and trying a parseMixinCall. Bug: T353143 Change-Id: Ifca743b916c53c7046bb7e764dcd0c16c0ebfcbb
1 parent 01b647e commit 2cd9715

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

lib/Less/Parser.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,13 +1516,7 @@ private function parseMixinArgs( $isCall ) {
15161516
// we do not support setting a ruleset as a default variable - it doesn't make sense
15171517
// However if we do want to add it, there is nothing blocking it, just don't error
15181518
// and remove isCall dependency below
1519-
$value = null;
1520-
if ( $isCall ) {
1521-
$value = $this->parseDetachedRuleset();
1522-
}
1523-
if ( !$value ) {
1524-
$value = $this->parseExpression();
1525-
}
1519+
$value = $this->parseDetachedRuleset() ?? $this->parseExpression();
15261520

15271521
if ( !$value ) {
15281522
if ( $isCall ) {
@@ -1899,12 +1893,9 @@ private function parseBlock() {
18991893

19001894
private function parseBlockRuleset() {
19011895
$block = $this->parseBlock();
1902-
1903-
if ( $block ) {
1904-
$block = new Less_Tree_Ruleset( null, $block );
1896+
if ( $block !== null ) {
1897+
return new Less_Tree_Ruleset( null, $block );
19051898
}
1906-
1907-
return $block;
19081899
}
19091900

19101901
/** @return Less_Tree_DetachedRuleset|null */
@@ -1983,7 +1974,7 @@ private function parseNameValue() {
19831974
if ( $match[3] ) {
19841975
$match[2] .= $match[3];
19851976
}
1986-
1977+
$this->forget();
19871978
return new Less_Tree_NameValue( $match[1], $match[2], $index, $this->env->currentFileInfo );
19881979
}
19891980

test/phpunit/FixturesTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class phpunit_FixturesTest extends phpunit_bootstrap {
3030
'comments2' => true, // T353131 & T353132
3131
'css' => true, // T352911 & T352866
3232
'css-guards' => true, // T353144
33-
'detached-rulesets' => true, // T353143
3433
'import' => true, // T353146
3534
'import-interpolation' => true, // TODO
3635
'import-reference' => true, // T352862

0 commit comments

Comments
 (0)