Skip to content

Commit c28be8d

Browse files
jenkins-botGerrit Code Review
jenkins-bot
authored and
Gerrit Code Review
committed
Merge "Minor 3.13 sync in Less_Tree for Anonymous, NamespaceValue, JavaScript"
2 parents 96ca779 + a7fef13 commit c28be8d

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

lib/Less/Parser.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ private function parseUnicodeDescriptor() {
16151615
* `window.location.href`
16161616
*
16171617
* @return Less_Tree_JavaScript|null
1618-
* @see less-2.5.3.js#parsers.entities.javascript
1618+
* @see less-3.13.1.js#parsers.entities.javascript
16191619
*/
16201620
private function parseEntitiesJavascript() {
16211621
// Optimization: Hardcode first char, to avoid save()/restore() overhead
@@ -1642,7 +1642,7 @@ private function parseEntitiesJavascript() {
16421642
$js = $this->matchReg( '/\\G[^`]*`/' );
16431643
if ( $js ) {
16441644
$this->forget();
1645-
return new Less_Tree_JavaScript( substr( $js, 0, -1 ), $index, $isEscaped );
1645+
return new Less_Tree_JavaScript( substr( $js, 0, -1 ), $isEscaped, $index );
16461646
}
16471647
$this->restore();
16481648
}
@@ -1764,7 +1764,9 @@ private function parseExtend( $isRule = false ) {
17641764
// namespaced, but we only support the child and descendant
17651765
// selector for now.
17661766
//
1767-
private function parseMixinCall( $inValue = false, $getLookup = false ) {
1767+
// @see less-3.13.1.js#parsers.mixin.call
1768+
//
1769+
private function parseMixinCall( $inValue, $getLookup = null ) {
17681770
$s = $this->input[$this->pos] ?? null;
17691771
$important = false;
17701772
$lookups = null;
@@ -2470,7 +2472,7 @@ private function parseDeclaration() {
24702472
if ( is_array( $name ) && array_key_exists( 0, $name ) // to satisfy phan
24712473
&& $name[0] instanceof Less_Tree_Keyword
24722474
&& $name[0]->value && strpos( $name[0]->value, '--' ) === 0 ) {
2473-
$value = $this->parsePermissiveValue( ';' );
2475+
$value = $this->parsePermissiveValue();
24742476
} else {
24752477
// Try to store values as anonymous
24762478
// If we need the value later we'll re-parse it in ruleset.parseValue
@@ -2489,7 +2491,7 @@ private function parseDeclaration() {
24892491
if ( $value ) {
24902492
$important = $this->parseImportant();
24912493
} elseif ( $isVariable ) {
2492-
$value = $this->parsePermissiveValue( ';' );
2494+
$value = $this->parsePermissiveValue();
24932495
}
24942496
}
24952497
if ( $value && ( $this->parseEnd() || $hasDR ) ) {
@@ -2527,7 +2529,6 @@ private function parseAnonymousValue() {
25272529
* @param null|string|array $untilTokens
25282530
*/
25292531
private function parsePermissiveValue( $untilTokens = null ) {
2530-
$value = [];
25312532
$tok = $untilTokens ?? ';';
25322533
$index = $this->pos;
25332534
$result = [];
@@ -2545,6 +2546,8 @@ private function parsePermissiveValue( $untilTokens = null ) {
25452546
if ( $testCurrentChar( $this->input[$this->pos] ) ) {
25462547
return;
25472548
}
2549+
2550+
$value = [];
25482551
do {
25492552
$e = $this->parseComment();
25502553
if ( $e ) {
@@ -2574,7 +2577,7 @@ private function parsePermissiveValue( $untilTokens = null ) {
25742577

25752578
if ( $value ) {
25762579
if ( is_string( $value ) ) {
2577-
$this->error( "expected '" . $value . "'" );
2580+
$this->Error( "expected '" . $value . "'" );
25782581
}
25792582
if ( count( $value ) === 1 && $value[0] === ' ' ) {
25802583
$this->forget();
@@ -2849,19 +2852,19 @@ private function parseAtRule() {
28492852
if ( $hasIdentifier ) {
28502853
$value = $this->parseEntity();
28512854
if ( !$value ) {
2852-
$this->error( "expected " . $name . " identifier" );
2855+
$this->Error( "expected " . $name . " identifier" );
28532856
}
28542857
} elseif ( $hasExpression ) {
28552858
$value = $this->parseExpression();
28562859
if ( !$value ) {
2857-
$this->error( "expected " . $name . " expression" );
2860+
$this->Error( "expected " . $name . " expression" );
28582861
}
28592862
} elseif ( $hasUnknown ) {
28602863
$value = $this->parsePermissiveValue( [ '{', ';' ] );
28612864
$hasBlock = $this->input[$this->pos] === '{';
28622865
if ( !$value ) {
28632866
if ( !$hasBlock && $this->input[$this->pos] !== ';' ) {
2864-
$this->error( $name . " rule is missing block or ending semi-colon" );
2867+
$this->Error( $name . " rule is missing block or ending semi-colon" );
28652868
}
28662869
} elseif ( !$value->value ) {
28672870
$value = null;

lib/Less/Tree/Anonymous.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,23 @@ public function compile( $env ) {
3939
/**
4040
* @param Less_Tree|mixed $x
4141
* @return int|null
42-
* @see less-2.5.3.js#Anonymous.prototype.compare
42+
* @see less-3.13.1.js#Anonymous.prototype.compare
4343
*/
4444
public function compare( $x ) {
45-
return ( is_object( $x ) && $this->toCSS() === $x->toCSS() ) ? 0 : null;
45+
return ( $x instanceof Less_Tree && $this->toCSS() === $x->toCSS() ) ? 0 : null;
4646
}
4747

4848
public function isRulesetLike() {
4949
return $this->rulesetLike;
5050
}
5151

52+
/**
53+
* @see less-3.13.1.js#Anonymous.prototype.genCSS
54+
*/
5255
public function genCSS( $output ) {
53-
if ( $this->value !== "" && $this->value !== 0 ) {
56+
// TODO: When we implement $visibilityInfo, store this result in-class
57+
$nodeVisible = $this->value !== "" && $this->value !== 0;
58+
if ( $nodeVisible ) {
5459
$output->add( $this->value, $this->currentFileInfo, $this->index, $this->mapLines );
5560
}
5661
}

lib/Less/Tree/JavaScript.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* @private
4+
* @see less-3.13.1.js#JavaScript.prototype
45
*/
56
class Less_Tree_JavaScript extends Less_Tree {
67

@@ -10,10 +11,10 @@ class Less_Tree_JavaScript extends Less_Tree {
1011

1112
/**
1213
* @param string $string
13-
* @param int $index
1414
* @param bool $escaped
15+
* @param int $index
1516
*/
16-
public function __construct( $string, $index, $escaped ) {
17+
public function __construct( $string, $escaped, $index ) {
1718
$this->escaped = $escaped;
1819
$this->expression = $string;
1920
$this->index = $index;

lib/Less/Tree/NamespaceValue.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22
/**
33
* @private
4-
* @see less-3.13.1.js#NamespaceValue
4+
* @see less-3.13.1.js#NamespaceValue.prototype
55
*/
66
class Less_Tree_NamespaceValue extends Less_Tree {
77

8+
/** @var Less_Tree_Mixin_Call|Less_Tree_VariableCall */
89
public $value;
910
public $index;
1011
public $lookups;

0 commit comments

Comments
 (0)