Skip to content

Commit

Permalink
Merge "Less_Parser: Reduce minor skipWhitespace() differences with up…
Browse files Browse the repository at this point in the history
…stream"
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Apr 24, 2024
2 parents 394ef4c + 366e6c0 commit a82ffbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions lib/Less/Parser.php
Expand Up @@ -860,11 +860,7 @@ private function peekChar( $tok ) {
private function skipWhitespace( $length ) {
$this->pos += $length;

// we do not increment the $this->pos as upstream, because $this->pos is updated with
// comment length or by amount of whitespaces strsspn finds. What upstream does is ignores
// whitespaces, which makes the for loop keep iterating.
// phpcs:ignore Generic.CodeAnalysis.ForLoopShouldBeWhileLoop.CanSimplify
for ( ; $this->pos < $this->input_len; ) {
for ( ; $this->pos < $this->input_len; $this->pos++ ) {
$currentChar = $this->input[$this->pos];

if ( $this->autoCommentAbsorb && $currentChar === '/' ) {
Expand All @@ -881,28 +877,29 @@ private function skipWhitespace( $length ) {
continue;
} elseif ( $nextChar === '*' ) {
$nextStarSlash = strpos( $this->input, "*/", $this->pos + 2 );
if ( $nextStarSlash ) {
if ( $nextStarSlash !== false ) {
$comment = [
'index' => $this->pos,
'text' => substr( $this->input, $this->pos, $nextStarSlash + 2 -
$this->pos ),
'isLineComment' => false,
'index' => $this->pos
];
$this->pos += strlen( $comment['text'] ) - 1;
$this->commentStore[] = $comment;
$this->pos += strlen( $comment['text'] );
continue;
}
}
break;
}

if ( $currentChar !== " " && $currentChar !== "\n"
&& $currentChar !== "\t" && $currentChar !== "\r" ) {
// Optimization: Skip over irrelevant chars without slow loop
$skip = strspn( $this->input, " \n\t\r", $this->pos );
if ( $skip ) {
$this->pos += $skip - 1;
}
if ( !$skip && $this->pos < $this->input_len ) {
break;
}

// Optimization: Skip over irrelevant chars without slow loop
$this->pos += strspn( $this->input, "\n\r\t ", $this->pos );
}
}

Expand Down Expand Up @@ -1036,7 +1033,9 @@ private function parsePrimary() {
/**
* comments are collected by the main parsing mechanism and then assigned to nodes
* where the current structure allows it
*
* @return Less_Tree_Comment|void
* @see less-2.5.3.js#parsers.comment
*/
private function parseComment() {
$comment = array_shift( $this->commentStore );
Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/Call.php
Expand Up @@ -26,7 +26,7 @@ public function accept( $visitor ) {
}

/**
* @see less-2.5.3.js#functionCaller.call
* @see less-2.5.3.js#functionCaller.prototype.call
*/
private function functionCaller( $function, array $arguments ) {
// This code is terrible and should be replaced as per this issue...
Expand Down

0 comments on commit a82ffbe

Please sign in to comment.