Skip to content

Commit 9aec5ed

Browse files
committed
fix dereferencable nodes
1 parent a3a857c commit 9aec5ed

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/parser/expr.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ module.exports = {
8484
if (this.token === this.tok.T_OBJECT_OPERATOR) {
8585
return this.recursive_variable_chain_scan(expr, false);
8686
} else if (this.token === this.tok.T_CURLY_OPEN || this.token === '[') {
87-
// @fixme - should avoid a new token (could be resolved)
88-
return this.node('deference')(
89-
expr, this.read_encapsed_string_item()
90-
);
87+
return this.read_dereferencable(expr);
9188
} else if (this.token === '(') {
9289
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1118
9390
return this.node('call')(
@@ -315,8 +312,7 @@ module.exports = {
315312
if (this.token === this.tok.T_OBJECT_OPERATOR) {
316313
expr = this.recursive_variable_chain_scan(expr, false);
317314
} else if (this.token === this.tok.T_CURLY_OPEN || this.token === '[') {
318-
// @fixme - should avoid a new token (could be resolved)
319-
expr = this.node('deference')(expr, this.read_encapsed_string_item());
315+
expr = this.read_dereferencable(expr);
320316
} else if (this.token === '(') {
321317
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1118
322318
expr = this.node('call')(expr, this.read_function_argument_list());

src/parser/scalar.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ module.exports = {
113113
}
114114
}
115115
}
116+
/**
117+
* Handles the dereferencing
118+
*/
119+
,read_dereferencable: function(expr) {
120+
var result;
121+
if (this.token === '[') {
122+
result = ['offset', expr, this.next().read_expr()];
123+
this.expect(']').next();
124+
} else if (this.token === this.tok.T_DOLLAR_OPEN_CURLY_BRACES) {
125+
result = ['offset', expr, this.read_encapsed_string_item()];
126+
}
127+
return result;
128+
}
116129
/**
117130
* <ebnf>
118131
* encapsed_string_item ::= T_ENCAPSED_AND_WHITESPACE | T_DOLLAR_OPEN_CURLY_BRACES ... | variable | T_CURLY_OPEN variable '}'

0 commit comments

Comments
 (0)