Skip to content

Commit

Permalink
Merge "Minor 3.13 sync in Less_Tree for Anonymous, NamespaceValue, Ja…
Browse files Browse the repository at this point in the history
…vaScript"
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jul 24, 2024
2 parents 96ca779 + a7fef13 commit c28be8d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
23 changes: 13 additions & 10 deletions lib/Less/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ private function parseUnicodeDescriptor() {
* `window.location.href`
*
* @return Less_Tree_JavaScript|null
* @see less-2.5.3.js#parsers.entities.javascript
* @see less-3.13.1.js#parsers.entities.javascript
*/
private function parseEntitiesJavascript() {
// Optimization: Hardcode first char, to avoid save()/restore() overhead
Expand All @@ -1642,7 +1642,7 @@ private function parseEntitiesJavascript() {
$js = $this->matchReg( '/\\G[^`]*`/' );
if ( $js ) {
$this->forget();
return new Less_Tree_JavaScript( substr( $js, 0, -1 ), $index, $isEscaped );
return new Less_Tree_JavaScript( substr( $js, 0, -1 ), $isEscaped, $index );
}
$this->restore();
}
Expand Down Expand Up @@ -1764,7 +1764,9 @@ private function parseExtend( $isRule = false ) {
// namespaced, but we only support the child and descendant
// selector for now.
//
private function parseMixinCall( $inValue = false, $getLookup = false ) {
// @see less-3.13.1.js#parsers.mixin.call
//
private function parseMixinCall( $inValue, $getLookup = null ) {
$s = $this->input[$this->pos] ?? null;
$important = false;
$lookups = null;
Expand Down Expand Up @@ -2470,7 +2472,7 @@ private function parseDeclaration() {
if ( is_array( $name ) && array_key_exists( 0, $name ) // to satisfy phan
&& $name[0] instanceof Less_Tree_Keyword
&& $name[0]->value && strpos( $name[0]->value, '--' ) === 0 ) {
$value = $this->parsePermissiveValue( ';' );
$value = $this->parsePermissiveValue();
} else {
// Try to store values as anonymous
// If we need the value later we'll re-parse it in ruleset.parseValue
Expand All @@ -2489,7 +2491,7 @@ private function parseDeclaration() {
if ( $value ) {
$important = $this->parseImportant();
} elseif ( $isVariable ) {
$value = $this->parsePermissiveValue( ';' );
$value = $this->parsePermissiveValue();
}
}
if ( $value && ( $this->parseEnd() || $hasDR ) ) {
Expand Down Expand Up @@ -2527,7 +2529,6 @@ private function parseAnonymousValue() {
* @param null|string|array $untilTokens
*/
private function parsePermissiveValue( $untilTokens = null ) {
$value = [];
$tok = $untilTokens ?? ';';
$index = $this->pos;
$result = [];
Expand All @@ -2545,6 +2546,8 @@ private function parsePermissiveValue( $untilTokens = null ) {
if ( $testCurrentChar( $this->input[$this->pos] ) ) {
return;
}

$value = [];
do {
$e = $this->parseComment();
if ( $e ) {
Expand Down Expand Up @@ -2574,7 +2577,7 @@ private function parsePermissiveValue( $untilTokens = null ) {

if ( $value ) {
if ( is_string( $value ) ) {
$this->error( "expected '" . $value . "'" );
$this->Error( "expected '" . $value . "'" );
}
if ( count( $value ) === 1 && $value[0] === ' ' ) {
$this->forget();
Expand Down Expand Up @@ -2849,19 +2852,19 @@ private function parseAtRule() {
if ( $hasIdentifier ) {
$value = $this->parseEntity();
if ( !$value ) {
$this->error( "expected " . $name . " identifier" );
$this->Error( "expected " . $name . " identifier" );
}
} elseif ( $hasExpression ) {
$value = $this->parseExpression();
if ( !$value ) {
$this->error( "expected " . $name . " expression" );
$this->Error( "expected " . $name . " expression" );
}
} elseif ( $hasUnknown ) {
$value = $this->parsePermissiveValue( [ '{', ';' ] );
$hasBlock = $this->input[$this->pos] === '{';
if ( !$value ) {
if ( !$hasBlock && $this->input[$this->pos] !== ';' ) {
$this->error( $name . " rule is missing block or ending semi-colon" );
$this->Error( $name . " rule is missing block or ending semi-colon" );
}
} elseif ( !$value->value ) {
$value = null;
Expand Down
11 changes: 8 additions & 3 deletions lib/Less/Tree/Anonymous.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,23 @@ public function compile( $env ) {
/**
* @param Less_Tree|mixed $x
* @return int|null
* @see less-2.5.3.js#Anonymous.prototype.compare
* @see less-3.13.1.js#Anonymous.prototype.compare
*/
public function compare( $x ) {
return ( is_object( $x ) && $this->toCSS() === $x->toCSS() ) ? 0 : null;
return ( $x instanceof Less_Tree && $this->toCSS() === $x->toCSS() ) ? 0 : null;
}

public function isRulesetLike() {
return $this->rulesetLike;
}

/**
* @see less-3.13.1.js#Anonymous.prototype.genCSS
*/
public function genCSS( $output ) {
if ( $this->value !== "" && $this->value !== 0 ) {
// TODO: When we implement $visibilityInfo, store this result in-class
$nodeVisible = $this->value !== "" && $this->value !== 0;
if ( $nodeVisible ) {
$output->add( $this->value, $this->currentFileInfo, $this->index, $this->mapLines );
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Less/Tree/JavaScript.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* @private
* @see less-3.13.1.js#JavaScript.prototype
*/
class Less_Tree_JavaScript extends Less_Tree {

Expand All @@ -10,10 +11,10 @@ class Less_Tree_JavaScript extends Less_Tree {

/**
* @param string $string
* @param int $index
* @param bool $escaped
* @param int $index
*/
public function __construct( $string, $index, $escaped ) {
public function __construct( $string, $escaped, $index ) {
$this->escaped = $escaped;
$this->expression = $string;
$this->index = $index;
Expand Down
3 changes: 2 additions & 1 deletion lib/Less/Tree/NamespaceValue.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
/**
* @private
* @see less-3.13.1.js#NamespaceValue
* @see less-3.13.1.js#NamespaceValue.prototype
*/
class Less_Tree_NamespaceValue extends Less_Tree {

/** @var Less_Tree_Mixin_Call|Less_Tree_VariableCall */
public $value;
public $index;
public $lookups;
Expand Down

0 comments on commit c28be8d

Please sign in to comment.