diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d4434c9bf4b..606bd22f2c9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4664,6 +4664,13 @@ module ts { } function emitClassDeclarationAboveES6(node: ClassDeclaration) { + if (node.flags & NodeFlags.Export) { + write("export "); + + if (node.flags & NodeFlags.Default) { + write("default "); + } + } write("class "); emitDeclarationName(node); var baseTypeNode = getClassBaseTypeNode(node); diff --git a/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt b/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt new file mode 100644 index 00000000000..11b1de11bf6 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts(1,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided. +tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts(5,22): error TS2309: An export assignment cannot be used in a module with other exported elements. + + +==== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts (2 errors) ==== + export class C { + ~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + foo() { } + } + + export default class D { + ~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + bar() { } + } \ No newline at end of file diff --git a/tests/baselines/reference/emitClassDeclarationWithExport.js b/tests/baselines/reference/emitClassDeclarationWithExport.js new file mode 100644 index 00000000000..5a6c84389f3 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExport.js @@ -0,0 +1,23 @@ +//// [emitClassDeclarationWithExport.ts] +export class C { + foo() { } +} + +export default class D { + bar() { } +} + +//// [emitClassDeclarationWithExport.js] +export class C { + constructor() { + } + foo() { + } +} +export default class D { + constructor() { + } + bar() { + } +} +module.exports = D; diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts new file mode 100644 index 00000000000..f3ed5eb95d8 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts @@ -0,0 +1,8 @@ +// @target: es6 +export class C { + foo() { } +} + +export default class D { + bar() { } +} \ No newline at end of file