Skip to content

Commit

Permalink
Merge pull request glayzzle#960 from glayzzle/fix-fqn-property-types
Browse files Browse the repository at this point in the history
Handle property types using T_NAME_* tokens.
  • Loading branch information
czosel authored Jul 2, 2022
2 parents 6c1d412 + e0f80f7 commit 428ceda
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/parser/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,14 @@ module.exports = {
// support https://wiki.php.net/rfc/typed_properties_v2
(this.version >= 704 &&
(this.token === "?" ||
this.token === this.tok.T_CALLABLE ||
this.token === this.tok.T_ARRAY ||
this.token === this.tok.T_CALLABLE ||
this.token === this.tok.T_NAMESPACE ||
this.token === this.tok.T_NAME_FULLY_QUALIFIED ||
this.token === this.tok.T_NAME_QUALIFIED ||
this.token === this.tok.T_NAME_RELATIVE ||
this.token === this.tok.T_NS_SEPARATOR ||
this.token === this.tok.T_STRING ||
this.token === this.tok.T_NAMESPACE)))
this.token === this.tok.T_STRING)))
) {
// reads a variable
const variables = this.read_variable_list(flags, attrs);
Expand Down
47 changes: 47 additions & 0 deletions test/snapshot/__snapshots__/class.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1809,3 +1809,50 @@ Program {
"kind": "program",
}
`;

exports[`Test classes handles property types with a leading \\ 1`] = `
Program {
"children": Array [
Class {
"attrGroups": Array [],
"body": Array [
PropertyStatement {
"isStatic": false,
"kind": "propertystatement",
"properties": Array [
Property {
"attrGroups": Array [],
"kind": "property",
"name": Identifier {
"kind": "identifier",
"name": "baz",
},
"nullable": false,
"readonly": false,
"type": Name {
"kind": "name",
"name": "\\\\Bar",
"resolution": "fqn",
},
"value": null,
},
],
"visibility": "public",
},
],
"extends": null,
"implements": null,
"isAbstract": false,
"isAnonymous": false,
"isFinal": false,
"kind": "class",
"name": Identifier {
"kind": "identifier",
"name": "Foo",
},
},
],
"errors": Array [],
"kind": "program",
}
`;
10 changes: 10 additions & 0 deletions test/snapshot/class.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,14 @@ class b {
"public static function a()"
);
});

it("handles property types with a leading \\", function () {
expect(
parser.parseEval(`
class Foo {
public \\Bar $baz;
}
`)
).toMatchSnapshot();
});
});

0 comments on commit 428ceda

Please sign in to comment.