@@ -1417,7 +1417,7 @@ private function parseStringLiteralExpression2($parentNode): StringLiteral {
14171417 case TokenKind::DollarOpenBraceToken:
14181418 case TokenKind::OpenBraceDollarToken:
14191419 $ expression ->children [] = $ this ->eat (TokenKind::DollarOpenBraceToken, TokenKind::OpenBraceDollarToken);
1420- /**
1420+ /**
14211421 * @phpstan-ignore-next-line "Strict comparison using
14221422 * === between 403|404 and 408 will always evaluate to
14231423 * false" is wrong because those tokens were eaten above
@@ -2802,10 +2802,6 @@ private function parseListIntrinsicExpression($parentNode) {
28022802 return $ listExpression ;
28032803 }
28042804
2805- private function isArrayElementStart ($ token ) {
2806- return ($ this ->isArrayElementStartFn ())($ token );
2807- }
2808-
28092805 private function isArrayElementStartFn () {
28102806 return function ($ token ) {
28112807 return $ token ->kind === TokenKind::AmpersandToken || $ token ->kind === TokenKind::DotDotDotToken || $ this ->isExpressionStart ($ token );
@@ -3370,6 +3366,16 @@ private function parseClassConstDeclaration($parentNode, $modifiers) {
33703366
33713367 $ classConstDeclaration ->modifiers = $ modifiers ;
33723368 $ classConstDeclaration ->constKeyword = $ this ->eat1 (TokenKind::ConstKeyword);
3369+ // Handle class constant declarations such as `const X|Y Z = 123;` or `const X = 123;`.
3370+ // This is similar to lookahead().
3371+ $ startPos = $ this ->lexer ->getCurrentPosition ();
3372+ $ startToken = $ this ->token ;
3373+ $ classConstDeclaration ->typeDeclarationList = $ this ->tryParseParameterTypeDeclarationList ($ classConstDeclaration );
3374+ if (in_array ($ this ->token ->kind , [TokenKind::EqualsToken, TokenKind::CommaToken, TokenKind::SemicolonToken]) && $ this ->lexer ->getCurrentPosition () <= $ startPos + 1 ) {
3375+ $ classConstDeclaration ->typeDeclarationList = null ;
3376+ $ this ->lexer ->setCurrentPosition ($ startPos );
3377+ $ this ->token = $ startToken ;
3378+ }
33733379 $ classConstDeclaration ->constElements = $ this ->parseConstElements ($ classConstDeclaration );
33743380 $ classConstDeclaration ->semicolon = $ this ->eat1 (TokenKind::SemicolonToken);
33753381
0 commit comments