Skip to content

Commit

Permalink
Fix interpolated selector & String interpolation
Browse files Browse the repository at this point in the history
string interpolation should run in a loop as long as the string keeps being modified
see less/less.js@796d37c

Bug: T353142
Change-Id: I9eae221cbb3fe93b17d79a66e9b3425cbe24163b
  • Loading branch information
Hannah Okwelum committed Feb 7, 2024
1 parent 6cb92a9 commit 21e77ca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
21 changes: 12 additions & 9 deletions lib/Less/Tree/Quoted.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,20 @@ public function compile( $env ) {
$value = str_replace( $matches[0][$i], $js, $value );
}
}

if ( preg_match_all( '/@\{([\w-]+)\}/', $value, $matches ) ) {
foreach ( $matches[1] as $i => $match ) {
$v = new Less_Tree_Variable( '@' . $match, $this->index, $this->currentFileInfo );
$v = $v->compile( $env );
$v = ( $v instanceof self ) ? $v->value : $v->toCSS();
$value = str_replace( $matches[0][$i], $v, $value );
$r = $value;
do{
$value = $r;
if ( preg_match_all( '/@\{([\w-]+)\}/', $value, $matches ) ) {
foreach ( $matches[1] as $i => $match ) {
$v = new Less_Tree_Variable( '@' . $match, $this->index, $this->currentFileInfo );
$v = $v->compile( $env );
$v = ( $v instanceof self ) ? $v->value : $v->toCSS();
$r = str_replace( $matches[0][$i], $v, $r );
}
}
}
}while ( $r != $value );

return new self( $this->quote . $value . $this->quote, $value, $this->escaped, $this->index, $this->currentFileInfo );
return new self( $this->quote . $r . $this->quote, $r, $this->escaped, $this->index, $this->currentFileInfo );
}

public function compare( $x ) {
Expand Down
9 changes: 4 additions & 5 deletions lib/Less/Tree/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ public function CacheElements() {
$css .= $v->value;
continue;
}

if (
( $v->value instanceof Less_Tree_Selector || $v->value instanceof Less_Tree_Variable )
if ( ( $v->value instanceof Less_Tree_Selector || $v->value instanceof Less_Tree_Variable )
|| !is_string( $v->value->value ) ) {
$this->cacheable = false;
return;
}
$css .= $v->value->value;
if ( isset( $v->value->value ) && !is_object( $v->value->value ) ) {
$css .= $v->value->value;
}
}

$this->_oelements_len = preg_match_all( '/[,&#\*\.\w-](?:[\w-]|(?:\\\\.))*/', $css, $matches );
Expand Down
5 changes: 1 addition & 4 deletions test/phpunit/FixturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class phpunit_FixturesTest extends phpunit_bootstrap {
'css-3' => true,
'import-reference' => true,

// Temporary disabled; Bug logged T353133
'strings' => true,
// TODO; Create Task for import-interpolation
'import-interpolation' => true,

// Temporary disabled; Bug logged here T352897
Expand Down Expand Up @@ -73,8 +72,6 @@ class phpunit_FixturesTest extends phpunit_bootstrap {
// behaviour of doing maths in parentheses by default
'parens' => true,

// Temporary disabled; Bug logged T353142
'mixins-interpolated' => true,
// Temporary disabled; Bug logged T353143
'detached-rulesets' => true,
]
Expand Down

0 comments on commit 21e77ca

Please sign in to comment.