Skip to content

Commit 6dbe42e

Browse files
committed
glayzzle#95 test & fix constant missing names
1 parent 627f9fe commit 6dbe42e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/parser/class.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,14 @@ module.exports = {
182182
* @return {Constant} [:link:](AST.md#constant)
183183
*/
184184
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;
186188
if (this.token === this.tok.T_STRING || this.is('IDENTIFIER')) {
187189
name = this.text();
188190
this.next();
191+
} else {
192+
this.expect('IDENTIFIER');
189193
}
190194
if (this.expect('=')) {
191195
value = this.next().read_expr();

test/classTests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ describe('Test classes', function() {
156156
method.body.children[0].expr.offset.name.should.be.exactly('list');
157157
});
158158

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+
});
159174
});
160175

161176
describe('Advanced tests', function() {

0 commit comments

Comments
 (0)