From b31ac2e946ed661ac9e0ea0cf7a2ef43cfa30ac6 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 12 Nov 2015 16:56:20 -0800 Subject: [PATCH 1/7] Add a handful of tests --- .../es6/moduleExportsAmd/defaultExportsGetExportedAmd.ts | 3 +++ .../moduleExportsCommonjs/defaultExportsGetExportedCommonjs.ts | 3 +++ .../es6/moduleExportsSystem/defaultExportsGetExportedSystem.ts | 3 +++ .../es6/moduleExportsUmd/defaultExportsGetExportedUmd.ts | 3 +++ 4 files changed, 12 insertions(+) create mode 100644 tests/cases/conformance/es6/moduleExportsAmd/defaultExportsGetExportedAmd.ts create mode 100644 tests/cases/conformance/es6/moduleExportsCommonjs/defaultExportsGetExportedCommonjs.ts create mode 100644 tests/cases/conformance/es6/moduleExportsSystem/defaultExportsGetExportedSystem.ts create mode 100644 tests/cases/conformance/es6/moduleExportsUmd/defaultExportsGetExportedUmd.ts diff --git a/tests/cases/conformance/es6/moduleExportsAmd/defaultExportsGetExportedAmd.ts b/tests/cases/conformance/es6/moduleExportsAmd/defaultExportsGetExportedAmd.ts new file mode 100644 index 00000000000..ef0f2ffde17 --- /dev/null +++ b/tests/cases/conformance/es6/moduleExportsAmd/defaultExportsGetExportedAmd.ts @@ -0,0 +1,3 @@ +// @target: ES6 +// @module: amd +export default class Foo {} diff --git a/tests/cases/conformance/es6/moduleExportsCommonjs/defaultExportsGetExportedCommonjs.ts b/tests/cases/conformance/es6/moduleExportsCommonjs/defaultExportsGetExportedCommonjs.ts new file mode 100644 index 00000000000..994f24df658 --- /dev/null +++ b/tests/cases/conformance/es6/moduleExportsCommonjs/defaultExportsGetExportedCommonjs.ts @@ -0,0 +1,3 @@ +// @target: ES6 +// @module: commonjs +export default class Foo {} diff --git a/tests/cases/conformance/es6/moduleExportsSystem/defaultExportsGetExportedSystem.ts b/tests/cases/conformance/es6/moduleExportsSystem/defaultExportsGetExportedSystem.ts new file mode 100644 index 00000000000..3764f2ec36c --- /dev/null +++ b/tests/cases/conformance/es6/moduleExportsSystem/defaultExportsGetExportedSystem.ts @@ -0,0 +1,3 @@ +// @target: ES6 +// @module: system +export default class Foo {} diff --git a/tests/cases/conformance/es6/moduleExportsUmd/defaultExportsGetExportedUmd.ts b/tests/cases/conformance/es6/moduleExportsUmd/defaultExportsGetExportedUmd.ts new file mode 100644 index 00000000000..39784fc7188 --- /dev/null +++ b/tests/cases/conformance/es6/moduleExportsUmd/defaultExportsGetExportedUmd.ts @@ -0,0 +1,3 @@ +// @target: ES6 +// @module: umd +export default class Foo {} From 57162e9b59c8126e4efc420f52b9666315086048 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 12 Nov 2015 18:11:07 -0800 Subject: [PATCH 2/7] handful more tests --- .../decoratedDefaultExportsGetExportedAmd.ts | 7 +++++++ .../decoratedDefaultExportsGetExportedCommonjs.ts | 7 +++++++ .../decoratedDefaultExportsGetExportedSystem.ts | 7 +++++++ .../decoratedDefaultExportsGetExportedUmd.ts | 7 +++++++ 4 files changed, 28 insertions(+) create mode 100644 tests/cases/conformance/es6/moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts create mode 100644 tests/cases/conformance/es6/moduleExportsCommonjs/decoratedDefaultExportsGetExportedCommonjs.ts create mode 100644 tests/cases/conformance/es6/moduleExportsSystem/decoratedDefaultExportsGetExportedSystem.ts create mode 100644 tests/cases/conformance/es6/moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts diff --git a/tests/cases/conformance/es6/moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts b/tests/cases/conformance/es6/moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts new file mode 100644 index 00000000000..3b51b80619f --- /dev/null +++ b/tests/cases/conformance/es6/moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts @@ -0,0 +1,7 @@ +// @target: ES6 +// @module: amd + +var decorator: ClassDecorator; + +@decorator +export default class Foo {} diff --git a/tests/cases/conformance/es6/moduleExportsCommonjs/decoratedDefaultExportsGetExportedCommonjs.ts b/tests/cases/conformance/es6/moduleExportsCommonjs/decoratedDefaultExportsGetExportedCommonjs.ts new file mode 100644 index 00000000000..3fc09a2eeb4 --- /dev/null +++ b/tests/cases/conformance/es6/moduleExportsCommonjs/decoratedDefaultExportsGetExportedCommonjs.ts @@ -0,0 +1,7 @@ +// @target: ES6 +// @module: commonjs + +var decorator: ClassDecorator; + +@decorator +export default class Foo {} diff --git a/tests/cases/conformance/es6/moduleExportsSystem/decoratedDefaultExportsGetExportedSystem.ts b/tests/cases/conformance/es6/moduleExportsSystem/decoratedDefaultExportsGetExportedSystem.ts new file mode 100644 index 00000000000..7957b78c805 --- /dev/null +++ b/tests/cases/conformance/es6/moduleExportsSystem/decoratedDefaultExportsGetExportedSystem.ts @@ -0,0 +1,7 @@ +// @target: ES6 +// @module: system + +var decorator: ClassDecorator; + +@decorator +export default class Foo {} diff --git a/tests/cases/conformance/es6/moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts b/tests/cases/conformance/es6/moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts new file mode 100644 index 00000000000..9dc63bec9c3 --- /dev/null +++ b/tests/cases/conformance/es6/moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts @@ -0,0 +1,7 @@ +// @target: ES6 +// @module: umd + +var decorator: ClassDecorator; + +@decorator +export default class Foo {} From b5ac1eb0ae3bd240b297750ea32b6d5a2e9451c5 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 12 Nov 2015 18:24:04 -0800 Subject: [PATCH 3/7] add decorator flag to tests --- .../moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts | 1 + .../decoratedDefaultExportsGetExportedCommonjs.ts | 1 + .../decoratedDefaultExportsGetExportedSystem.ts | 1 + .../moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts | 1 + 4 files changed, 4 insertions(+) diff --git a/tests/cases/conformance/es6/moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts b/tests/cases/conformance/es6/moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts index 3b51b80619f..87fc8afd263 100644 --- a/tests/cases/conformance/es6/moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts +++ b/tests/cases/conformance/es6/moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts @@ -1,4 +1,5 @@ // @target: ES6 +// @experimentalDecorators: true // @module: amd var decorator: ClassDecorator; diff --git a/tests/cases/conformance/es6/moduleExportsCommonjs/decoratedDefaultExportsGetExportedCommonjs.ts b/tests/cases/conformance/es6/moduleExportsCommonjs/decoratedDefaultExportsGetExportedCommonjs.ts index 3fc09a2eeb4..aefd07ffdb9 100644 --- a/tests/cases/conformance/es6/moduleExportsCommonjs/decoratedDefaultExportsGetExportedCommonjs.ts +++ b/tests/cases/conformance/es6/moduleExportsCommonjs/decoratedDefaultExportsGetExportedCommonjs.ts @@ -1,4 +1,5 @@ // @target: ES6 +// @experimentalDecorators: true // @module: commonjs var decorator: ClassDecorator; diff --git a/tests/cases/conformance/es6/moduleExportsSystem/decoratedDefaultExportsGetExportedSystem.ts b/tests/cases/conformance/es6/moduleExportsSystem/decoratedDefaultExportsGetExportedSystem.ts index 7957b78c805..b871b3c7b35 100644 --- a/tests/cases/conformance/es6/moduleExportsSystem/decoratedDefaultExportsGetExportedSystem.ts +++ b/tests/cases/conformance/es6/moduleExportsSystem/decoratedDefaultExportsGetExportedSystem.ts @@ -1,4 +1,5 @@ // @target: ES6 +// @experimentalDecorators: true // @module: system var decorator: ClassDecorator; diff --git a/tests/cases/conformance/es6/moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts b/tests/cases/conformance/es6/moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts index 9dc63bec9c3..9b0a7d773ef 100644 --- a/tests/cases/conformance/es6/moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts +++ b/tests/cases/conformance/es6/moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts @@ -1,4 +1,5 @@ // @target: ES6 +// @experimentalDecorators: true // @module: umd var decorator: ClassDecorator; From e79253a07c2b913810d5042ed592c3cacaad2f69 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 12 Nov 2015 18:27:47 -0800 Subject: [PATCH 4/7] fix handling of decorated default exports on es6 with nones6 modules --- src/compiler/emitter.ts | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 84d6f091039..ab9fe35b92f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5576,9 +5576,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitDecoratorsOfClass(node); } + if (!(node.flags & NodeFlags.Export)) { + return; + } // If this is an exported class, but not on the top level (i.e. on an internal // module), export it - if (!isES6ExportedDeclaration(node) && (node.flags & NodeFlags.Export)) { + if (node.parent.kind !== SyntaxKind.SourceFile) { writeLine(); emitStart(node); emitModuleMemberName(node); @@ -5587,12 +5590,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitEnd(node); write(";"); } - else if (isES6ExportedDeclaration(node) && (node.flags & NodeFlags.Default) && thisNodeIsDecorated) { + else if (node.parent.kind === SyntaxKind.SourceFile && (node.flags & NodeFlags.Default) && thisNodeIsDecorated) { // if this is a top level default export of decorated class, write the export after the declaration. - writeLine(); - write("export default "); - emitDeclarationName(node); - write(";"); + if (modulekind === ModuleKind.ES6) { + writeLine(); + write("export default "); + emitDeclarationName(node); + write(";"); + } + else if (modulekind === ModuleKind.System) { + writeLine(); + write(`${exportFunctionForFile}("default", `); + emitDeclarationName(node); + write(");"); + } + else { + writeLine(); + if (languageVersion === ScriptTarget.ES3) { + write(`exports["default"] = `); + } + else { + write(`exports.default = `); + } + emitDeclarationName(node); + write(";"); + } } } From 521a0a160c36eba85875817efb274c94dac58b87 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 12 Nov 2015 19:03:52 -0800 Subject: [PATCH 5/7] Fix class exports with varrying module emits while targeting es6 --- src/compiler/emitter.ts | 47 ++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ab9fe35b92f..323a5680ccc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5581,7 +5581,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } // If this is an exported class, but not on the top level (i.e. on an internal // module), export it - if (node.parent.kind !== SyntaxKind.SourceFile) { + if (node.parent.kind === SyntaxKind.SourceFile && (node.flags & NodeFlags.Default)) { + // if this is a top level default export of decorated class, write the export after the declaration. + writeLine(); + if (thisNodeIsDecorated && modulekind === ModuleKind.ES6) { + write("export default "); + emitDeclarationName(node); + write(";"); + } + else if (modulekind === ModuleKind.System) { + write(`${exportFunctionForFile}("default", `); + emitDeclarationName(node); + write(");"); + } + else if (modulekind !== ModuleKind.ES6) { + write(`exports.default = `); + emitDeclarationName(node); + write(";"); + } + } + else if (node.parent.kind !== SyntaxKind.SourceFile || (modulekind !== ModuleKind.ES6 && !(node.flags & NodeFlags.Default))) { writeLine(); emitStart(node); emitModuleMemberName(node); @@ -5590,32 +5609,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitEnd(node); write(";"); } - else if (node.parent.kind === SyntaxKind.SourceFile && (node.flags & NodeFlags.Default) && thisNodeIsDecorated) { - // if this is a top level default export of decorated class, write the export after the declaration. - if (modulekind === ModuleKind.ES6) { - writeLine(); - write("export default "); - emitDeclarationName(node); - write(";"); - } - else if (modulekind === ModuleKind.System) { - writeLine(); - write(`${exportFunctionForFile}("default", `); - emitDeclarationName(node); - write(");"); - } - else { - writeLine(); - if (languageVersion === ScriptTarget.ES3) { - write(`exports["default"] = `); - } - else { - write(`exports.default = `); - } - emitDeclarationName(node); - write(";"); - } - } } function emitClassLikeDeclarationBelowES6(node: ClassLikeDeclaration) { From 36607b99b51a2d812ca96da24069756acce44375 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 12 Nov 2015 19:05:28 -0800 Subject: [PATCH 6/7] accept baselines for new tests --- .../decoratedDefaultExportsGetExportedAmd.js | 24 ++++++++++++++ ...oratedDefaultExportsGetExportedAmd.symbols | 12 +++++++ ...ecoratedDefaultExportsGetExportedAmd.types | 12 +++++++ ...oratedDefaultExportsGetExportedCommonjs.js | 22 +++++++++++++ ...dDefaultExportsGetExportedCommonjs.symbols | 12 +++++++ ...tedDefaultExportsGetExportedCommonjs.types | 12 +++++++ ...ecoratedDefaultExportsGetExportedSystem.js | 29 +++++++++++++++++ ...tedDefaultExportsGetExportedSystem.symbols | 12 +++++++ ...ratedDefaultExportsGetExportedSystem.types | 12 +++++++ .../decoratedDefaultExportsGetExportedUmd.js | 31 +++++++++++++++++++ ...oratedDefaultExportsGetExportedUmd.symbols | 12 +++++++ ...ecoratedDefaultExportsGetExportedUmd.types | 12 +++++++ .../reference/defaultExportsGetExportedAmd.js | 10 ++++++ .../defaultExportsGetExportedAmd.symbols | 4 +++ .../defaultExportsGetExportedAmd.types | 4 +++ .../defaultExportsGetExportedCommonjs.js | 8 +++++ .../defaultExportsGetExportedCommonjs.symbols | 4 +++ .../defaultExportsGetExportedCommonjs.types | 4 +++ .../defaultExportsGetExportedSystem.js | 16 ++++++++++ .../defaultExportsGetExportedSystem.symbols | 4 +++ .../defaultExportsGetExportedSystem.types | 4 +++ .../reference/defaultExportsGetExportedUmd.js | 17 ++++++++++ .../defaultExportsGetExportedUmd.symbols | 4 +++ .../defaultExportsGetExportedUmd.types | 4 +++ 24 files changed, 285 insertions(+) create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.js create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.symbols create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.js create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.symbols create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.symbols create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.js create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.symbols create mode 100644 tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types create mode 100644 tests/baselines/reference/defaultExportsGetExportedAmd.js create mode 100644 tests/baselines/reference/defaultExportsGetExportedAmd.symbols create mode 100644 tests/baselines/reference/defaultExportsGetExportedAmd.types create mode 100644 tests/baselines/reference/defaultExportsGetExportedCommonjs.js create mode 100644 tests/baselines/reference/defaultExportsGetExportedCommonjs.symbols create mode 100644 tests/baselines/reference/defaultExportsGetExportedCommonjs.types create mode 100644 tests/baselines/reference/defaultExportsGetExportedSystem.js create mode 100644 tests/baselines/reference/defaultExportsGetExportedSystem.symbols create mode 100644 tests/baselines/reference/defaultExportsGetExportedSystem.types create mode 100644 tests/baselines/reference/defaultExportsGetExportedUmd.js create mode 100644 tests/baselines/reference/defaultExportsGetExportedUmd.symbols create mode 100644 tests/baselines/reference/defaultExportsGetExportedUmd.types diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.js b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.js new file mode 100644 index 00000000000..441d8b0d70a --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.js @@ -0,0 +1,24 @@ +//// [decoratedDefaultExportsGetExportedAmd.ts] + +var decorator: ClassDecorator; + +@decorator +export default class Foo {} + + +//// [decoratedDefaultExportsGetExportedAmd.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +define(["require", "exports"], function (require, exports) { + var decorator; + let Foo = class { + }; + Foo = __decorate([ + decorator + ], Foo); + exports.default = Foo; +}); diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.symbols b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.symbols new file mode 100644 index 00000000000..d8ff6716c38 --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts === + +var decorator: ClassDecorator; +>decorator : Symbol(decorator, Decl(decoratedDefaultExportsGetExportedAmd.ts, 1, 3)) +>ClassDecorator : Symbol(ClassDecorator, Decl(lib.d.ts, --, --)) + +@decorator +>decorator : Symbol(decorator, Decl(decoratedDefaultExportsGetExportedAmd.ts, 1, 3)) + +export default class Foo {} +>Foo : Symbol(Foo, Decl(decoratedDefaultExportsGetExportedAmd.ts, 1, 30)) + diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types new file mode 100644 index 00000000000..89df83ce76d --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts === + +var decorator: ClassDecorator; +>decorator : (target: TFunction) => TFunction | void +>ClassDecorator : (target: TFunction) => TFunction | void + +@decorator +>decorator : (target: TFunction) => TFunction | void + +export default class Foo {} +>Foo : Foo + diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.js b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.js new file mode 100644 index 00000000000..8818241c9b5 --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.js @@ -0,0 +1,22 @@ +//// [decoratedDefaultExportsGetExportedCommonjs.ts] + +var decorator: ClassDecorator; + +@decorator +export default class Foo {} + + +//// [decoratedDefaultExportsGetExportedCommonjs.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var decorator; +let Foo = class { +}; +Foo = __decorate([ + decorator +], Foo); +exports.default = Foo; diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.symbols b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.symbols new file mode 100644 index 00000000000..35131c1244e --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/moduleExportsCommonjs/decoratedDefaultExportsGetExportedCommonjs.ts === + +var decorator: ClassDecorator; +>decorator : Symbol(decorator, Decl(decoratedDefaultExportsGetExportedCommonjs.ts, 1, 3)) +>ClassDecorator : Symbol(ClassDecorator, Decl(lib.d.ts, --, --)) + +@decorator +>decorator : Symbol(decorator, Decl(decoratedDefaultExportsGetExportedCommonjs.ts, 1, 3)) + +export default class Foo {} +>Foo : Symbol(Foo, Decl(decoratedDefaultExportsGetExportedCommonjs.ts, 1, 30)) + diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types new file mode 100644 index 00000000000..56c8926342a --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/moduleExportsCommonjs/decoratedDefaultExportsGetExportedCommonjs.ts === + +var decorator: ClassDecorator; +>decorator : (target: TFunction) => TFunction | void +>ClassDecorator : (target: TFunction) => TFunction | void + +@decorator +>decorator : (target: TFunction) => TFunction | void + +export default class Foo {} +>Foo : Foo + diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js new file mode 100644 index 00000000000..1ae54560ae3 --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js @@ -0,0 +1,29 @@ +//// [decoratedDefaultExportsGetExportedSystem.ts] + +var decorator: ClassDecorator; + +@decorator +export default class Foo {} + + +//// [decoratedDefaultExportsGetExportedSystem.js] +System.register([], function(exports_1) { + var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; + }; + var decorator, Foo; + return { + setters:[], + execute: function() { + let Foo = class { + }; + Foo = __decorate([ + decorator + ], Foo); + exports_1("default", Foo); + } + } +}); diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.symbols b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.symbols new file mode 100644 index 00000000000..106ea3cacd8 --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/moduleExportsSystem/decoratedDefaultExportsGetExportedSystem.ts === + +var decorator: ClassDecorator; +>decorator : Symbol(decorator, Decl(decoratedDefaultExportsGetExportedSystem.ts, 1, 3)) +>ClassDecorator : Symbol(ClassDecorator, Decl(lib.d.ts, --, --)) + +@decorator +>decorator : Symbol(decorator, Decl(decoratedDefaultExportsGetExportedSystem.ts, 1, 3)) + +export default class Foo {} +>Foo : Symbol(Foo, Decl(decoratedDefaultExportsGetExportedSystem.ts, 1, 30)) + diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types new file mode 100644 index 00000000000..c180f5fcf09 --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/moduleExportsSystem/decoratedDefaultExportsGetExportedSystem.ts === + +var decorator: ClassDecorator; +>decorator : (target: TFunction) => TFunction | void +>ClassDecorator : (target: TFunction) => TFunction | void + +@decorator +>decorator : (target: TFunction) => TFunction | void + +export default class Foo {} +>Foo : Foo + diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.js b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.js new file mode 100644 index 00000000000..118af702fc1 --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.js @@ -0,0 +1,31 @@ +//// [decoratedDefaultExportsGetExportedUmd.ts] + +var decorator: ClassDecorator; + +@decorator +export default class Foo {} + + +//// [decoratedDefaultExportsGetExportedUmd.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +(function (factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + var decorator; + let Foo = class { + }; + Foo = __decorate([ + decorator + ], Foo); + exports.default = Foo; +}); diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.symbols b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.symbols new file mode 100644 index 00000000000..f4a8266cfa1 --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts === + +var decorator: ClassDecorator; +>decorator : Symbol(decorator, Decl(decoratedDefaultExportsGetExportedUmd.ts, 1, 3)) +>ClassDecorator : Symbol(ClassDecorator, Decl(lib.d.ts, --, --)) + +@decorator +>decorator : Symbol(decorator, Decl(decoratedDefaultExportsGetExportedUmd.ts, 1, 3)) + +export default class Foo {} +>Foo : Symbol(Foo, Decl(decoratedDefaultExportsGetExportedUmd.ts, 1, 30)) + diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types new file mode 100644 index 00000000000..a258a600ba0 --- /dev/null +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts === + +var decorator: ClassDecorator; +>decorator : (target: TFunction) => TFunction | void +>ClassDecorator : (target: TFunction) => TFunction | void + +@decorator +>decorator : (target: TFunction) => TFunction | void + +export default class Foo {} +>Foo : Foo + diff --git a/tests/baselines/reference/defaultExportsGetExportedAmd.js b/tests/baselines/reference/defaultExportsGetExportedAmd.js new file mode 100644 index 00000000000..4eba3ba9600 --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedAmd.js @@ -0,0 +1,10 @@ +//// [defaultExportsGetExportedAmd.ts] +export default class Foo {} + + +//// [defaultExportsGetExportedAmd.js] +define(["require", "exports"], function (require, exports) { + class Foo { + } + exports.default = Foo; +}); diff --git a/tests/baselines/reference/defaultExportsGetExportedAmd.symbols b/tests/baselines/reference/defaultExportsGetExportedAmd.symbols new file mode 100644 index 00000000000..22376f91b08 --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedAmd.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/moduleExportsAmd/defaultExportsGetExportedAmd.ts === +export default class Foo {} +>Foo : Symbol(Foo, Decl(defaultExportsGetExportedAmd.ts, 0, 0)) + diff --git a/tests/baselines/reference/defaultExportsGetExportedAmd.types b/tests/baselines/reference/defaultExportsGetExportedAmd.types new file mode 100644 index 00000000000..94e511dbef6 --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedAmd.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/moduleExportsAmd/defaultExportsGetExportedAmd.ts === +export default class Foo {} +>Foo : Foo + diff --git a/tests/baselines/reference/defaultExportsGetExportedCommonjs.js b/tests/baselines/reference/defaultExportsGetExportedCommonjs.js new file mode 100644 index 00000000000..a19b99fe9d3 --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedCommonjs.js @@ -0,0 +1,8 @@ +//// [defaultExportsGetExportedCommonjs.ts] +export default class Foo {} + + +//// [defaultExportsGetExportedCommonjs.js] +class Foo { +} +exports.default = Foo; diff --git a/tests/baselines/reference/defaultExportsGetExportedCommonjs.symbols b/tests/baselines/reference/defaultExportsGetExportedCommonjs.symbols new file mode 100644 index 00000000000..a5be95f1787 --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedCommonjs.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/moduleExportsCommonjs/defaultExportsGetExportedCommonjs.ts === +export default class Foo {} +>Foo : Symbol(Foo, Decl(defaultExportsGetExportedCommonjs.ts, 0, 0)) + diff --git a/tests/baselines/reference/defaultExportsGetExportedCommonjs.types b/tests/baselines/reference/defaultExportsGetExportedCommonjs.types new file mode 100644 index 00000000000..d7034ffa03d --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedCommonjs.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/moduleExportsCommonjs/defaultExportsGetExportedCommonjs.ts === +export default class Foo {} +>Foo : Foo + diff --git a/tests/baselines/reference/defaultExportsGetExportedSystem.js b/tests/baselines/reference/defaultExportsGetExportedSystem.js new file mode 100644 index 00000000000..1f1a7c9dea6 --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedSystem.js @@ -0,0 +1,16 @@ +//// [defaultExportsGetExportedSystem.ts] +export default class Foo {} + + +//// [defaultExportsGetExportedSystem.js] +System.register([], function(exports_1) { + var Foo; + return { + setters:[], + execute: function() { + class Foo { + } + exports_1("default", Foo); + } + } +}); diff --git a/tests/baselines/reference/defaultExportsGetExportedSystem.symbols b/tests/baselines/reference/defaultExportsGetExportedSystem.symbols new file mode 100644 index 00000000000..9050833680e --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedSystem.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/moduleExportsSystem/defaultExportsGetExportedSystem.ts === +export default class Foo {} +>Foo : Symbol(Foo, Decl(defaultExportsGetExportedSystem.ts, 0, 0)) + diff --git a/tests/baselines/reference/defaultExportsGetExportedSystem.types b/tests/baselines/reference/defaultExportsGetExportedSystem.types new file mode 100644 index 00000000000..d1439f0f99d --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedSystem.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/moduleExportsSystem/defaultExportsGetExportedSystem.ts === +export default class Foo {} +>Foo : Foo + diff --git a/tests/baselines/reference/defaultExportsGetExportedUmd.js b/tests/baselines/reference/defaultExportsGetExportedUmd.js new file mode 100644 index 00000000000..ed3639ace55 --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedUmd.js @@ -0,0 +1,17 @@ +//// [defaultExportsGetExportedUmd.ts] +export default class Foo {} + + +//// [defaultExportsGetExportedUmd.js] +(function (factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + class Foo { + } + exports.default = Foo; +}); diff --git a/tests/baselines/reference/defaultExportsGetExportedUmd.symbols b/tests/baselines/reference/defaultExportsGetExportedUmd.symbols new file mode 100644 index 00000000000..9c59f10e6e0 --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedUmd.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/moduleExportsUmd/defaultExportsGetExportedUmd.ts === +export default class Foo {} +>Foo : Symbol(Foo, Decl(defaultExportsGetExportedUmd.ts, 0, 0)) + diff --git a/tests/baselines/reference/defaultExportsGetExportedUmd.types b/tests/baselines/reference/defaultExportsGetExportedUmd.types new file mode 100644 index 00000000000..ed5f4b7f709 --- /dev/null +++ b/tests/baselines/reference/defaultExportsGetExportedUmd.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/moduleExportsUmd/defaultExportsGetExportedUmd.ts === +export default class Foo {} +>Foo : Foo + From e41f1ae04d69f1dadf02c40c56d378098865f2ff Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 17 Nov 2015 13:03:15 -0800 Subject: [PATCH 7/7] only check against default flag --- src/compiler/emitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 4bddaa221e8..1cd017cbf2b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5583,7 +5583,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } // If this is an exported class, but not on the top level (i.e. on an internal // module), export it - if (node.parent.kind === SyntaxKind.SourceFile && (node.flags & NodeFlags.Default)) { + if (node.flags & NodeFlags.Default) { // if this is a top level default export of decorated class, write the export after the declaration. writeLine(); if (thisNodeIsDecorated && modulekind === ModuleKind.ES6) {