Skip to content

Commit b4f32f0

Browse files
committed
fix: don't parse enums for PHP < 8
1 parent 2b769c2 commit b4f32f0

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/lexer/tokens.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ module.exports = {
3333
}
3434

3535
if (id === this.tok.T_ENUM) {
36+
if (this.version < 801) {
37+
return this.tok.T_STRING;
38+
}
3639
const initial = this.offset;
3740
let ch = this.input();
3841
while (ch == " ") {

test/snapshot/__snapshots__/enum.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ Program {
275275
}
276276
`;
277277

278+
exports[`Test enums can't be parsed with PHP < 8 1`] = `"Parse Error : syntax error, unexpected 'Foo' (T_STRING), expecting ';' on line 1"`;
279+
278280
exports[`Test enums cannot have properties 1`] = `"Parse Error : syntax error, unexpected 'int' (T_STRING) on line 3"`;
279281

280282
exports[`Test enums doesn't cause problems when used as identifier 1`] = `

test/snapshot/enum.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,10 @@ describe("Test enums", function () {
101101
`)
102102
).toMatchSnapshot();
103103
});
104+
105+
it("can't be parsed with PHP < 8", function () {
106+
expect(() => {
107+
parser.parseEval("enum Foo {}", { parser: { version: "8.0" } });
108+
}).toThrowErrorMatchingSnapshot();
109+
});
104110
});

0 commit comments

Comments
 (0)