Skip to content

Commit

Permalink
Don't set start attributes for whitespace
Browse files Browse the repository at this point in the history
These will get overwritten later anyway.
  • Loading branch information
nikic committed Jul 9, 2023
1 parent c48ee36 commit 748aab3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions lib/PhpParser/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,6 @@ public function getNextToken(&$value = null, &$startAttributes = null, &$endAttr
while (1) {
$token = $this->tokens[++$this->pos];

if ($this->attributeStartLineUsed) {
$startAttributes['startLine'] = $token->line;
}
if ($this->attributeStartTokenPosUsed) {
$startAttributes['startTokenPos'] = $this->pos;
}
if ($this->attributeStartFilePosUsed) {
$startAttributes['startFilePos'] = $token->pos;
}

$id = $token->id;
if (isset($this->dropTokens[$id])) {
if (\T_COMMENT === $id || \T_DOC_COMMENT === $id) {
Expand All @@ -219,6 +209,16 @@ public function getNextToken(&$value = null, &$startAttributes = null, &$endAttr
continue;
}

if ($this->attributeStartLineUsed) {
$startAttributes['startLine'] = $token->line;
}
if ($this->attributeStartTokenPosUsed) {
$startAttributes['startTokenPos'] = $this->pos;
}
if ($this->attributeStartFilePosUsed) {
$startAttributes['startFilePos'] = $token->pos;
}

$value = $token->text;
if (\T_CLOSE_TAG === $token->id) {
$this->prevCloseTagHasNewline = false !== strpos($value, "\n")
Expand Down
4 changes: 2 additions & 2 deletions test/PhpParser/NodeAbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ function functionName(&$a = 0, $b = 1.0) {
"attrGroups": [],
"namespacedName": null,
"attributes": {
"startLine": 4,
"comments": [
{
"nodeType": "Comment",
Expand All @@ -332,6 +331,7 @@ function functionName(&$a = 0, $b = 1.0) {
"endTokenPos": 3
}
],
"startLine": 4,
"endLine": 6
}
}
Expand All @@ -342,7 +342,6 @@ function functionName(&$a = 0, $b = 1.0) {
{
"nodeType": "Stmt_Function",
"attributes": {
"startLine": 4,
"comments": [
{
"nodeType": "Comment",
Expand All @@ -365,6 +364,7 @@ function functionName(&$a = 0, $b = 1.0) {
"endTokenPos": 3
}
],
"startLine": 4,
"endLine": 6
},
"byRef": false,
Expand Down

0 comments on commit 748aab3

Please sign in to comment.