Skip to content

Commit

Permalink
Fixed type vs string
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy Quissens committed Nov 8, 2020
1 parent 1d1bc8a commit ddd477d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lib/PhpParser/Internal/TokenStream.php
Expand Up @@ -64,12 +64,19 @@ public function haveTokenImmediatelyBefore(int $pos, $expectedTokenType) : bool
$tokens = $this->tokens;
$pos--;
for (; $pos >= 0; $pos--) {
$tokenType = $tokens[$pos][0];
$token = $tokens[$pos];
if (is_array($token)) {
$index = is_string($expectedTokenType) ? 1 : 0;
$tokenType = $token[$index];
} else {
$tokenType = $token;
}
if ($tokenType === $expectedTokenType) {
return true;
}
if ($tokenType !== \T_WHITESPACE
&& $tokenType !== \T_COMMENT && $tokenType !== \T_DOC_COMMENT) {
if (
$tokenType !== \T_WHITESPACE && $tokenType !== \T_COMMENT && $tokenType !== \T_DOC_COMMENT && $tokenType !== ' '
) {
break;
}
}
Expand All @@ -90,12 +97,19 @@ public function haveTokenImmediatelyAfter(int $pos, $expectedTokenType) : bool {
$tokens = $this->tokens;
$pos++;
for (; $pos < \count($tokens); $pos++) {
$tokenType = $tokens[$pos][0];
$token = $tokens[$pos];
if (is_array($token)) {
$index = is_string($expectedTokenType) ? 1 : 0;
$tokenType = $token[$index];
} else {
$tokenType = $token;
}
if ($tokenType === $expectedTokenType) {
return true;
}
if ($tokenType !== \T_WHITESPACE
&& $tokenType !== \T_COMMENT && $tokenType !== \T_DOC_COMMENT) {
if (
$tokenType !== \T_WHITESPACE && $tokenType !== \T_COMMENT && $tokenType !== \T_DOC_COMMENT && $tokenType !== ' '
) {
break;
}
}
Expand Down
@@ -0,0 +1,9 @@
Nop statement with comment at end (#513)
-----
<?php
"{$e}";
-----
$stmts[0]->expr->parts[0]->setAttribute('origNode', null);
-----
<?php
"{$e}";

0 comments on commit ddd477d

Please sign in to comment.