@@ -1419,7 +1419,7 @@ private function parseStringLiteralExpression2($parentNode): StringLiteral {
14191419 case TokenKind::DollarOpenBraceToken:
14201420 case TokenKind::OpenBraceDollarToken:
14211421 $ expression ->children [] = $ this ->eat (TokenKind::DollarOpenBraceToken, TokenKind::OpenBraceDollarToken);
1422- /**
1422+ /**
14231423 * @phpstan-ignore-next-line "Strict comparison using
14241424 * === between 403|404 and 408 will always evaluate to
14251425 * false" is wrong because those tokens were eaten above
@@ -2804,10 +2804,6 @@ private function parseListIntrinsicExpression($parentNode) {
28042804 return $ listExpression ;
28052805 }
28062806
2807- private function isArrayElementStart ($ token ) {
2808- return ($ this ->isArrayElementStartFn ())($ token );
2809- }
2810-
28112807 private function isArrayElementStartFn () {
28122808 return function ($ token ) {
28132809 return $ token ->kind === TokenKind::AmpersandToken || $ token ->kind === TokenKind::DotDotDotToken || $ this ->isExpressionStart ($ token );
@@ -3372,6 +3368,16 @@ private function parseClassConstDeclaration($parentNode, $modifiers) {
33723368
33733369 $ classConstDeclaration ->modifiers = $ modifiers ;
33743370 $ classConstDeclaration ->constKeyword = $ this ->eat1 (TokenKind::ConstKeyword);
3371+ // Handle class constant declarations such as `const X|Y Z = 123;` or `const X = 123;`.
3372+ // This is similar to lookahead().
3373+ $ startPos = $ this ->lexer ->getCurrentPosition ();
3374+ $ startToken = $ this ->token ;
3375+ $ classConstDeclaration ->typeDeclarationList = $ this ->tryParseParameterTypeDeclarationList ($ classConstDeclaration );
3376+ if (in_array ($ this ->token ->kind , [TokenKind::EqualsToken, TokenKind::CommaToken, TokenKind::SemicolonToken]) && $ this ->lexer ->getCurrentPosition () <= $ startPos + 1 ) {
3377+ $ classConstDeclaration ->typeDeclarationList = null ;
3378+ $ this ->lexer ->setCurrentPosition ($ startPos );
3379+ $ this ->token = $ startToken ;
3380+ }
33753381 $ classConstDeclaration ->constElements = $ this ->parseConstElements ($ classConstDeclaration );
33763382 $ classConstDeclaration ->semicolon = $ this ->eat1 (TokenKind::SemicolonToken);
33773383
0 commit comments