From c1afef2dc8f4049b684bd54243f28a7a90c378f6 Mon Sep 17 00:00:00 2001 From: jason lim <50891910+Sxxov@users.noreply.github.com> Date: Tue, 4 Jul 2023 02:18:26 +0800 Subject: [PATCH 1/2] Use same path in `?->` for eating properties as `->` --- src/lexer/tokens.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lexer/tokens.js b/src/lexer/tokens.js index c57c0b3ca..217524ca8 100644 --- a/src/lexer/tokens.js +++ b/src/lexer/tokens.js @@ -238,7 +238,8 @@ module.exports = { this._input[this.offset] === "-" && this._input[this.offset + 1] === ">" ) { - this.consume(2); + this.consume(1); + this.begin("ST_LOOKING_FOR_PROPERTY").input(); return this.tok.T_NULLSAFE_OBJECT_OPERATOR; } return "?"; From 57854ca752975cc1ac0054270e80197481d4ca01 Mon Sep 17 00:00:00 2001 From: jason lim <50891910+Sxxov@users.noreply.github.com> Date: Mon, 11 Sep 2023 05:48:03 +0800 Subject: [PATCH 2/2] Add test for `?->` with reserved keyword --- .../snapshot/__snapshots__/lexer.test.js.snap | 24 +++++++++++++++++++ test/snapshot/lexer.test.js | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/test/snapshot/__snapshots__/lexer.test.js.snap b/test/snapshot/__snapshots__/lexer.test.js.snap index ced4c81eb..e71bb1665 100644 --- a/test/snapshot/__snapshots__/lexer.test.js.snap +++ b/test/snapshot/__snapshots__/lexer.test.js.snap @@ -125,6 +125,30 @@ exports[`Test lexer test #148 - sensitive lexer 1`] = ` ] `; +exports[`Test lexer test #1003 - null-safe operator with reserved keyword 1`] = ` +Program { + "children": [ + ExpressionStatement { + "expression": NullSafePropertyLookup { + "kind": "nullsafepropertylookup", + "offset": Identifier { + "kind": "identifier", + "name": "class", + }, + "what": Variable { + "curly": false, + "kind": "variable", + "name": "a", + }, + }, + "kind": "expressionstatement", + }, + ], + "errors": [], + "kind": "program", +} +`; + exports[`Test lexer test comments 1`] = ` Program { "children": [ diff --git a/test/snapshot/lexer.test.js b/test/snapshot/lexer.test.js index 2888fdef8..ab6b3155b 100644 --- a/test/snapshot/lexer.test.js +++ b/test/snapshot/lexer.test.js @@ -81,4 +81,8 @@ describe("Test lexer", function () { it("test #148 - sensitive lexer", function () { expect(parser.tokenGetAll(" list;")).toMatchSnapshot(); }); + + it("test #1003 - null-safe operator with reserved keyword", function () { + expect(parser.parseCode("class;")).toMatchSnapshot(); + }); });