Skip to content

Commit d9e3877

Browse files
committed
Make HaltCompilerStatement inline html start=fullStart
Include whitespace before the data as part of the data for invalid ASTs.
1 parent 2218a40 commit d9e3877

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

src/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,7 @@ private function parseHaltCompilerStatement($parentNode) {
28762876
if ($remainingTokens) {
28772877
$firstToken = $remainingTokens[0];
28782878
$lastToken = end($remainingTokens);
2879-
$haltCompilerStatement->data = new Token(TokenKind::InlineHtml, $firstToken->fullStart, $firstToken->start, $lastToken->fullStart + $lastToken->length - $firstToken->fullStart);
2879+
$haltCompilerStatement->data = new Token(TokenKind::InlineHtml, $firstToken->fullStart, $firstToken->fullStart, $lastToken->fullStart + $lastToken->length - $firstToken->fullStart);
28802880
}
28812881
return $haltCompilerStatement;
28822882
}

tests/cases/parser/haltCompiler7.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
// no matter what those tokens happen to be, so tolerant-php-parser combines unexpected tokens into T_INLINE_HTML
55
// so that no subsequent statements get emitted.
66
// (T_HALT_COMPILER is forbidden in other node types)
7-
__halt_compiler() + 1;
7+
// In this invalid AST, treat " + 1;\n" as the inline data after the missing semicolon.
8+
__halt_compiler() + 1;

tests/cases/parser/haltCompiler7.php.diag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"kind": 0,
44
"message": "';' expected.",
5-
"start": 390,
5+
"start": 482,
66
"length": 0
77
}
88
]

tests/cases/parser/haltCompiler7.php.tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"data": {
3434
"kind": "InlineHtml",
35-
"textLength": 5
35+
"textLength": 10
3636
}
3737
}
3838
}

0 commit comments

Comments
 (0)