Skip to content

Commit c2e2bc4

Browse files
fix: ast for offsetlookup in encapsed
1 parent 74ee26f commit c2e2bc4

File tree

3 files changed

+56
-53
lines changed

3 files changed

+56
-53
lines changed

src/parser/scalar.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ module.exports = {
221221
text
222222
);
223223
} else if (this.token === this.tok.T_DOLLAR_OPEN_CURLY_BRACES) {
224-
syntax = 'simple';
224+
syntax = "simple";
225225
curly = true;
226226
// dynamic variable name
227227
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1239
@@ -237,24 +237,23 @@ module.exports = {
237237
node = this.node("offsetlookup");
238238
offset = this.next().read_expr();
239239
this.expect("]") && this.next();
240-
name = node(name, offset);
240+
result = node(name, offset);
241241
} else {
242-
name = varName;
242+
result = name(varName, false);
243243
}
244244
} else {
245-
name = this.read_expr();
245+
result = result("variable", this.read_expr(), false);
246246
}
247247
this.expect("}") && this.next();
248-
result = result("variable", name);
249248
} else if (this.token === this.tok.T_CURLY_OPEN) {
250249
// expression
251250
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1246
252-
syntax = 'complex';
251+
syntax = "complex";
253252
result.destroy();
254253
result = this.next().read_variable(false, false);
255254
this.expect("}") && this.next();
256255
} else if (this.token === this.tok.T_VARIABLE) {
257-
syntax = 'simple';
256+
syntax = "simple";
258257
// plain variable
259258
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1231
260259
result.destroy();

test/snapshot/__snapshots__/encapsed.test.js.snap

+27-15
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ Program {
193193
"expression": Variable {
194194
"curly": false,
195195
"kind": "variable",
196-
"name": "juice",
196+
"name": Variable {
197+
"curly": false,
198+
"kind": "variable",
199+
"name": "juice",
200+
},
197201
},
198202
"kind": "encapsedpart",
199203
"syntax": "simple",
@@ -244,12 +248,16 @@ Program {
244248
EncapsedPart {
245249
"curly": true,
246250
"expression": Variable {
247-
"curly": true,
251+
"curly": false,
248252
"kind": "variable",
249253
"name": Variable {
250-
"curly": false,
254+
"curly": true,
251255
"kind": "variable",
252-
"name": "juice",
256+
"name": Variable {
257+
"curly": false,
258+
"kind": "variable",
259+
"name": "juice",
260+
},
253261
},
254262
},
255263
"kind": "encapsedpart",
@@ -300,13 +308,17 @@ Program {
300308
},
301309
EncapsedPart {
302310
"curly": true,
303-
"expression": Call {
304-
"arguments": Array [],
305-
"kind": "call",
306-
"what": ClassReference {
307-
"kind": "classreference",
308-
"name": "call",
309-
"resolution": "uqn",
311+
"expression": Variable {
312+
"curly": false,
313+
"kind": "variable",
314+
"name": Call {
315+
"arguments": Array [],
316+
"kind": "call",
317+
"what": ClassReference {
318+
"kind": "classreference",
319+
"name": "call",
320+
"resolution": "uqn",
321+
},
310322
},
311323
},
312324
"kind": "encapsedpart",
@@ -604,9 +616,9 @@ Program {
604616
EncapsedPart {
605617
"curly": true,
606618
"expression": Variable {
607-
"curly": "juice",
619+
"curly": false,
608620
"kind": "variable",
609-
"name": "variable",
621+
"name": "juice",
610622
},
611623
"kind": "encapsedpart",
612624
"syntax": "simple",
@@ -2854,9 +2866,9 @@ Program {
28542866
EncapsedPart {
28552867
"curly": true,
28562868
"expression": Variable {
2857-
"curly": "var",
2869+
"curly": false,
28582870
"kind": "variable",
2859-
"name": "variable",
2871+
"name": "var",
28602872
},
28612873
"kind": "encapsedpart",
28622874
"syntax": "simple",

test/snapshot/__snapshots__/string.test.js.snap

+23-31
Original file line numberDiff line numberDiff line change
@@ -1662,23 +1662,19 @@ Program {
16621662
},
16631663
EncapsedPart {
16641664
"curly": true,
1665-
"expression": Variable {
1666-
"curly": false,
1667-
"kind": "variable",
1668-
"name": OffsetLookup {
1669-
"kind": "offsetlookup",
1670-
"offset": String {
1671-
"isDoubleQuote": false,
1672-
"kind": "string",
1673-
"raw": "'FOO'",
1674-
"unicode": false,
1675-
"value": "FOO",
1676-
},
1677-
"what": Variable {
1678-
"curly": false,
1679-
"kind": "variable",
1680-
"name": "juices",
1681-
},
1665+
"expression": OffsetLookup {
1666+
"kind": "offsetlookup",
1667+
"offset": String {
1668+
"isDoubleQuote": false,
1669+
"kind": "string",
1670+
"raw": "'FOO'",
1671+
"unicode": false,
1672+
"value": "FOO",
1673+
},
1674+
"what": Variable {
1675+
"curly": false,
1676+
"kind": "variable",
1677+
"name": "juices",
16821678
},
16831679
},
16841680
"kind": "encapsedpart",
@@ -2866,20 +2862,16 @@ EOFX",
28662862
},
28672863
EncapsedPart {
28682864
"curly": true,
2869-
"expression": Variable {
2870-
"curly": false,
2871-
"kind": "variable",
2872-
"name": OffsetLookup {
2873-
"kind": "offsetlookup",
2874-
"offset": Number {
2875-
"kind": "number",
2876-
"value": "1",
2877-
},
2878-
"what": Variable {
2879-
"curly": false,
2880-
"kind": "variable",
2881-
"name": "targetDirs",
2882-
},
2865+
"expression": OffsetLookup {
2866+
"kind": "offsetlookup",
2867+
"offset": Number {
2868+
"kind": "number",
2869+
"value": "1",
2870+
},
2871+
"what": Variable {
2872+
"curly": false,
2873+
"kind": "variable",
2874+
"name": "targetDirs",
28832875
},
28842876
},
28852877
"kind": "encapsedpart",

0 commit comments

Comments
 (0)