Skip to content

Commit

Permalink
Fix ?-> with succeeding PHP keyword (glayzzle#1124)
Browse files Browse the repository at this point in the history
* Use same path in `?->` for eating properties as `->`

* Add test for `?->` with reserved keyword
  • Loading branch information
sxxov authored Sep 11, 2023
1 parent 66c2cc8 commit 80eb946
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lexer/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "?";
Expand Down
24 changes: 24 additions & 0 deletions test/snapshot/__snapshots__/lexer.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
4 changes: 4 additions & 0 deletions test/snapshot/lexer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ describe("Test lexer", function () {
it("test #148 - sensitive lexer", function () {
expect(parser.tokenGetAll("<?php $this-> list;")).toMatchSnapshot();
});

it("test #1003 - null-safe operator with reserved keyword", function () {
expect(parser.parseCode("<?php $a?->class;")).toMatchSnapshot();
});
});

0 comments on commit 80eb946

Please sign in to comment.