Skip to content

Commit 7ba8978

Browse files
committed
glayzzle#205 - fix assign usage - new & function calls
1 parent fc128e4 commit 7ba8978

File tree

9 files changed

+56
-43
lines changed

9 files changed

+56
-43
lines changed

src/parser/expr.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ module.exports = {
199199
case this.tok.T_INC:
200200
return this.node("pre")(
201201
"+",
202-
this.next().read_variable(false, false, false)
202+
this.next().read_variable(false, false)
203203
);
204204

205205
case this.tok.T_DEC:
206206
return this.node("pre")(
207207
"-",
208-
this.next().read_variable(false, false, false)
208+
this.next().read_variable(false, false)
209209
);
210210

211211
case this.tok.T_NEW:
@@ -341,7 +341,7 @@ module.exports = {
341341
// SCALAR | VARIABLE
342342
if (this.is("VARIABLE")) {
343343
result = this.node();
344-
expr = this.read_variable(false, false, false);
344+
expr = this.read_variable(false, false);
345345

346346
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L877
347347
// should accept only a variable
@@ -355,13 +355,14 @@ module.exports = {
355355
if (isConst) this.error("VARIABLE");
356356
let right;
357357
if (this.next().token == "&") {
358+
right = this.node('byref');
358359
if (this.next().token === this.tok.T_NEW) {
359360
if (this.php7) {
360361
this.error();
361362
}
362-
right = this.read_new_expr();
363+
right = right(this.read_new_expr());
363364
} else {
364-
right = this.read_variable(false, false, true);
365+
right = right(this.read_variable(false, false));
365366
}
366367
} else {
367368
right = this.read_expr();
@@ -511,7 +512,7 @@ module.exports = {
511512
}
512513
return result;
513514
} else if (this.is("VARIABLE")) {
514-
return this.read_variable(true, false, false);
515+
return this.read_variable(true, false);
515516
} else {
516517
this.expect([this.tok.T_STRING, "VARIABLE"]);
517518
}

src/parser/loops.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ module.exports = {
162162
if (this.expect(isShort ? "]" : ")")) this.next();
163163
return result(assignList, isShort);
164164
} else {
165-
return this.read_variable(false, false, false);
165+
return this.read_variable(false, false);
166166
}
167167
}
168168
};

src/parser/namespace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ module.exports = {
123123
*/
124124
read_class_name_reference: function() {
125125
// resolved as the same
126-
return this.read_variable(true, false, false);
126+
return this.read_variable(true, false);
127127
},
128128
/**
129129
* Reads a use declaration

src/parser/scalar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ module.exports = {
224224
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1246
225225
curly = true;
226226
result.destroy();
227-
result = this.next().read_variable(false, false, false);
227+
result = this.next().read_variable(false, false);
228228
this.expect("}") && this.next();
229229
} else if (this.token === this.tok.T_VARIABLE) {
230230
// plain variable

src/parser/try.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828
const item = this.node("catch");
2929
this.next().expect("(") && this.next();
3030
const what = this.read_list(this.read_namespace_name, "|", false);
31-
const variable = this.read_variable(true, false, false);
31+
const variable = this.read_variable(true, false);
3232
this.expect(")");
3333
catches.push(item(this.next().read_statement(), what, variable));
3434
}

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-
&$foo = 1;
20+
$a =& foo( &$b );
2121
`, {
2222
parser: {
2323
debug: true,

test/snapshot/__snapshots__/byref.test.js.snap

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,25 @@ Program {
1212
"name": "a",
1313
},
1414
"operator": "=",
15-
"right": Call {
16-
"arguments": Array [
17-
ByRef {
18-
"kind": "byref",
19-
"what": Variable {
20-
"curly": false,
21-
"kind": "variable",
22-
"name": "b",
15+
"right": ByRef {
16+
"kind": "byref",
17+
"what": Call {
18+
"arguments": Array [
19+
ByRef {
20+
"kind": "byref",
21+
"what": Variable {
22+
"curly": false,
23+
"kind": "variable",
24+
"name": "b",
25+
},
2326
},
27+
],
28+
"kind": "call",
29+
"what": ClassReference {
30+
"kind": "classreference",
31+
"name": "foo",
32+
"resolution": "uqn",
2433
},
25-
],
26-
"kind": "call",
27-
"what": ClassReference {
28-
"kind": "classreference",
29-
"name": "foo",
30-
"resolution": "uqn",
3134
},
3235
},
3336
},
@@ -88,13 +91,16 @@ Program {
8891
"name": "a",
8992
},
9093
"operator": "=",
91-
"right": New {
92-
"arguments": Array [],
93-
"kind": "new",
94-
"what": ClassReference {
95-
"kind": "classreference",
96-
"name": "foo",
97-
"resolution": "uqn",
94+
"right": ByRef {
95+
"kind": "byref",
96+
"what": New {
97+
"arguments": Array [],
98+
"kind": "new",
99+
"what": ClassReference {
100+
"kind": "classreference",
101+
"name": "foo",
102+
"resolution": "uqn",
103+
},
98104
},
99105
},
100106
},

test/snapshot/__snapshots__/new.test.js.snap

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ Program {
1212
"name": "a",
1313
},
1414
"operator": "=",
15-
"right": New {
16-
"arguments": Array [],
17-
"kind": "new",
18-
"what": ClassReference {
19-
"kind": "classreference",
20-
"name": "Foo",
21-
"resolution": "uqn",
15+
"right": ByRef {
16+
"kind": "byref",
17+
"what": New {
18+
"arguments": Array [],
19+
"kind": "new",
20+
"what": ClassReference {
21+
"kind": "classreference",
22+
"name": "Foo",
23+
"resolution": "uqn",
24+
},
2225
},
2326
},
2427
},

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,10 +799,13 @@ Program {
799799
"name": "b",
800800
},
801801
"operator": "=",
802-
"right": Variable {
803-
"curly": false,
804-
"kind": "variable",
805-
"name": "c",
802+
"right": ByRef {
803+
"kind": "byref",
804+
"what": Variable {
805+
"curly": false,
806+
"kind": "variable",
807+
"name": "c",
808+
},
806809
},
807810
},
808811
"kind": "expressionstatement",

0 commit comments

Comments
 (0)