Skip to content

Commit

Permalink
Merge "Fix ParseError for comments after rule name or in @keyframes"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Apr 13, 2024
2 parents 9105597 + a4411b4 commit 8c8f446
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 5 deletions.
24 changes: 21 additions & 3 deletions lib/Less/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,9 @@ private function parseComment() {
return new Less_Tree_Comment( $match, true, $this->pos, $this->env->currentFileInfo );
}

// $comment = $this->matchReg('/\\G\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/');
$comment = $this->matchReg( '/\\G\/\*(?s).*?\*+\/\n?/' );// not the same as less.js to prevent fatal errors
// not the same as less.js to prevent fatal errors
// $this->matchReg( '/\\G\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/') ;
$comment = $this->matchReg( '/\\G\/\*(?s).*?\*+\/\n?/' );
if ( $comment ) {
return new Less_Tree_Comment( $comment, false, $this->pos, $this->env->currentFileInfo );
}
Expand Down Expand Up @@ -2018,7 +2019,7 @@ private function parseRule( $tryAnonymous = null ) {
if ( $isVariable ) {
$value = $this->parseDetachedRuleset();
}

$this->parseComments();
if ( !$value ) {
// a name returned by this.ruleProperty() is always an array of the form:
// [string-1, ..., string-n, ""] or [string-1, ..., string-n, "+"]
Expand Down Expand Up @@ -2302,6 +2303,8 @@ private function parseDirective() {
$isRooted = false;
break;
}
// TODO: T353132 - differs from less.js - we don't have the ParserInput yet
$this->parseComments();

if ( $hasIdentifier ) {
$value = $this->parseEntity();
Expand All @@ -2321,6 +2324,9 @@ private function parseDirective() {
}
}

// TODO: T353132 - differs from less.js - we don't have the ParserInput yet
$this->parseComments();

if ( $hasBlock ) {
$rules = $this->parseBlockRuleset();
}
Expand Down Expand Up @@ -2581,6 +2587,7 @@ private function parseProperty() {
* eg: 'color', 'width', 'height', etc
*
* @return array<Less_Tree_Keyword|Less_Tree_Variable>
* @see less-2.5.3.js#parsers.ruleProperty
*/
private function parseRuleProperty() {
$name = [];
Expand All @@ -2600,6 +2607,8 @@ private function parseRuleProperty() {
// Consume!
// @phan-suppress-next-line PhanPluginEmptyStatementWhileLoop
while ( $this->rulePropertyMatch( '/\\G((?:[\w-]+)|(?:@\{[\w-]+\}))/', $index, $name ) );
// @phan-suppress-next-line PhanPluginEmptyStatementWhileLoop
while ( $this->rulePropertyCutOutBlockComments() );

if ( ( count( $name ) > 1 ) && $this->rulePropertyMatch( '/\\G((?:\+_|\+)?)\s*:/', $index, $name ) ) {
$this->forget();
Expand Down Expand Up @@ -2633,6 +2642,15 @@ private function rulePropertyMatch( $re, &$index, &$name ) {
}
}

private function rulePropertyCutOutBlockComments() {
// not the same as less.js to prevent fatal errors
// similar to parseComment()
// '/\\G\s*\/\*(?:[^*]|\*+[^\/*])*\*+\//'
$re = '/\\G\s*\/\*(?s).*?\*+\//';
$chunk = $this->matchReg( $re );
return $chunk != null;
}

public static function serializeVars( $vars ) {
$s = '';

Expand Down
82 changes: 82 additions & 0 deletions test/Fixtures/lessjs-2.5.3/override/comments.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/******************\
* *
* Comment Header *
* *
\******************/
/*
Comment
*/
/*
* Comment Test
*
* - cloudhead (http://cloudhead.net)
*
*/
/* Colors
* ------
* #EDF8FC (background blue)
* #166C89 (darkest blue)
*
* Text:
* #333 (standard text) // A comment within a comment!
* #1F9EC9 (standard link)
*
*/
/* @group Variables
------------------- */
#comments,
.comments {
/**/
color: red;
/* A C-style comment */
/* A C-style comment */
background-color: orange;
font-size: 12px;
/* lost comment */
content: "content";
border: 1px solid black;
padding: 0;
margin: 2em;
}
/* commented out
#more-comments {
color: grey;
}
*/
.selector,
.lots,
.comments {
color: grey, /* blue */ orange;
-webkit-border-radius: 2px /* webkit only */;
-moz-border-radius: 8px /* moz only with operation */;
}
.test {
color: 1px;
}
.sr-only-focusable {
clip: auto;
}
@-webkit-keyframes hover {
0% {
color: red;
}
}
#last {
color: blue;
}
/* */
/* { */
/* */
/* */
/* */
#div {
color: #A33;
}
/* } */
/*by block */
#output-block {
comment: /* // Not commented out // */;
}
/*comment on last line*/
3 changes: 1 addition & 2 deletions test/phpunit/FixturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class phpunit_FixturesTest extends phpunit_bootstrap {
'parens' => true,

// Temporary disabled
'comments' => true, // T353131 & T353132
'comments2' => true, // T353131 & T353132
'comments2' => true, // T353132
'css' => true, // T352911 & T352866
'css-guards' => true, // T353144
'import' => true, // T353146
Expand Down

0 comments on commit 8c8f446

Please sign in to comment.