diff --git a/lib/Less/Parser.php b/lib/Less/Parser.php index 904af615..ef8a8164 100644 --- a/lib/Less/Parser.php +++ b/lib/Less/Parser.php @@ -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 @@ -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(); } @@ -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; @@ -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 @@ -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 ) ) { @@ -2527,7 +2529,6 @@ private function parseAnonymousValue() { * @param null|string|array $untilTokens */ private function parsePermissiveValue( $untilTokens = null ) { - $value = []; $tok = $untilTokens ?? ';'; $index = $this->pos; $result = []; @@ -2545,6 +2546,8 @@ private function parsePermissiveValue( $untilTokens = null ) { if ( $testCurrentChar( $this->input[$this->pos] ) ) { return; } + + $value = []; do { $e = $this->parseComment(); if ( $e ) { @@ -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(); @@ -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; diff --git a/lib/Less/Tree/Anonymous.php b/lib/Less/Tree/Anonymous.php index f7235824..dc48cac2 100644 --- a/lib/Less/Tree/Anonymous.php +++ b/lib/Less/Tree/Anonymous.php @@ -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 ); } } diff --git a/lib/Less/Tree/JavaScript.php b/lib/Less/Tree/JavaScript.php index ff432c19..1bb1e8b4 100644 --- a/lib/Less/Tree/JavaScript.php +++ b/lib/Less/Tree/JavaScript.php @@ -1,6 +1,7 @@ escaped = $escaped; $this->expression = $string; $this->index = $index; diff --git a/lib/Less/Tree/NamespaceValue.php b/lib/Less/Tree/NamespaceValue.php index 0559860a..1a7fc858 100644 --- a/lib/Less/Tree/NamespaceValue.php +++ b/lib/Less/Tree/NamespaceValue.php @@ -1,10 +1,11 @@