File tree 2 files changed +20
-1
lines changed
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -182,10 +182,14 @@ module.exports = {
182
182
* @return {Constant } [:link:](AST.md#constant)
183
183
*/
184
184
function read_constant_declaration ( ) {
185
- var result = this . node ( 'classconstant' ) , name = null , value = null ;
185
+ var result = this . node ( 'classconstant' ) ,
186
+ name = null ,
187
+ value = null ;
186
188
if ( this . token === this . tok . T_STRING || this . is ( 'IDENTIFIER' ) ) {
187
189
name = this . text ( ) ;
188
190
this . next ( ) ;
191
+ } else {
192
+ this . expect ( 'IDENTIFIER' ) ;
189
193
}
190
194
if ( this . expect ( '=' ) ) {
191
195
value = this . next ( ) . read_expr ( ) ;
Original file line number Diff line number Diff line change @@ -156,6 +156,21 @@ describe('Test classes', function() {
156
156
method . body . children [ 0 ] . expr . offset . name . should . be . exactly ( 'list' ) ;
157
157
} ) ;
158
158
159
+ it ( 'test fallback on constant names' , function ( ) {
160
+ var ast = parser . parseEval (
161
+ [
162
+ 'class foo {' ,
163
+ ' const = true;' ,
164
+ '}'
165
+ ] . join ( '\n' ) , {
166
+ parser : {
167
+ suppressErrors : true
168
+ }
169
+ }
170
+ ) ;
171
+ ( ast . children [ 0 ] . body [ 0 ] . name === null ) . should . be . true ( 'constant name should be true' ) ;
172
+ ast . errors . length . should . be . exactly ( 1 ) ;
173
+ } ) ;
159
174
} ) ;
160
175
161
176
describe ( 'Advanced tests' , function ( ) {
You can’t perform that action at this time.
0 commit comments