mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
The CoffeeScript compiler should error on trying to export anonymous classes (previously we were outputting invalid JavaScript that the runtime was erroring on)
This commit is contained in:
parent
0853b412c6
commit
48e00d81a9
3 changed files with 10 additions and 1 deletions
|
@ -1906,6 +1906,9 @@
|
|||
code.push(this.makeCode('default '));
|
||||
}
|
||||
if (!(this instanceof ExportDefaultDeclaration) && (this.clause instanceof Assign || this.clause instanceof Class)) {
|
||||
if (this.clause instanceof Class && !this.clause.variable) {
|
||||
this.clause.error('anonymous classes cannot be exported');
|
||||
}
|
||||
code.push(this.makeCode('var '));
|
||||
this.clause.moduleDeclaration = 'export';
|
||||
}
|
||||
|
|
|
@ -1285,6 +1285,10 @@ exports.ExportDeclaration = class ExportDeclaration extends ModuleDeclaration
|
|||
|
||||
if @ not instanceof ExportDefaultDeclaration and
|
||||
(@clause instanceof Assign or @clause instanceof Class)
|
||||
# Prevent exporting an anonymous class; all exported members must be named
|
||||
if @clause instanceof Class and not @clause.variable
|
||||
@clause.error 'anonymous classes cannot be exported'
|
||||
|
||||
# When the ES2015 `class` keyword is supported, don’t add a `var` here
|
||||
code.push @makeCode 'var '
|
||||
@clause.moduleDeclaration = 'export'
|
||||
|
|
|
@ -1012,7 +1012,9 @@ test "anonymous classes cannot be exported", ->
|
|||
constructor: ->
|
||||
console.log 'hello, world!'
|
||||
''', '''
|
||||
SyntaxError: Unexpected token export
|
||||
[stdin]:1:8: error: anonymous classes cannot be exported
|
||||
export class
|
||||
^^^^^
|
||||
'''
|
||||
|
||||
test "unless enclosed by curly braces, only * can be aliased", ->
|
||||
|
|
Loading…
Reference in a new issue