diff --git a/src/parser/class.js b/src/parser/class.js index d9070f434..089701716 100644 --- a/src/parser/class.js +++ b/src/parser/class.js @@ -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(); @@ -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(); @@ -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(); diff --git a/src/parser/function.js b/src/parser/function.js index 6a84e4a5d..ba62bea15 100644 --- a/src/parser/function.js +++ b/src/parser/function.js @@ -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) { @@ -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(); diff --git a/test/snapshot/__snapshots__/enum.test.js.snap b/test/snapshot/__snapshots__/enum.test.js.snap index bd3370029..9bc2e6de8 100644 --- a/test/snapshot/__snapshots__/enum.test.js.snap +++ b/test/snapshot/__snapshots__/enum.test.js.snap @@ -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 [ diff --git a/test/snapshot/enum.test.js b/test/snapshot/enum.test.js index ffc7b0e04..0d433fa25 100644 --- a/test/snapshot/enum.test.js +++ b/test/snapshot/enum.test.js @@ -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(); + }); });