Skip to content

Commit 80eb946

Browse files
authored
Fix ?-> with succeeding PHP keyword (#1124)
* Use same path in `?->` for eating properties as `->` * Add test for `?->` with reserved keyword
1 parent 66c2cc8 commit 80eb946

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/lexer/tokens.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ module.exports = {
238238
this._input[this.offset] === "-" &&
239239
this._input[this.offset + 1] === ">"
240240
) {
241-
this.consume(2);
241+
this.consume(1);
242+
this.begin("ST_LOOKING_FOR_PROPERTY").input();
242243
return this.tok.T_NULLSAFE_OBJECT_OPERATOR;
243244
}
244245
return "?";

test/snapshot/__snapshots__/lexer.test.js.snap

+24
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ exports[`Test lexer test #148 - sensitive lexer 1`] = `
125125
]
126126
`;
127127

128+
exports[`Test lexer test #1003 - null-safe operator with reserved keyword 1`] = `
129+
Program {
130+
"children": [
131+
ExpressionStatement {
132+
"expression": NullSafePropertyLookup {
133+
"kind": "nullsafepropertylookup",
134+
"offset": Identifier {
135+
"kind": "identifier",
136+
"name": "class",
137+
},
138+
"what": Variable {
139+
"curly": false,
140+
"kind": "variable",
141+
"name": "a",
142+
},
143+
},
144+
"kind": "expressionstatement",
145+
},
146+
],
147+
"errors": [],
148+
"kind": "program",
149+
}
150+
`;
151+
128152
exports[`Test lexer test comments 1`] = `
129153
Program {
130154
"children": [

test/snapshot/lexer.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,8 @@ describe("Test lexer", function () {
8181
it("test #148 - sensitive lexer", function () {
8282
expect(parser.tokenGetAll("<?php $this-> list;")).toMatchSnapshot();
8383
});
84+
85+
it("test #1003 - null-safe operator with reserved keyword", function () {
86+
expect(parser.parseCode("<?php $a?->class;")).toMatchSnapshot();
87+
});
8488
});

0 commit comments

Comments
 (0)