Skip to content

Commit ae9b5b8

Browse files
authored
Merge pull request glayzzle#388 from glayzzle/refactor-by-ref
refactor: byRef
2 parents 62973ef + 23d2743 commit ae9b5b8

11 files changed

+262
-107
lines changed

src/ast.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const Position = require("./ast/position");
4646
* - [Exit](#exit)
4747
* - [Clone](#clone)
4848
* - [Assign](#assign)
49+
* - [AssignRef](#assignref)
4950
* - [Array](#array)
5051
* - [List](#list)
5152
* - [Variable](#variable)
@@ -458,6 +459,7 @@ AST.prototype.checkNodes = function() {
458459
[
459460
require("./ast/array"),
460461
require("./ast/assign"),
462+
require("./ast/assignref"),
461463
require("./ast/bin"),
462464
require("./ast/block"),
463465
require("./ast/boolean"),

src/ast/assign.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = Expression.extends(KIND, function Assign(
2424
location
2525
) {
2626
Expression.apply(this, [KIND, docs, location]);
27-
this.operator = operator;
2827
this.left = left;
2928
this.right = right;
29+
this.operator = operator;
3030
});

src/ast/assignref.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (C) 2018 Glayzzle (BSD3 License)
3+
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
4+
* @url http://glayzzle.com
5+
*/
6+
"use strict";
7+
8+
const Expression = require("./expression");
9+
const KIND = "assignref";
10+
11+
/**
12+
* Assigns a value to the specified target
13+
* @constructor Assign
14+
* @extends {Expression}
15+
* @property {Expression} left
16+
* @property {Expression} right
17+
* @property {String} operator
18+
*/
19+
module.exports = Expression.extends(KIND, function AssignRef(
20+
left,
21+
right,
22+
docs,
23+
location
24+
) {
25+
Expression.apply(this, [KIND, docs, location]);
26+
this.left = left;
27+
this.right = right;
28+
});

src/parser/expr.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,19 @@ module.exports = {
354354
if (isConst) this.error("VARIABLE");
355355
let right;
356356
if (this.next().token == "&") {
357-
right = this.read_byref(
358-
function() {
359-
if (this.token === this.tok.T_NEW) {
360-
if (this.php7) {
361-
this.error();
362-
}
363-
return this.read_new_expr();
364-
} else {
365-
return this.read_variable(false, false);
366-
}
367-
}.bind(this)
368-
);
369-
} else {
370-
right = this.read_expr();
357+
this.next();
358+
if (this.token === this.tok.T_NEW) {
359+
if (this.php7) {
360+
this.error();
361+
}
362+
right = this.read_new_expr();
363+
} else {
364+
right = this.read_variable(false, false);
365+
}
366+
367+
return result("assignref", expr, right);
371368
}
369+
right = this.read_expr();
372370
return result("assign", expr, right, "=");
373371
}
374372

test/snapshot/__snapshots__/assign.test.js.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,16 +402,14 @@ exports[`assign with ref 1`] = `
402402
Program {
403403
"children": Array [
404404
ExpressionStatement {
405-
"expression": Assign {
406-
"kind": "assign",
405+
"expression": AssignRef {
406+
"kind": "assignref",
407407
"left": Variable {
408408
"curly": false,
409409
"kind": "variable",
410410
"name": "bar",
411411
},
412-
"operator": "=",
413412
"right": Variable {
414-
"byref": true,
415413
"curly": false,
416414
"kind": "variable",
417415
"name": "foo",

0 commit comments

Comments
 (0)