Skip to content

Commit 428ceda

Browse files
authored
Merge pull request glayzzle#960 from glayzzle/fix-fqn-property-types
Handle property types using T_NAME_* tokens.
2 parents 6c1d412 + e0f80f7 commit 428ceda

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

src/parser/class.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,14 @@ module.exports = {
126126
// support https://wiki.php.net/rfc/typed_properties_v2
127127
(this.version >= 704 &&
128128
(this.token === "?" ||
129-
this.token === this.tok.T_CALLABLE ||
130129
this.token === this.tok.T_ARRAY ||
130+
this.token === this.tok.T_CALLABLE ||
131+
this.token === this.tok.T_NAMESPACE ||
132+
this.token === this.tok.T_NAME_FULLY_QUALIFIED ||
133+
this.token === this.tok.T_NAME_QUALIFIED ||
134+
this.token === this.tok.T_NAME_RELATIVE ||
131135
this.token === this.tok.T_NS_SEPARATOR ||
132-
this.token === this.tok.T_STRING ||
133-
this.token === this.tok.T_NAMESPACE)))
136+
this.token === this.tok.T_STRING)))
134137
) {
135138
// reads a variable
136139
const variables = this.read_variable_list(flags, attrs);

test/snapshot/__snapshots__/class.test.js.snap

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,3 +1809,50 @@ Program {
18091809
"kind": "program",
18101810
}
18111811
`;
1812+
1813+
exports[`Test classes handles property types with a leading \\ 1`] = `
1814+
Program {
1815+
"children": Array [
1816+
Class {
1817+
"attrGroups": Array [],
1818+
"body": Array [
1819+
PropertyStatement {
1820+
"isStatic": false,
1821+
"kind": "propertystatement",
1822+
"properties": Array [
1823+
Property {
1824+
"attrGroups": Array [],
1825+
"kind": "property",
1826+
"name": Identifier {
1827+
"kind": "identifier",
1828+
"name": "baz",
1829+
},
1830+
"nullable": false,
1831+
"readonly": false,
1832+
"type": Name {
1833+
"kind": "name",
1834+
"name": "\\\\Bar",
1835+
"resolution": "fqn",
1836+
},
1837+
"value": null,
1838+
},
1839+
],
1840+
"visibility": "public",
1841+
},
1842+
],
1843+
"extends": null,
1844+
"implements": null,
1845+
"isAbstract": false,
1846+
"isAnonymous": false,
1847+
"isFinal": false,
1848+
"kind": "class",
1849+
"name": Identifier {
1850+
"kind": "identifier",
1851+
"name": "Foo",
1852+
},
1853+
},
1854+
],
1855+
"errors": Array [],
1856+
"kind": "program",
1857+
}
1858+
`;

test/snapshot/class.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,14 @@ class b {
255255
"public static function a()"
256256
);
257257
});
258+
259+
it("handles property types with a leading \\", function () {
260+
expect(
261+
parser.parseEval(`
262+
class Foo {
263+
public \\Bar $baz;
264+
}
265+
`)
266+
).toMatchSnapshot();
267+
});
258268
});

0 commit comments

Comments
 (0)