豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 7c04580

Browse files
authored
fix: multiple static lookup (#1215)
* fix: multiple static lookup * change names of test
1 parent 8da733d commit 7c04580

File tree

5 files changed

+74
-116
lines changed

5 files changed

+74
-116
lines changed

src/parser/variable.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,6 @@ module.exports = {
216216
break;
217217
}
218218
case this.tok.T_DOUBLE_COLON:
219-
// @see https://github.com/glayzzle/php-parser/issues/107#issuecomment-354104574
220-
if (
221-
result.kind === "staticlookup" &&
222-
result.offset.kind === "identifier"
223-
) {
224-
this.error();
225-
}
226-
227219
node = this.node("staticlookup");
228220
result = node(result, this.read_what(true));
229221

test/snapshot/__snapshots__/expr.test.js.snap

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,6 @@ Program {
224224
"message": "Parse Error : syntax error, unexpected 'bar' (T_STRING), expecting ';' on line 1",
225225
"token": "'bar' (T_STRING)",
226226
},
227-
Error {
228-
"expected": undefined,
229-
"kind": "error",
230-
"line": 1,
231-
"message": "Parse Error : syntax error, unexpected '::' (T_DOUBLE_COLON) on line 1",
232-
"token": "'::' (T_DOUBLE_COLON)",
233-
},
234227
],
235228
"kind": "program",
236229
}

test/snapshot/__snapshots__/variable.test.js.snap

Lines changed: 69 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,75 @@ Program {
6565
}
6666
`;
6767

68+
exports[`Test variables Check errors chained static lookup foo::bar::baz 1`] = `
69+
Program {
70+
"children": [
71+
ExpressionStatement {
72+
"expression": StaticLookup {
73+
"kind": "staticlookup",
74+
"offset": Identifier {
75+
"kind": "identifier",
76+
"name": "baz",
77+
},
78+
"what": StaticLookup {
79+
"kind": "staticlookup",
80+
"offset": Identifier {
81+
"kind": "identifier",
82+
"name": "bar",
83+
},
84+
"what": Name {
85+
"kind": "name",
86+
"name": "foo",
87+
"resolution": "uqn",
88+
},
89+
},
90+
},
91+
"kind": "expressionstatement",
92+
},
93+
],
94+
"errors": [],
95+
"kind": "program",
96+
}
97+
`;
98+
99+
exports[`Test variables Check errors chained static lookup on property lookup 1`] = `
100+
Program {
101+
"children": [
102+
ExpressionStatement {
103+
"expression": StaticLookup {
104+
"kind": "staticlookup",
105+
"offset": Identifier {
106+
"kind": "identifier",
107+
"name": "baz",
108+
},
109+
"what": StaticLookup {
110+
"kind": "staticlookup",
111+
"offset": Identifier {
112+
"kind": "identifier",
113+
"name": "bar",
114+
},
115+
"what": PropertyLookup {
116+
"kind": "propertylookup",
117+
"offset": Identifier {
118+
"kind": "identifier",
119+
"name": "foo",
120+
},
121+
"what": Name {
122+
"kind": "name",
123+
"name": "this",
124+
"resolution": "uqn",
125+
},
126+
},
127+
},
128+
},
129+
"kind": "expressionstatement",
130+
},
131+
],
132+
"errors": [],
133+
"kind": "program",
134+
}
135+
`;
136+
68137
exports[`Test variables Check errors should be ? 1`] = `
69138
Program {
70139
"children": [
@@ -147,90 +216,6 @@ Program {
147216
}
148217
`;
149218

150-
exports[`Test variables Check errors should fail foo::bar::baz 1`] = `
151-
Program {
152-
"children": [
153-
ExpressionStatement {
154-
"expression": StaticLookup {
155-
"kind": "staticlookup",
156-
"offset": Identifier {
157-
"kind": "identifier",
158-
"name": "baz",
159-
},
160-
"what": StaticLookup {
161-
"kind": "staticlookup",
162-
"offset": Identifier {
163-
"kind": "identifier",
164-
"name": "bar",
165-
},
166-
"what": Name {
167-
"kind": "name",
168-
"name": "foo",
169-
"resolution": "uqn",
170-
},
171-
},
172-
},
173-
"kind": "expressionstatement",
174-
},
175-
],
176-
"errors": [
177-
Error {
178-
"expected": undefined,
179-
"kind": "error",
180-
"line": 1,
181-
"message": "Parse Error : syntax error, unexpected '::' (T_DOUBLE_COLON) on line 1",
182-
"token": "'::' (T_DOUBLE_COLON)",
183-
},
184-
],
185-
"kind": "program",
186-
}
187-
`;
188-
189-
exports[`Test variables Check errors should fail on double static lookup 1`] = `
190-
Program {
191-
"children": [
192-
ExpressionStatement {
193-
"expression": StaticLookup {
194-
"kind": "staticlookup",
195-
"offset": Identifier {
196-
"kind": "identifier",
197-
"name": "baz",
198-
},
199-
"what": StaticLookup {
200-
"kind": "staticlookup",
201-
"offset": Identifier {
202-
"kind": "identifier",
203-
"name": "bar",
204-
},
205-
"what": PropertyLookup {
206-
"kind": "propertylookup",
207-
"offset": Identifier {
208-
"kind": "identifier",
209-
"name": "foo",
210-
},
211-
"what": Name {
212-
"kind": "name",
213-
"name": "this",
214-
"resolution": "uqn",
215-
},
216-
},
217-
},
218-
},
219-
"kind": "expressionstatement",
220-
},
221-
],
222-
"errors": [
223-
Error {
224-
"expected": undefined,
225-
"kind": "error",
226-
"line": 1,
227-
"message": "Parse Error : syntax error, unexpected '::' (T_DOUBLE_COLON) on line 1",
228-
"token": "'::' (T_DOUBLE_COLON)",
229-
},
230-
],
231-
"kind": "program",
232-
}
233-
`;
234219

235220
exports[`Test variables Check errors should fail on property lookup on static lookup 1`] = `
236221
Program {

test/snapshot/expr.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ describe("Test expressions", function () {
299299
expect(
300300
parser.parseEval(`($a++)($foo)->bar{$baz}::foo();`),
301301
).toMatchSnapshot();
302-
// expect error :
302+
// expect error: `bar` is not a valid continuation after `($a++)`
303303
expect(
304304
parser.parseEval(`($a++)bar::foo::baz;`, {
305305
parser: {

test/snapshot/variable.test.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,8 @@ describe("Test variables", function () {
126126
).toMatchSnapshot();
127127
});
128128

129-
it("should fail on double static lookup", function () {
130-
expect(
131-
parser.parseEval(["this->foo::bar::baz;"].join("\n"), {
132-
parser: {
133-
suppressErrors: true,
134-
},
135-
}),
136-
).toMatchSnapshot();
129+
it("chained static lookup on property lookup", function () {
130+
expect(parser.parseEval("this->foo::bar::baz;")).toMatchSnapshot();
137131
});
138132

139133
it("should fail on property lookup on static lookup", function () {
@@ -156,14 +150,8 @@ describe("Test variables", function () {
156150
).toMatchSnapshot();
157151
});
158152

159-
it("should fail foo::bar::baz", function () {
160-
expect(
161-
parser.parseEval("foo::bar::baz", {
162-
parser: {
163-
suppressErrors: true,
164-
},
165-
}),
166-
).toMatchSnapshot();
153+
it("chained static lookup foo::bar::baz", function () {
154+
expect(parser.parseEval("foo::bar::baz")).toMatchSnapshot();
167155
});
168156
});
169157

0 commit comments

Comments
 (0)