Skip to content

Commit f817999

Browse files
committed
glayzzle#251 - implement the encapsedpart usage
1 parent 7ba8978 commit f817999

File tree

7 files changed

+68
-46
lines changed

7 files changed

+68
-46
lines changed

src/parser/variable.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ module.exports = {
138138
what.loc.start = what.value[0].loc.start;
139139
}
140140
} else if (this.token === "{") {
141+
142+
// EncapsedPart
143+
const part = this.node('encapsedpart');
141144
const expr = this.next().read_expr();
142145
this.expect("}") && this.next();
143-
what = this.node("encapsed")([what, expr], null, "offset");
146+
what = this.node("encapsed")([what, part(expr, true)], null, "offset");
144147
if (what.loc && what.value[0].loc) {
145148
what.loc.start = what.value[0].loc.start;
146149
}
@@ -159,18 +162,18 @@ module.exports = {
159162
// $obj->${$varname}
160163
name = this.next().read_expr();
161164
this.expect("}") && this.next();
162-
what = what("literal", "literal", name, null);
165+
what = what("variable", name, true);
163166
} else {
164167
// $obj->$$varname
165168
name = this.read_expr();
166169
what = what("variable", name, false);
167170
}
168171
break;
169172
case "{":
170-
what = this.node("literal");
173+
what = this.node("encapsedpart");
171174
name = this.next().read_expr();
172175
this.expect("}") && this.next();
173-
what = what("literal", name, null);
176+
what = what(name, true);
174177
break;
175178
default:
176179
this.error([this.tok.T_STRING, this.tok.T_VARIABLE, "$", "{"]);

test/debug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
const util = require('util');
1818
const parser = require("../src/index");
1919
const ast = parser.parseEval(`
20-
$a =& foo( &$b );
20+
$var->foo_{$bar};
2121
`, {
2222
parser: {
2323
debug: true,

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,10 @@ Program {
330330
ExpressionStatement {
331331
"expression": StaticLookup {
332332
"kind": "staticlookup",
333-
"offset": Literal {
334-
"kind": "literal",
335-
"value": Variable {
333+
"offset": Variable {
334+
"curly": true,
335+
"kind": "variable",
336+
"name": Variable {
336337
"curly": false,
337338
"kind": "variable",
338339
"name": "property",
@@ -368,29 +369,32 @@ Program {
368369
ExpressionStatement {
369370
"expression": StaticLookup {
370371
"kind": "staticlookup",
371-
"offset": Literal {
372-
"kind": "literal",
373-
"value": Variable {
372+
"offset": Variable {
373+
"curly": true,
374+
"kind": "variable",
375+
"name": Variable {
374376
"curly": false,
375377
"kind": "variable",
376378
"name": "property",
377379
},
378380
},
379381
"what": StaticLookup {
380382
"kind": "staticlookup",
381-
"offset": Literal {
382-
"kind": "literal",
383-
"value": Variable {
383+
"offset": Variable {
384+
"curly": true,
385+
"kind": "variable",
386+
"name": Variable {
384387
"curly": false,
385388
"kind": "variable",
386389
"name": "property",
387390
},
388391
},
389392
"what": StaticLookup {
390393
"kind": "staticlookup",
391-
"offset": Literal {
392-
"kind": "literal",
393-
"value": Variable {
394+
"offset": Variable {
395+
"curly": true,
396+
"kind": "variable",
397+
"name": Variable {
394398
"curly": false,
395399
"kind": "variable",
396400
"name": "property",
@@ -428,9 +432,10 @@ Program {
428432
ExpressionStatement {
429433
"expression": StaticLookup {
430434
"kind": "staticlookup",
431-
"offset": Literal {
432-
"kind": "literal",
433-
"value": String {
435+
"offset": Variable {
436+
"curly": true,
437+
"kind": "variable",
438+
"name": String {
434439
"isDoubleQuote": true,
435440
"kind": "string",
436441
"raw": "\\"property\\"",
@@ -468,9 +473,10 @@ Program {
468473
ExpressionStatement {
469474
"expression": StaticLookup {
470475
"kind": "staticlookup",
471-
"offset": Literal {
472-
"kind": "literal",
473-
"value": Variable {
476+
"offset": Variable {
477+
"curly": true,
478+
"kind": "variable",
479+
"name": Variable {
474480
"curly": false,
475481
"kind": "variable",
476482
"name": "property",

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,9 @@ Program {
754754
"curly": true,
755755
"expression": PropertyLookup {
756756
"kind": "propertylookup",
757-
"offset": Literal {
758-
"kind": "literal",
759-
"value": OffsetLookup {
757+
"offset": EncapsedPart {
758+
"curly": true,
759+
"expression": OffsetLookup {
760760
"kind": "offsetlookup",
761761
"offset": Number {
762762
"kind": "number",
@@ -768,6 +768,7 @@ Program {
768768
"name": "array",
769769
},
770770
},
771+
"kind": "encapsedpart",
771772
},
772773
"what": Variable {
773774
"curly": false,

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,14 @@ Program {
124124
"kind": "identifier",
125125
"name": "bar",
126126
},
127-
Variable {
128-
"curly": false,
129-
"kind": "variable",
130-
"name": "baz",
127+
EncapsedPart {
128+
"curly": true,
129+
"expression": Variable {
130+
"curly": false,
131+
"kind": "variable",
132+
"name": "baz",
133+
},
134+
"kind": "encapsedpart",
131135
},
132136
],
133137
},

test/snapshot/__snapshots__/propertylookup.test.js.snap

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ Program {
3434
ExpressionStatement {
3535
"expression": PropertyLookup {
3636
"kind": "propertylookup",
37-
"offset": Literal {
38-
"kind": "literal",
39-
"value": Identifier {
37+
"offset": EncapsedPart {
38+
"curly": true,
39+
"expression": Identifier {
4040
"kind": "identifier",
4141
"name": ClassReference {
4242
"kind": "classreference",
4343
"name": "foo",
4444
"resolution": "uqn",
4545
},
4646
},
47+
"kind": "encapsedpart",
4748
},
4849
"what": Variable {
4950
"curly": false,

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,9 +1208,10 @@ Program {
12081208
ExpressionStatement {
12091209
"expression": PropertyLookup {
12101210
"kind": "propertylookup",
1211-
"offset": Literal {
1212-
"kind": "literal",
1213-
"value": Variable {
1211+
"offset": Variable {
1212+
"curly": true,
1213+
"kind": "variable",
1214+
"name": Variable {
12141215
"curly": false,
12151216
"kind": "variable",
12161217
"name": "property",
@@ -1236,9 +1237,9 @@ Program {
12361237
ExpressionStatement {
12371238
"expression": PropertyLookup {
12381239
"kind": "propertylookup",
1239-
"offset": Literal {
1240-
"kind": "literal",
1241-
"value": PropertyLookup {
1240+
"offset": EncapsedPart {
1241+
"curly": true,
1242+
"expression": PropertyLookup {
12421243
"kind": "propertylookup",
12431244
"offset": Identifier {
12441245
"kind": "identifier",
@@ -1250,6 +1251,7 @@ Program {
12501251
"name": "property",
12511252
},
12521253
},
1254+
"kind": "encapsedpart",
12531255
},
12541256
"what": Variable {
12551257
"curly": false,
@@ -1262,9 +1264,10 @@ Program {
12621264
ExpressionStatement {
12631265
"expression": PropertyLookup {
12641266
"kind": "propertylookup",
1265-
"offset": Literal {
1266-
"kind": "literal",
1267-
"value": Variable {
1267+
"offset": Variable {
1268+
"curly": true,
1269+
"kind": "variable",
1270+
"name": Variable {
12681271
"curly": false,
12691272
"kind": "variable",
12701273
"name": "property",
@@ -1289,10 +1292,14 @@ Program {
12891292
"kind": "identifier",
12901293
"name": "foo_",
12911294
},
1292-
Variable {
1293-
"curly": false,
1294-
"kind": "variable",
1295-
"name": "property",
1295+
EncapsedPart {
1296+
"curly": true,
1297+
"expression": Variable {
1298+
"curly": false,
1299+
"kind": "variable",
1300+
"name": "property",
1301+
},
1302+
"kind": "encapsedpart",
12961303
},
12971304
],
12981305
},

0 commit comments

Comments
 (0)