Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ?-> with succeeding PHP keyword #1124

Merged
merged 2 commits into from
Sep 11, 2023
Merged
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
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();
});
});