Skip to content

Commit 26c187b

Browse files
committed
revert back deferencable + add tests
1 parent b094350 commit 26c187b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/parser/expr.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,19 @@ module.exports = {
405405
}
406406
} else if (this.is('SCALAR')) {
407407
expr = this.read_scalar();
408+
// handle dereferencable
409+
while(this.token !== this.EOF) {
410+
if (this.token === this.tok.T_OBJECT_OPERATOR) {
411+
expr = this.recursive_variable_chain_scan(expr, false);
412+
} else if (this.token === this.tok.T_CURLY_OPEN || this.token === '[') {
413+
expr = this.read_dereferencable(expr);
414+
} else if (this.token === '(') {
415+
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1118
416+
expr = this.node('call')(expr, this.read_function_argument_list());
417+
} else {
418+
return expr;
419+
}
420+
}
408421
} else {
409422
this.error('EXPR');
410423
this.next();

test/arrayTests.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ var parser = require('../src/index');
33

44
describe('Array without keys', function() {
55

6+
it('deference array', function () {
7+
var ast = parser.parseEval([
8+
'$a = [',
9+
'"a", "b"',
10+
']($foo)[$foo->bar()[1]]->foo()'
11+
].join('\r'), {
12+
parser: {
13+
debug: true
14+
}
15+
});
16+
console.log(ast);
17+
});
18+
619
describe('of strings', function () {
720
// Get result from parser
821
var ast = parser.parseEval('array("item1", "item2", "item3")');

0 commit comments

Comments
 (0)