Open
Description
/cc @genintho
Context
Problem
- class constant Syntax error introduced in 3.2.2 (Fix Typed Class Constants parsing #1147)
- 3.2.1 does not occur this syntax error
- https://github.com/prettier/plugin-php/blob/5f75fea7979af4dd530ea8cac827fb6314264621/tests/comments/classconstant.php#L16-L24
- It occured when class constant is multilined and comment is inserted before
=
.
e.g.
<?php
$var = new class {
public
const
CONSTANT
// Comment 3
=
'string';
};
How to reproduce
- create test file
vim test.js
const engine = require(".");
// initialize a new parser instance
const parser = new engine({
// some options :
parser: {
extractDoc: true,
phpVersion: "8.3",
},
ast: {
withPositions: true,
withSource: true,
},
});
const target = `
<?php
$var = new class {
public
const
CONSTANT
// Comment 3
=
'string';
};
`;
// Retrieve the AST from the specified source
parser.parseCode(target);
- execute
$ node test.js
/home/shuhei/develop/php-parser/src/parser.js:357
throw err;
^
SyntaxError: Parse Error : syntax error, unexpected '=' on line 11
at Parser.raiseError (/home/shuhei/develop/php-parser/src/parser.js:349:17)
at Parser.error (/home/shuhei/develop/php-parser/src/parser.js:397:15)
at Parser.expect (/home/shuhei/develop/php-parser/src/parser.js:577:10)
at Parser.read_constant_declaration (/home/shuhei/develop/php-parser/src/parser/class.js:262:16)
at Parser.read_list (/home/shuhei/develop/php-parser/src/parser/utils.js:76:33)
at Parser.read_constant_list (/home/shuhei/develop/php-parser/src/parser/class.js:234:24)
at Parser.read_class_body (/home/shuhei/develop/php-parser/src/parser/class.js:117:32)
at Parser.read_new_expr (/home/shuhei/develop/php-parser/src/parser/expr.js:769:28)
at Parser.read_expr_item (/home/shuhei/develop/php-parser/src/parser/expr.js:353:21)
at Parser.read_expr (/home/shuhei/develop/php-parser/src/parser/expr.js:18:19) {
lineNumber: 11,
fileName: 'eval',
columnNumber: 4
}
Node.js v20.12.2