Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit ea69b15

Browse files
authored
Merge pull request glayzzle#221 from glayzzle/fix-reference-node
fix: reference node
2 parents 97a7525 + 67d928f commit ea69b15

23 files changed

+1459
-10
lines changed

src/ast/parentreference.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ const KIND = "parentreference";
1414
* @extends {Reference}
1515
*/
1616
const ParentReference = Reference.extends(KIND, function ParentReference(
17+
raw,
1718
docs,
1819
location
1920
) {
2021
Reference.apply(this, [KIND, docs, location]);
22+
this.raw = raw;
2123
});
2224
module.exports = ParentReference;

src/ast/selfreference.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ const KIND = "selfreference";
1414
* @extends {Reference}
1515
*/
1616
const SelfReference = Reference.extends(KIND, function SelfReference(
17+
raw,
1718
docs,
1819
location
1920
) {
2021
Reference.apply(this, [KIND, docs, location]);
22+
this.raw = raw;
2123
});
2224
module.exports = SelfReference;

src/ast/staticreference.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ const KIND = "staticreference";
1414
* @extends {Reference}
1515
*/
1616
const StaticReference = Reference.extends(KIND, function StaticReference(
17+
raw,
1718
docs,
1819
location
1920
) {
2021
Reference.apply(this, [KIND, docs, location]);
22+
this.raw = raw;
2123
});
2224
module.exports = StaticReference;

src/ast/typereference.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@ const KIND = "typereference";
1616
*/
1717
const TypeReference = Reference.extends(KIND, function TypeReference(
1818
name,
19+
raw,
1920
docs,
2021
location
2122
) {
2223
Reference.apply(this, [KIND, docs, location]);
2324
this.name = name;
25+
this.raw = raw;
2426
});
2527

26-
TypeReference.types = ["int", "float", "string", "bool", "object", "array"];
28+
TypeReference.types = [
29+
"int",
30+
"float",
31+
"string",
32+
"bool",
33+
"object",
34+
"array",
35+
"callable",
36+
"iterable"
37+
];
2738

2839
module.exports = TypeReference;

src/parser/function.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,11 @@ module.exports = {
240240
* ```
241241
*/
242242
read_type: function() {
243-
const result = this.node("typereference");
244-
let type = null;
243+
const result = this.node();
245244
if (this.token === this.tok.T_ARRAY || this.token === this.tok.T_CALLABLE) {
246245
let type = this.text();
247246
this.next();
248-
return result(type);
247+
return result("typereference", type.toLowerCase(), type);
249248
} else if (this.token === this.tok.T_STRING) {
250249
let type = this.text();
251250
const backup = [this.token, this.lexer.getState()];
@@ -254,7 +253,7 @@ module.exports = {
254253
this.token !== this.tok.T_NS_SEPARATOR &&
255254
this.ast.typereference.types.indexOf(type.toLowerCase()) > -1
256255
) {
257-
return result(type);
256+
return result("typereference", type.toLowerCase(), type);
258257
} else {
259258
// rollback a classic namespace
260259
this.lexer.tokens.push(backup);

src/parser/namespace.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ module.exports = {
7474
true
7575
);
7676
if (!relative && names.length === 1) {
77-
if (names[0] === "parent") {
78-
return result("parentreference");
79-
} else if (names[0] === "self") {
80-
return result("selfreference");
77+
if (names[0].toLowerCase() === "parent") {
78+
return result("parentreference", names[0]);
79+
} else if (names[0].toLowerCase() === "self") {
80+
return result("selfreference", names[0]);
8181
}
8282
}
8383
return result("classreference", names, relative);

src/parser/variable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ module.exports = {
6464
}
6565
} else if (this.token === this.tok.T_STATIC) {
6666
result = this.node("staticreference");
67+
const raw = this.text();
6768
this.next();
68-
result = result();
69+
result = result(raw);
6970
} else {
7071
this.expect("VARIABLE");
7172
}

test/snapshot/__snapshots__/acid.test.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,7 @@ Program {
14481448
},
14491449
},
14501450
"name": "bool",
1451+
"raw": "bool",
14511452
},
14521453
"visibility": "public",
14531454
},
@@ -1506,6 +1507,7 @@ Program {
15061507
},
15071508
},
15081509
"name": "bool",
1510+
"raw": "bool",
15091511
},
15101512
"visibility": "protected",
15111513
},
@@ -1564,6 +1566,7 @@ Program {
15641566
},
15651567
},
15661568
"name": "bool",
1569+
"raw": "bool",
15671570
},
15681571
"visibility": "protected",
15691572
},
@@ -1860,6 +1863,7 @@ Program {
18601863
},
18611864
},
18621865
"name": "bool",
1866+
"raw": "bool",
18631867
},
18641868
"value": Boolean {
18651869
"kind": "boolean",
@@ -2504,6 +2508,7 @@ Program {
25042508
},
25052509
},
25062510
"name": "string",
2511+
"raw": "string",
25072512
},
25082513
"visibility": "public",
25092514
},
@@ -3637,6 +3642,7 @@ next:
36373642
},
36383643
},
36393644
"name": "int",
3645+
"raw": "int",
36403646
},
36413647
},
36423648
ExpressionStatement {
@@ -3747,6 +3753,7 @@ next:
37473753
},
37483754
},
37493755
"name": "int",
3756+
"raw": "int",
37503757
},
37513758
"value": Number {
37523759
"kind": "number",
@@ -6316,6 +6323,7 @@ next:
63166323
},
63176324
},
63186325
"name": "bool",
6326+
"raw": "bool",
63196327
},
63206328
"uses": Array [
63216329
Variable {

test/snapshot/__snapshots__/call.test.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ Program {
711711
},
712712
"what": ParentReference {
713713
"kind": "parentreference",
714+
"raw": "parent",
714715
},
715716
},
716717
},
@@ -830,6 +831,7 @@ Program {
830831
},
831832
"what": SelfReference {
832833
"kind": "selfreference",
834+
"raw": "self",
833835
},
834836
},
835837
},
@@ -928,6 +930,7 @@ Program {
928930
},
929931
"what": StaticReference {
930932
"kind": "staticreference",
933+
"raw": "static",
931934
},
932935
},
933936
},

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ Program {
284284
},
285285
"what": ParentReference {
286286
"kind": "parentreference",
287+
"raw": "parent",
287288
},
288289
},
289290
},
@@ -298,6 +299,7 @@ Program {
298299
},
299300
"what": SelfReference {
300301
"kind": "selfreference",
302+
"raw": "self",
301303
},
302304
},
303305
},
@@ -313,6 +315,7 @@ Program {
313315
},
314316
"what": StaticReference {
315317
"kind": "staticreference",
318+
"raw": "static",
316319
},
317320
},
318321
},
@@ -462,6 +465,7 @@ Program {
462465
},
463466
"what": SelfReference {
464467
"kind": "selfreference",
468+
"raw": "self",
465469
},
466470
},
467471
"operator": "=",
@@ -650,6 +654,7 @@ Program {
650654
"type": TypeReference {
651655
"kind": "typereference",
652656
"name": "array",
657+
"raw": "array",
653658
},
654659
"value": Identifier {
655660
"kind": "identifier",
@@ -737,6 +742,7 @@ Program {
737742
},
738743
"what": SelfReference {
739744
"kind": "selfreference",
745+
"raw": "self",
740746
},
741747
},
742748
"variadic": false,
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`classreference argument type (2) 1`] = `
4+
Program {
5+
"children": Array [
6+
_Function {
7+
"arguments": Array [
8+
Parameter {
9+
"byref": false,
10+
"kind": "parameter",
11+
"name": "arg",
12+
"nullable": false,
13+
"type": ClassReference {
14+
"kind": "classreference",
15+
"name": "Foo\\\\Foo",
16+
"resolution": "qn",
17+
},
18+
"value": null,
19+
"variadic": false,
20+
},
21+
],
22+
"body": Block {
23+
"children": Array [],
24+
"kind": "block",
25+
},
26+
"byref": false,
27+
"kind": "function",
28+
"name": Identifier {
29+
"kind": "identifier",
30+
"name": "fn",
31+
},
32+
"nullable": false,
33+
"type": null,
34+
},
35+
],
36+
"errors": Array [],
37+
"kind": "program",
38+
}
39+
`;
40+
41+
exports[`classreference argument type 1`] = `
42+
Program {
43+
"children": Array [
44+
_Function {
45+
"arguments": Array [
46+
Parameter {
47+
"byref": false,
48+
"kind": "parameter",
49+
"name": "arg",
50+
"nullable": false,
51+
"type": ClassReference {
52+
"kind": "classreference",
53+
"name": "Foo",
54+
"resolution": "uqn",
55+
},
56+
"value": null,
57+
"variadic": false,
58+
},
59+
],
60+
"body": Block {
61+
"children": Array [],
62+
"kind": "block",
63+
},
64+
"byref": false,
65+
"kind": "function",
66+
"name": Identifier {
67+
"kind": "identifier",
68+
"name": "fn",
69+
},
70+
"nullable": false,
71+
"type": null,
72+
},
73+
],
74+
"errors": Array [],
75+
"kind": "program",
76+
}
77+
`;
78+
79+
exports[`classreference call 1`] = `
80+
Program {
81+
"children": Array [
82+
Call {
83+
"arguments": Array [],
84+
"kind": "call",
85+
"what": StaticLookup {
86+
"kind": "staticlookup",
87+
"offset": Identifier {
88+
"kind": "identifier",
89+
"name": "call",
90+
},
91+
"what": ClassReference {
92+
"kind": "classreference",
93+
"name": "Foo",
94+
"resolution": "uqn",
95+
},
96+
},
97+
},
98+
],
99+
"errors": Array [],
100+
"kind": "program",
101+
}
102+
`;
103+
104+
exports[`classreference constant 1`] = `
105+
Program {
106+
"children": Array [
107+
StaticLookup {
108+
"kind": "staticlookup",
109+
"offset": Identifier {
110+
"kind": "identifier",
111+
"name": "CONSTANT",
112+
},
113+
"what": ClassReference {
114+
"kind": "classreference",
115+
"name": "Foo",
116+
"resolution": "uqn",
117+
},
118+
},
119+
],
120+
"errors": Array [],
121+
"kind": "program",
122+
}
123+
`;
124+
125+
exports[`classreference variable 1`] = `
126+
Program {
127+
"children": Array [
128+
StaticLookup {
129+
"kind": "staticlookup",
130+
"offset": Variable {
131+
"byref": false,
132+
"curly": false,
133+
"kind": "variable",
134+
"name": "var",
135+
},
136+
"what": ClassReference {
137+
"kind": "classreference",
138+
"name": "Foo",
139+
"resolution": "uqn",
140+
},
141+
},
142+
],
143+
"errors": Array [],
144+
"kind": "program",
145+
}
146+
`;

0 commit comments

Comments
 (0)