Skip to content

Commit 73c9f67

Browse files
committed
3.0.0-prerelease.5
1 parent 778c8c0 commit 73c9f67

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

dist/php-parser.js

+49-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Package: php-parser
44
* Parse PHP code and returns its AST
5-
* Build: 3a77549cb15446749700 - 2018-9-3
5+
* Build: 800b5c0abc57980b33d2 - 2018-9-30
66
* License: BSD-3-Clause
77
* Author: Ioan CHIRIAC
88
*
@@ -3099,6 +3099,23 @@ AST.prototype.prepare = function (kind, docs, parser) {
30993099
result.setKind = function (newKind) {
31003100
kind = newKind;
31013101
};
3102+
/**
3103+
* Release a node without using it on the AST
3104+
*/
3105+
result.destroy = function (target) {
3106+
if (docs) {
3107+
// release current docs stack
3108+
if (target) {
3109+
if (!target.leadingComments) {
3110+
target.leadingComments = docs;
3111+
} else {
3112+
target.leadingComments = docs.concat(target.leadingComments);
3113+
}
3114+
} else {
3115+
parser._docIndex = parser._docs.length - docs.length;
3116+
}
3117+
}
3118+
};
31023119
return result;
31033120
};
31043121

@@ -3455,6 +3472,7 @@ module.exports = {
34553472
result = result("constref", name);
34563473
}
34573474
} else {
3475+
// @fixme possible #193 bug
34583476
result = name;
34593477
}
34603478
} else if (this.token === this.tok.T_STATIC) {
@@ -3496,7 +3514,7 @@ module.exports = {
34963514
return result(what, offset);
34973515
},
34983516

3499-
recursive_variable_chain_scan: function recursive_variable_chain_scan(result, read_only, encapsed) {
3517+
recursive_variable_chain_scan: function recursive_variable_chain_scan(result, read_only, encapsed, dereferencable) {
35003518
var name = void 0,
35013519
node = void 0,
35023520
offset = void 0;
@@ -3551,6 +3569,10 @@ module.exports = {
35513569
this.next();
35523570
}
35533571
result = node(result, offset);
3572+
// static lookup dereferencables are limited to staticlookup over functions
3573+
if (dereferencable && this.token !== "(") {
3574+
this.error("(");
3575+
}
35543576
break;
35553577
case this.tok.T_OBJECT_OPERATOR:
35563578
{
@@ -3673,7 +3695,10 @@ module.exports = {
36733695
offset = this.next().read_expr();
36743696
this.expect("}") && this.next();
36753697
result = node("offsetlookup", result, offset);
3676-
} else break;
3698+
} else {
3699+
node.destroy();
3700+
break;
3701+
}
36773702
}
36783703
return result;
36793704
},
@@ -4604,6 +4629,7 @@ module.exports = {
46044629
} else if (this.token === this.tok.T_CURLY_OPEN) {
46054630
// expression
46064631
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1246
4632+
result.destroy();
46074633
result = this.next().read_variable(false, false, false);
46084634
if (result.kind === "variable") {
46094635
result.curly = true;
@@ -4612,6 +4638,7 @@ module.exports = {
46124638
} else if (this.token === this.tok.T_VARIABLE) {
46134639
// plain variable
46144640
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1231
4641+
result.destroy();
46154642
result = this.read_simple_variable(false);
46164643

46174644
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1233
@@ -4625,8 +4652,8 @@ module.exports = {
46254652
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1236
46264653
if (this.token === this.tok.T_OBJECT_OPERATOR) {
46274654
node = this.node("propertylookup");
4628-
var what = this.node("constref");
46294655
this.next().expect(this.tok.T_STRING);
4656+
var what = this.node("constref");
46304657
name = this.text();
46314658
this.next();
46324659
result = node(result, what(name));
@@ -4638,6 +4665,7 @@ module.exports = {
46384665
var value = this.text();
46394666
this.next();
46404667
// consider it as string
4668+
result.destroy();
46414669
result = result("string", false, value, false, value);
46424670
}
46434671

@@ -5482,6 +5510,9 @@ module.exports = {
54825510
}
54835511
this.expect(":") && this.next();
54845512
return result("retif", expr, trueArg, this.read_expr());
5513+
} else {
5514+
// see #193
5515+
result.destroy(expr);
54855516
}
54865517

54875518
return expr;
@@ -5516,9 +5547,8 @@ module.exports = {
55165547
result = result("number", "-" + this.text(), null);
55175548
this.next();
55185549
return result;
5519-
} else {
5520-
return result("unary", "-", this.read_expr());
55215550
}
5551+
return result("unary", "-", this.read_expr());
55225552
}
55235553

55245554
if (this.token === "(") {
@@ -5804,6 +5834,9 @@ module.exports = {
58045834
if (isConst) this.error("VARIABLE");
58055835
this.next();
58065836
return result("post", "-", expr);
5837+
default:
5838+
// see #193
5839+
result.destroy(expr);
58075840
}
58085841
} else if (this.is("SCALAR")) {
58095842
result = this.node();
@@ -5814,6 +5847,9 @@ module.exports = {
58145847
if (expr.loc) list.loc = expr.loc;
58155848
var _right = this.next().read_expr();
58165849
return result("assign", list, _right, "=");
5850+
} else {
5851+
// see #189 - swap docs on nodes
5852+
result.destroy(expr);
58175853
}
58185854
// classic array
58195855
return this.handleDereferencable(expr);
@@ -5882,8 +5918,8 @@ module.exports = {
58825918
},
58835919
handleDereferencable: function handleDereferencable(expr) {
58845920
while (this.token !== this.EOF) {
5885-
if (this.token === this.tok.T_OBJECT_OPERATOR) {
5886-
expr = this.recursive_variable_chain_scan(expr, false);
5921+
if (this.token === this.tok.T_OBJECT_OPERATOR || this.token === this.tok.T_DOUBLE_COLON) {
5922+
expr = this.recursive_variable_chain_scan(expr, false, false, true);
58875923
} else if (this.token === this.tok.T_CURLY_OPEN || this.token === "[") {
58885924
expr = this.read_dereferencable(expr);
58895925
} else if (this.token === "(") {
@@ -6658,6 +6694,10 @@ parser.prototype.node = function (name) {
66586694
if (this._docIndex < this._docs.length) {
66596695
var docs = this._docs.slice(this._docIndex);
66606696
this._docIndex = this._docs.length;
6697+
if (this.debug) {
6698+
console.log(new Error("Append docs on " + name));
6699+
console.log(docs);
6700+
}
66616701
return this.ast.prepare(name, docs, this);
66626702
}
66636703
}
@@ -6684,7 +6724,7 @@ parser.prototype.expectEndOfStatement = function (node) {
66846724
};
66856725

66866726
/** outputs some debug information on current token **/
6687-
var ignoreStack = ["parser.next"];
6727+
var ignoreStack = ["parser.next", "parser.node", "parser.showlog"];
66886728
parser.prototype.showlog = function () {
66896729
var stack = new Error().stack.split("\n");
66906730
var line = void 0;

dist/php-parser.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)