diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fd0d4ad796e5d..cd827a54c5196 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3012,6 +3012,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return result; } + function emitEs6ExportDefaultCompat(node: Node) { + if (node.parent.kind === SyntaxKind.SourceFile) { + Debug.assert(!!(node.flags & NodeFlags.Default) || node.kind === SyntaxKind.ExportAssignment); + // only allow export default at a source file level + if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) { + if (!currentSourceFile.symbol.exports["___esModule"]) { + if (languageVersion === ScriptTarget.ES5) { + // default value of configurable, enumerable, writable are `false`. + write("Object.defineProperty(exports, \"__esModule\", { value: true });"); + writeLine(); + } + else if (languageVersion === ScriptTarget.ES3) { + write("exports.__esModule = true;"); + writeLine(); + } + } + } + } + } + function emitExportMemberAssignment(node: FunctionLikeDeclaration | ClassDeclaration) { if (node.flags & NodeFlags.Export) { writeLine(); @@ -3034,9 +3054,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } else { if (node.flags & NodeFlags.Default) { + emitEs6ExportDefaultCompat(node); if (languageVersion === ScriptTarget.ES3) { write("exports[\"default\"]"); - } else { + } + else { write("exports.default"); } } @@ -5529,6 +5551,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(")"); } else { + emitEs6ExportDefaultCompat(node); emitContainingModuleName(node); if (languageVersion === ScriptTarget.ES3) { write("[\"default\"] = "); diff --git a/tests/baselines/reference/es5-commonjs.js b/tests/baselines/reference/es5-commonjs.js new file mode 100644 index 0000000000000..2a0c6d924ca49 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs.js @@ -0,0 +1,27 @@ +//// [es5-commonjs.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-commonjs.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = A; diff --git a/tests/baselines/reference/es5-commonjs.symbols b/tests/baselines/reference/es5-commonjs.symbols new file mode 100644 index 0000000000000..41e4484afcde9 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-commonjs.ts === + +export default class A +>A : Symbol(A, Decl(es5-commonjs.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-commonjs.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-commonjs.types b/tests/baselines/reference/es5-commonjs.types new file mode 100644 index 0000000000000..4c1bc9229177f --- /dev/null +++ b/tests/baselines/reference/es5-commonjs.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-commonjs.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-commonjs2.js b/tests/baselines/reference/es5-commonjs2.js new file mode 100644 index 0000000000000..174665b41255a --- /dev/null +++ b/tests/baselines/reference/es5-commonjs2.js @@ -0,0 +1,8 @@ +//// [es5-commonjs2.ts] + +export default 1; + + +//// [es5-commonjs2.js] +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = 1; diff --git a/tests/baselines/reference/es5-commonjs2.symbols b/tests/baselines/reference/es5-commonjs2.symbols new file mode 100644 index 0000000000000..ee57f9ad5cdad --- /dev/null +++ b/tests/baselines/reference/es5-commonjs2.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5-commonjs2.ts === + +No type information for this code.export default 1; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5-commonjs2.types b/tests/baselines/reference/es5-commonjs2.types new file mode 100644 index 0000000000000..ee57f9ad5cdad --- /dev/null +++ b/tests/baselines/reference/es5-commonjs2.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5-commonjs2.ts === + +No type information for this code.export default 1; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5-commonjs3.js b/tests/baselines/reference/es5-commonjs3.js new file mode 100644 index 0000000000000..cc3d0b1527a2a --- /dev/null +++ b/tests/baselines/reference/es5-commonjs3.js @@ -0,0 +1,9 @@ +//// [es5-commonjs3.ts] + +export default "test"; +export var __esModule = 1; + + +//// [es5-commonjs3.js] +exports.default = "test"; +exports.__esModule = 1; diff --git a/tests/baselines/reference/es5-commonjs3.symbols b/tests/baselines/reference/es5-commonjs3.symbols new file mode 100644 index 0000000000000..9d5bc830099e8 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es5-commonjs3.ts === + +export default "test"; +export var __esModule = 1; +>__esModule : Symbol(__esModule, Decl(es5-commonjs3.ts, 2, 10)) + diff --git a/tests/baselines/reference/es5-commonjs3.types b/tests/baselines/reference/es5-commonjs3.types new file mode 100644 index 0000000000000..facdfae00ce94 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs3.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs3.ts === + +export default "test"; +export var __esModule = 1; +>__esModule : number +>1 : number + diff --git a/tests/baselines/reference/es5-commonjs4.js b/tests/baselines/reference/es5-commonjs4.js new file mode 100644 index 0000000000000..50a4c49e464f3 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs4.js @@ -0,0 +1,28 @@ +//// [es5-commonjs4.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} +export var __esModule = 1; + + +//// [es5-commonjs4.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.default = A; +exports.__esModule = 1; diff --git a/tests/baselines/reference/es5-commonjs4.symbols b/tests/baselines/reference/es5-commonjs4.symbols new file mode 100644 index 0000000000000..22d41128d7411 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs4.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/es5-commonjs4.ts === + +export default class A +>A : Symbol(A, Decl(es5-commonjs4.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-commonjs4.ts, 6, 5)) + { + return 42; + } +} +export var __esModule = 1; +>__esModule : Symbol(__esModule, Decl(es5-commonjs4.ts, 13, 10)) + diff --git a/tests/baselines/reference/es5-commonjs4.types b/tests/baselines/reference/es5-commonjs4.types new file mode 100644 index 0000000000000..d3471afbfeb52 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs4.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es5-commonjs4.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} +export var __esModule = 1; +>__esModule : number +>1 : number + diff --git a/tests/baselines/reference/es5-commonjs5.js b/tests/baselines/reference/es5-commonjs5.js new file mode 100644 index 0000000000000..ead6079eff13e --- /dev/null +++ b/tests/baselines/reference/es5-commonjs5.js @@ -0,0 +1,13 @@ +//// [es5-commonjs5.ts] + +export default function () { + return "test"; +} + + +//// [es5-commonjs5.js] +function default_1() { + return "test"; +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = default_1; diff --git a/tests/baselines/reference/es5-commonjs5.symbols b/tests/baselines/reference/es5-commonjs5.symbols new file mode 100644 index 0000000000000..b134e21666834 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs5.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs5.ts === + +No type information for this code.export default function () { +No type information for this code. return "test"; +No type information for this code.} +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5-commonjs5.types b/tests/baselines/reference/es5-commonjs5.types new file mode 100644 index 0000000000000..d8094e1e0ea1b --- /dev/null +++ b/tests/baselines/reference/es5-commonjs5.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs5.ts === + +export default function () { + return "test"; +>"test" : string +} + diff --git a/tests/baselines/reference/es5-commonjs6.js b/tests/baselines/reference/es5-commonjs6.js new file mode 100644 index 0000000000000..7c2c8b21779d9 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs6.js @@ -0,0 +1,10 @@ +//// [es5-commonjs6.ts] + +export default "test"; +var __esModule = 1; + + +//// [es5-commonjs6.js] +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = "test"; +var __esModule = 1; diff --git a/tests/baselines/reference/es5-commonjs6.symbols b/tests/baselines/reference/es5-commonjs6.symbols new file mode 100644 index 0000000000000..7a2847e0f25e0 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs6.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es5-commonjs6.ts === + +export default "test"; +var __esModule = 1; +>__esModule : Symbol(__esModule, Decl(es5-commonjs6.ts, 2, 3)) + diff --git a/tests/baselines/reference/es5-commonjs6.types b/tests/baselines/reference/es5-commonjs6.types new file mode 100644 index 0000000000000..904b69dec2244 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs6.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs6.ts === + +export default "test"; +var __esModule = 1; +>__esModule : number +>1 : number + diff --git a/tests/baselines/reference/es5-system.js b/tests/baselines/reference/es5-system.js new file mode 100644 index 0000000000000..2674527722a9e --- /dev/null +++ b/tests/baselines/reference/es5-system.js @@ -0,0 +1,34 @@ +//// [es5-system.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-system.js] +System.register([], function(exports_1) { + var A; + return { + setters:[], + execute: function() { + A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + exports_1("default", A); + } + } +}); diff --git a/tests/baselines/reference/es5-system.symbols b/tests/baselines/reference/es5-system.symbols new file mode 100644 index 0000000000000..5211e3c4259d5 --- /dev/null +++ b/tests/baselines/reference/es5-system.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-system.ts === + +export default class A +>A : Symbol(A, Decl(es5-system.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-system.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-system.types b/tests/baselines/reference/es5-system.types new file mode 100644 index 0000000000000..eae884a78b45d --- /dev/null +++ b/tests/baselines/reference/es5-system.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-system.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-umd3.js b/tests/baselines/reference/es5-umd3.js index 3abb92f816fb9..92ac306698a43 100644 --- a/tests/baselines/reference/es5-umd3.js +++ b/tests/baselines/reference/es5-umd3.js @@ -31,5 +31,6 @@ export default class A }; return A; })(); + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = A; }); diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js index b5cfdb02f7838..0d4076e39a183 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js @@ -12,6 +12,7 @@ var C = (function () { C.prototype.method = function () { }; return C; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = C; diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js index de0d109dadf8d..5e5eeae1f0f93 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js @@ -12,6 +12,7 @@ var default_1 = (function () { default_1.prototype.method = function () { }; return default_1; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js index bff80940a02cb..a977447f9ad6d 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js @@ -24,6 +24,7 @@ var C = (function () { }; return C; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = C; var after = new C(); var t = C; diff --git a/tests/baselines/reference/es5ExportDefaultExpression.js b/tests/baselines/reference/es5ExportDefaultExpression.js index 944b6fc71a5fc..a825e45971bb6 100644 --- a/tests/baselines/reference/es5ExportDefaultExpression.js +++ b/tests/baselines/reference/es5ExportDefaultExpression.js @@ -4,6 +4,7 @@ export default (1 + 2); //// [es5ExportDefaultExpression.js] +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = (1 + 2); diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js index 673cc3cb4534b..afc44ac53f506 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js @@ -5,6 +5,7 @@ export default function f() { } //// [es5ExportDefaultFunctionDeclaration.js] function f() { } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js index ad1334e810b6c..10f1db6a0eb1d 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js @@ -5,6 +5,7 @@ export default function () { } //// [es5ExportDefaultFunctionDeclaration2.js] function default_1() { } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js index 1fc5797643948..af437c087662e 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js @@ -13,6 +13,7 @@ var before = func(); function func() { return func; } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = func; var after = func(); diff --git a/tests/baselines/reference/es5ExportDefaultIdentifier.js b/tests/baselines/reference/es5ExportDefaultIdentifier.js index 739f3d6c1095e..c8fb6b3be2785 100644 --- a/tests/baselines/reference/es5ExportDefaultIdentifier.js +++ b/tests/baselines/reference/es5ExportDefaultIdentifier.js @@ -8,6 +8,7 @@ export default f; //// [es5ExportDefaultIdentifier.js] function f() { } exports.f = f; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f; diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.js b/tests/baselines/reference/es6ImportDefaultBindingAmd.js index 70e4f7e2f57a1..9c8cbec9db5cc 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingAmd.js +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.js @@ -14,6 +14,7 @@ import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import //// [es6ImportDefaultBindingAmd_0.js] define(["require", "exports"], function (require, exports) { var a = 10; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [es6ImportDefaultBindingAmd_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingDts.js index caa46ed30efe2..a5e8d509da113 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.js @@ -17,6 +17,7 @@ var c = (function () { } return c; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = c; //// [client.js] var server_1 = require("server"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js index 15ca1284a1e0b..7090b7a066389 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js @@ -22,6 +22,7 @@ var x: number = defaultBinding6; //// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.js] var es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js index b6b03176df115..2b0e3ebbeb520 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js @@ -22,6 +22,7 @@ export var x1: number = defaultBinding6; //// [server.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [client.js] var server_1 = require("server"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js index e6211ac1ebec0..dad034c618cab 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js @@ -25,6 +25,7 @@ var a = (function () { } return a; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [client.js] var server_1 = require("server"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js index 90521007735c0..b7da05d7dbbb9 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js @@ -27,6 +27,7 @@ define(["require", "exports"], function (require, exports) { exports.a = 10; exports.x = exports.a; exports.m = exports.a; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = {}; }); //// [client.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js index c2bd5476a7c4e..4a9871102248f 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js @@ -11,6 +11,7 @@ var x: number = defaultBinding; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] var es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"), nameSpaceBinding = es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0_1; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js index ed40582e9231d..a032325fbb446 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js @@ -12,6 +12,7 @@ export var x: number = defaultBinding; //// [server.js] define(["require", "exports"], function (require, exports) { var a = 10; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [client.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js index e03ded5fd5aaf..639ffce59fd0b 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js @@ -16,6 +16,7 @@ define(["require", "exports"], function (require, exports) { } return a; })(); + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [client.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js index 1208ace5ddef4..10b8bec03c72f 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js +++ b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js @@ -18,6 +18,7 @@ import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be //// [es6ImportDefaultBindingMergeErrors_0.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [es6ImportDefaultBindingMergeErrors_1.js] var es6ImportDefaultBindingMergeErrors_0_1 = require("es6ImportDefaultBindingMergeErrors_0"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js index e2c5fab4c94b6..2fb7f0644b9ca 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingWithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js @@ -13,6 +13,7 @@ export import defaultBinding2 from "server"; // non referenced //// [server.js] define(["require", "exports"], function (require, exports) { var a = 10; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [client.js] diff --git a/tests/baselines/reference/exportAndImport-es3-amd.js b/tests/baselines/reference/exportAndImport-es3-amd.js index a4552e70d68d2..d2293a56e2365 100644 --- a/tests/baselines/reference/exportAndImport-es3-amd.js +++ b/tests/baselines/reference/exportAndImport-es3-amd.js @@ -16,6 +16,7 @@ export default function f2() { define(["require", "exports"], function (require, exports) { function f1() { } + exports.__esModule = true; exports["default"] = f1; }); //// [m2.js] @@ -23,5 +24,6 @@ define(["require", "exports", "./m1"], function (require, exports, m1_1) { function f2() { m1_1["default"](); } + exports.__esModule = true; exports["default"] = f2; }); diff --git a/tests/baselines/reference/exportAndImport-es3.js b/tests/baselines/reference/exportAndImport-es3.js index 5f467509b689c..1be548bc9305c 100644 --- a/tests/baselines/reference/exportAndImport-es3.js +++ b/tests/baselines/reference/exportAndImport-es3.js @@ -15,10 +15,12 @@ export default function f2() { //// [m1.js] function f1() { } +exports.__esModule = true; exports["default"] = f1; //// [m2.js] var m1_1 = require("./m1"); function f2() { m1_1["default"](); } +exports.__esModule = true; exports["default"] = f2; diff --git a/tests/baselines/reference/exportAndImport-es5-amd.js b/tests/baselines/reference/exportAndImport-es5-amd.js index 4966af874f7fa..447356b12302a 100644 --- a/tests/baselines/reference/exportAndImport-es5-amd.js +++ b/tests/baselines/reference/exportAndImport-es5-amd.js @@ -16,6 +16,7 @@ export default function f2() { define(["require", "exports"], function (require, exports) { function f1() { } + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f1; }); //// [m2.js] @@ -23,5 +24,6 @@ define(["require", "exports", "./m1"], function (require, exports, m1_1) { function f2() { m1_1.default(); } + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f2; }); diff --git a/tests/baselines/reference/exportAndImport-es5.js b/tests/baselines/reference/exportAndImport-es5.js index 02d0e43e5a91e..c0bacb94aeef0 100644 --- a/tests/baselines/reference/exportAndImport-es5.js +++ b/tests/baselines/reference/exportAndImport-es5.js @@ -15,10 +15,12 @@ export default function f2() { //// [m1.js] function f1() { } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f1; //// [m2.js] var m1_1 = require("./m1"); function f2() { m1_1.default(); } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f2; diff --git a/tests/baselines/reference/exportStar-amd.js b/tests/baselines/reference/exportStar-amd.js index dcd2d126a3539..534a23b4d5bd7 100644 --- a/tests/baselines/reference/exportStar-amd.js +++ b/tests/baselines/reference/exportStar-amd.js @@ -36,6 +36,7 @@ define(["require", "exports"], function (require, exports) { }); //// [t2.js] define(["require", "exports"], function (require, exports) { + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; function foo() { } exports.foo = foo; diff --git a/tests/baselines/reference/exportStar.js b/tests/baselines/reference/exportStar.js index d219a3650e727..74cf24a0f9718 100644 --- a/tests/baselines/reference/exportStar.js +++ b/tests/baselines/reference/exportStar.js @@ -33,6 +33,7 @@ foo; exports.x = 1; exports.y = 2; //// [t2.js] +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; function foo() { } exports.foo = foo; diff --git a/tests/baselines/reference/exportsAndImports4-amd.js b/tests/baselines/reference/exportsAndImports4-amd.js index db28ed5b35009..e6a431854b27b 100644 --- a/tests/baselines/reference/exportsAndImports4-amd.js +++ b/tests/baselines/reference/exportsAndImports4-amd.js @@ -41,6 +41,7 @@ export { a, b, c, d, e1, e2, f1, f2 }; //// [t1.js] define(["require", "exports"], function (require, exports) { + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; }); //// [t3.js] diff --git a/tests/baselines/reference/exportsAndImports4.js b/tests/baselines/reference/exportsAndImports4.js index ea5f34b882be8..7358b31eacec3 100644 --- a/tests/baselines/reference/exportsAndImports4.js +++ b/tests/baselines/reference/exportsAndImports4.js @@ -40,6 +40,7 @@ export { a, b, c, d, e1, e2, f1, f2 }; //// [t1.js] +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; //// [t3.js] var a = require("./t1"); diff --git a/tests/baselines/reference/tsxAttributeResolution9.symbols b/tests/baselines/reference/tsxAttributeResolution9.symbols deleted file mode 100644 index 081482d5d47a4..0000000000000 --- a/tests/baselines/reference/tsxAttributeResolution9.symbols +++ /dev/null @@ -1,47 +0,0 @@ -=== tests/cases/conformance/jsx/react.d.ts === - -declare module JSX { ->JSX : Symbol(JSX, Decl(react.d.ts, 0, 0)) - - interface Element { } ->Element : Symbol(Element, Decl(react.d.ts, 1, 20)) - - interface IntrinsicElements { ->IntrinsicElements : Symbol(IntrinsicElements, Decl(react.d.ts, 2, 22)) - } - interface ElementAttributesProperty { ->ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(react.d.ts, 4, 2)) - - props; ->props : Symbol(props, Decl(react.d.ts, 5, 38)) - } -} - -interface Props { ->Props : Symbol(Props, Decl(react.d.ts, 8, 1)) - - foo: string; ->foo : Symbol(foo, Decl(react.d.ts, 10, 17)) -} - -=== tests/cases/conformance/jsx/file.tsx === -export class MyComponent { ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) - - render() { ->render : Symbol(render, Decl(file.tsx, 0, 26)) - } - - props: { foo: string; } ->props : Symbol(props, Decl(file.tsx, 2, 3)) ->foo : Symbol(foo, Decl(file.tsx, 4, 10)) -} - -; // ok ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) ->foo : Symbol(unknown) - -; // should be an error ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) ->foo : Symbol(unknown) - diff --git a/tests/baselines/reference/tsxAttributeResolution9.types b/tests/baselines/reference/tsxAttributeResolution9.types deleted file mode 100644 index 1b2c6d423896a..0000000000000 --- a/tests/baselines/reference/tsxAttributeResolution9.types +++ /dev/null @@ -1,49 +0,0 @@ -=== tests/cases/conformance/jsx/react.d.ts === - -declare module JSX { ->JSX : any - - interface Element { } ->Element : Element - - interface IntrinsicElements { ->IntrinsicElements : IntrinsicElements - } - interface ElementAttributesProperty { ->ElementAttributesProperty : ElementAttributesProperty - - props; ->props : any - } -} - -interface Props { ->Props : Props - - foo: string; ->foo : string -} - -=== tests/cases/conformance/jsx/file.tsx === -export class MyComponent { ->MyComponent : MyComponent - - render() { ->render : () => void - } - - props: { foo: string; } ->props : { foo: string; } ->foo : string -} - -; // ok -> : JSX.Element ->MyComponent : typeof MyComponent ->foo : any - -; // should be an error -> : JSX.Element ->MyComponent : typeof MyComponent ->foo : any - diff --git a/tests/cases/compiler/es5-commonjs.ts b/tests/cases/compiler/es5-commonjs.ts new file mode 100644 index 0000000000000..21eb3732ada08 --- /dev/null +++ b/tests/cases/compiler/es5-commonjs.ts @@ -0,0 +1,17 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} diff --git a/tests/cases/compiler/es5-commonjs2.ts b/tests/cases/compiler/es5-commonjs2.ts new file mode 100644 index 0000000000000..c6b404c7ef5f2 --- /dev/null +++ b/tests/cases/compiler/es5-commonjs2.ts @@ -0,0 +1,6 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default 1; diff --git a/tests/cases/compiler/es5-commonjs3.ts b/tests/cases/compiler/es5-commonjs3.ts new file mode 100644 index 0000000000000..54f2c9ac6fe1c --- /dev/null +++ b/tests/cases/compiler/es5-commonjs3.ts @@ -0,0 +1,7 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default "test"; +export var __esModule = 1; diff --git a/tests/cases/compiler/es5-commonjs4.ts b/tests/cases/compiler/es5-commonjs4.ts new file mode 100644 index 0000000000000..ce4f8ef68832d --- /dev/null +++ b/tests/cases/compiler/es5-commonjs4.ts @@ -0,0 +1,18 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} +export var __esModule = 1; diff --git a/tests/cases/compiler/es5-commonjs5.ts b/tests/cases/compiler/es5-commonjs5.ts new file mode 100644 index 0000000000000..631dd11a39ae7 --- /dev/null +++ b/tests/cases/compiler/es5-commonjs5.ts @@ -0,0 +1,8 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default function () { + return "test"; +} diff --git a/tests/cases/compiler/es5-commonjs6.ts b/tests/cases/compiler/es5-commonjs6.ts new file mode 100644 index 0000000000000..676e5bddb48ff --- /dev/null +++ b/tests/cases/compiler/es5-commonjs6.ts @@ -0,0 +1,7 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default "test"; +var __esModule = 1; diff --git a/tests/cases/compiler/es5-system.ts b/tests/cases/compiler/es5-system.ts new file mode 100644 index 0000000000000..e615f7e54121a --- /dev/null +++ b/tests/cases/compiler/es5-system.ts @@ -0,0 +1,17 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: system + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +}