Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/parser/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
this.next();
return null;
}
this.next().expect(this.tok.T_STRING);
this.next().expect([this.tok.T_STRING, this.tok.T_ENUM]);
let propName = this.node("identifier");
const name = this.text();
this.next();
Expand Down Expand Up @@ -381,7 +381,7 @@ module.exports = {
this.next();
return null;
}
this.next().expect(this.tok.T_STRING);
this.next().expect([this.tok.T_STRING, this.tok.T_ENUM]);
let propName = this.node("identifier");
const name = this.text();
this.next();
Expand Down Expand Up @@ -465,7 +465,7 @@ module.exports = {
this.next();
return null;
}
this.next().expect(this.tok.T_STRING);
this.next().expect([this.tok.T_STRING, this.tok.T_ENUM]);
let propName = this.node("identifier");
const name = this.text();
this.next();
Expand Down
7 changes: 5 additions & 2 deletions src/parser/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ module.exports = {
}
} else {
if (this.version >= 700) {
if (this.token === this.tok.T_STRING) {
if (
this.token === this.tok.T_STRING ||
this.token === this.tok.T_ENUM
) {
name = this.text();
this.next();
} else if (this.version >= 704) {
Expand All @@ -111,7 +114,7 @@ module.exports = {
this.next();
}
} else {
if (this.expect(this.tok.T_STRING)) {
if (this.expect([this.tok.T_STRING, this.tok.T_ENUM])) {
name = this.text();
}
this.next();
Expand Down
78 changes: 78 additions & 0 deletions test/snapshot/__snapshots__/enum.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,84 @@ Program {

exports[`Test enums cannot have properties 1`] = `"Parse Error : syntax error, unexpected 'int' (T_STRING) on line 3"`;

exports[`Test enums doesn't cause problems when used as identifier 1`] = `
Program {
"children": Array [
Class {
"attrGroups": Array [],
"body": Array [
Method {
"arguments": Array [],
"attrGroups": Array [],
"body": Block {
"children": Array [],
"kind": "block",
},
"byref": false,
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "method",
"name": Identifier {
"kind": "identifier",
"name": "enum",
},
"nullable": false,
"type": null,
"visibility": "",
},
],
"extends": null,
"implements": null,
"isAbstract": false,
"isAnonymous": false,
"isFinal": false,
"kind": "class",
"name": Identifier {
"kind": "identifier",
"name": "Enum",
},
},
Interface {
"attrGroups": Array [],
"body": Array [],
"extends": null,
"kind": "interface",
"name": Identifier {
"kind": "identifier",
"name": "Enum",
},
},
Trait {
"body": Array [],
"kind": "trait",
"name": Identifier {
"kind": "identifier",
"name": "Enum",
},
},
_Function {
"arguments": Array [],
"attrGroups": Array [],
"body": Block {
"children": Array [],
"kind": "block",
},
"byref": false,
"kind": "function",
"name": Identifier {
"kind": "identifier",
"name": "enum",
},
"nullable": false,
"type": null,
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`Test enums empty 1`] = `
Program {
"children": Array [
Expand Down
11 changes: 11 additions & 0 deletions test/snapshot/enum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,15 @@ describe("Test enums", function () {
`);
}).toThrowErrorMatchingSnapshot();
});

it("doesn't cause problems when used as identifier", function () {
expect(
parser.parseEval(`
class Enum { function enum () {} }
interface Enum {}
trait Enum {}
function enum() {}
`)
).toMatchSnapshot();
});
});