File tree 3 files changed +11
-5
lines changed
3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -20,13 +20,14 @@ module.exports = {
20
20
var items = [ ] ;
21
21
var result = this . node ( ArrayExpr ) ;
22
22
23
- this . expect ( [ this . tok . T_ARRAY , '[' ] ) ;
24
-
25
- if ( this . token == this . tok . T_ARRAY ) {
23
+ if ( this . token === this . tok . T_ARRAY ) {
26
24
this . next ( ) . expect ( '(' ) ;
25
+ expect = ')' ;
27
26
} else {
28
27
shortForm = true ;
28
+ expect = ']' ;
29
29
}
30
+
30
31
if ( this . next ( ) . token != expect ) {
31
32
while ( this . token != this . EOF ) {
32
33
items . push ( this . read_array_pair_list ( ) ) ;
@@ -38,7 +39,7 @@ module.exports = {
38
39
} else break ;
39
40
}
40
41
}
41
- this . expect ( shortForm ? ']' : ')' ) ;
42
+ this . expect ( expect ) ;
42
43
this . next ( ) ;
43
44
return result ( shortForm , items ) ;
44
45
} ,
Original file line number Diff line number Diff line change @@ -149,7 +149,7 @@ module.exports = {
149
149
var assignList = this . read_assignment_list ( ) ;
150
150
if ( this . expect ( ')' ) ) this . next ( ) ;
151
151
return result ( assignList ) ;
152
- } else if ( this . token === '[' ) {
152
+ } else if ( this . token === '[' || this . token === this . tok . T_ARRAY ) {
153
153
return this . read_array ( ) ;
154
154
} else {
155
155
return this . read_variable ( false , false , false ) ;
Original file line number Diff line number Diff line change @@ -164,6 +164,11 @@ describe('Array without keys', function() {
164
164
} ) ;
165
165
166
166
describe ( 'mixed tests / coverage' , function ( ) {
167
+ it ( 'test empty array' , function ( ) {
168
+ var ast = parser . parseEval ( '$a = []; $b = array();' ) ;
169
+ ast . children [ 0 ] . right . items . length . should . be . exactly ( 0 ) ;
170
+ ast . children [ 1 ] . right . items . length . should . be . exactly ( 0 ) ;
171
+ } ) ;
167
172
it ( 'test short form / keys' , function ( ) {
168
173
var ast = parser . parseEval ( '[0 => &$foo, $bar => "foobar"];' ) ;
169
174
ast . children [ 0 ] . items . length . should . be . exactly ( 2 ) ;
You can’t perform that action at this time.
0 commit comments