diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 9726c6402e168..cb7c82b14a664 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -998,8 +998,8 @@ namespace ts { setOriginalNode( setTextRange( createExpressionStatement( - createExportExpression(getExportName(specifier), exportedValue) - ), + createExportExpression(getExportName(specifier), exportedValue, /* location */ undefined, /* liveBinding */ true) + ), specifier), specifier ) @@ -1310,7 +1310,7 @@ namespace ts { case SyntaxKind.NamedImports: for (const importBinding of namedBindings.elements) { - statements = appendExportsOfDeclaration(statements, importBinding); + statements = appendExportsOfDeclaration(statements, importBinding, /* liveBinding */ true); } break; @@ -1420,12 +1420,12 @@ namespace ts { * appended. * @param decl The declaration to export. */ - function appendExportsOfDeclaration(statements: Statement[] | undefined, decl: Declaration): Statement[] | undefined { + function appendExportsOfDeclaration(statements: Statement[] | undefined, decl: Declaration, liveBinding?: boolean): Statement[] | undefined { const name = getDeclarationName(decl); const exportSpecifiers = currentModuleInfo.exportSpecifiers.get(idText(name)); if (exportSpecifiers) { for (const exportSpecifier of exportSpecifiers) { - statements = appendExportStatement(statements, exportSpecifier.name, name, /*location*/ exportSpecifier.name); + statements = appendExportStatement(statements, exportSpecifier.name, name, /*location*/ exportSpecifier.name, /* allowComments */ undefined, liveBinding); } } return statements; @@ -1443,8 +1443,8 @@ namespace ts { * @param location The location to use for source maps and comments for the export. * @param allowComments Whether to allow comments on the export. */ - function appendExportStatement(statements: Statement[] | undefined, exportName: Identifier, expression: Expression, location?: TextRange, allowComments?: boolean): Statement[] | undefined { - statements = append(statements, createExportStatement(exportName, expression, location, allowComments)); + function appendExportStatement(statements: Statement[] | undefined, exportName: Identifier, expression: Expression, location?: TextRange, allowComments?: boolean, liveBinding?: boolean): Statement[] | undefined { + statements = append(statements, createExportStatement(exportName, expression, location, allowComments, liveBinding)); return statements; } @@ -1485,8 +1485,8 @@ namespace ts { * @param location The location to use for source maps and comments for the export. * @param allowComments An optional value indicating whether to emit comments for the statement. */ - function createExportStatement(name: Identifier, value: Expression, location?: TextRange, allowComments?: boolean) { - const statement = setTextRange(createExpressionStatement(createExportExpression(name, value)), location); + function createExportStatement(name: Identifier, value: Expression, location?: TextRange, allowComments?: boolean, liveBinding?: boolean) { + const statement = setTextRange(createExpressionStatement(createExportExpression(name, value, /* location */ undefined, liveBinding)), location); startOnNewLine(statement); if (!allowComments) { setEmitFlags(statement, EmitFlags.NoComments); @@ -1502,9 +1502,30 @@ namespace ts { * @param value The exported value. * @param location The location to use for source maps and comments for the export. */ - function createExportExpression(name: Identifier, value: Expression, location?: TextRange) { + function createExportExpression(name: Identifier, value: Expression, location?: TextRange, liveBinding?: boolean) { return setTextRange( - createAssignment( + liveBinding && languageVersion !== ScriptTarget.ES3 ? createCall( + createPropertyAccess( + createIdentifier("Object"), + "defineProperty" + ), + /*typeArguments*/ undefined, + [ + createIdentifier("exports"), + createLiteral(name), + createObjectLiteral([ + createPropertyAssignment("enumerable", createLiteral(/*value*/ true)), + createPropertyAssignment("get", createArrowFunction( + /*modifiers*/ undefined, + /*typeParameters*/ undefined, + /*parameters*/ [], + /*type*/ undefined, + /*equalsGreaterThanToken*/ undefined, + value + )) + ]) + ] + ) : createAssignment( createPropertyAccess( createIdentifier("exports"), getSynthesizedClone(name) @@ -1786,7 +1807,18 @@ namespace ts { scoped: true, text: ` function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } }` }; diff --git a/tests/baselines/reference/ambientShorthand_reExport.js b/tests/baselines/reference/ambientShorthand_reExport.js index 6842d0f75541f..e32f3504fec71 100644 --- a/tests/baselines/reference/ambientShorthand_reExport.js +++ b/tests/baselines/reference/ambientShorthand_reExport.js @@ -24,7 +24,18 @@ exports.x = jquery_1.x; //// [reExportAll.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; __export(require("jquery")); diff --git a/tests/baselines/reference/commentsOnRequireStatement.js b/tests/baselines/reference/commentsOnRequireStatement.js index 2a39206ecf3c0..0511285b2d2f2 100644 --- a/tests/baselines/reference/commentsOnRequireStatement.js +++ b/tests/baselines/reference/commentsOnRequireStatement.js @@ -32,7 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); // blah // blah var _0_1 = require("./0"); -exports.subject = _0_1.subject; +Object.defineProperty(exports, "subject", { enumerable: true, get: () => _0_1.subject }); /* blah1 */ var _1_1 = require("./1"); -exports.subject1 = _1_1.subject1; +Object.defineProperty(exports, "subject1", { enumerable: true, get: () => _1_1.subject1 }); diff --git a/tests/baselines/reference/declarationEmitExportDeclaration.js b/tests/baselines/reference/declarationEmitExportDeclaration.js index 1cde34aeba0d2..b1d7f9aab3781 100644 --- a/tests/baselines/reference/declarationEmitExportDeclaration.js +++ b/tests/baselines/reference/declarationEmitExportDeclaration.js @@ -23,7 +23,7 @@ exports.bar = bar; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var utils_1 = require("./utils"); -exports.bar = utils_1.bar; +Object.defineProperty(exports, "bar", { enumerable: true, get: () => utils_1.bar }); utils_1.foo(); var obj; diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js index 0683f21cd575a..a6e3a59de40b4 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js @@ -51,7 +51,15 @@ exports.ADMIN = pkg2_1.MetadataAccessor.create('1'); //// [index.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { + enumerable: true, + get: function () { + return m[p]; + } + }); + } } Object.defineProperty(exports, "__esModule", { value: true }); __export(require("./keys")); diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js index 5403cb95effe5..787eedd3c851b 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js @@ -54,7 +54,18 @@ exports.ADMIN = pkg2_1.MetadataAccessor.create('1'); //// [index.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } Object.defineProperty(exports, "__esModule", { value: true }); __export(require("./keys")); diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js index 2ac5a9fffbd0c..7b9b8412e9f64 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js @@ -51,7 +51,15 @@ exports.ADMIN = pkg2_1.MetadataAccessor.create('1'); //// [index.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { + enumerable: true, + get: function () { + return m[p]; + } + }); + } } Object.defineProperty(exports, "__esModule", { value: true }); __export(require("./keys")); diff --git a/tests/baselines/reference/doubleUnderscoreExportStarConflict.js b/tests/baselines/reference/doubleUnderscoreExportStarConflict.js index e73c586852575..2d70cfedf4ab5 100644 --- a/tests/baselines/reference/doubleUnderscoreExportStarConflict.js +++ b/tests/baselines/reference/doubleUnderscoreExportStarConflict.js @@ -24,7 +24,18 @@ exports.__foo = __foo; //// [index.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; __export(require("./b")); diff --git a/tests/baselines/reference/es6ExportAllInEs5.js b/tests/baselines/reference/es6ExportAllInEs5.js index ee949682f625d..31e2d8bd297fa 100644 --- a/tests/baselines/reference/es6ExportAllInEs5.js +++ b/tests/baselines/reference/es6ExportAllInEs5.js @@ -32,7 +32,18 @@ exports.x = 10; //// [client.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } Object.defineProperty(exports, "__esModule", { value: true }); __export(require("./server")); diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js index 00e5f73f0fdde..6449364894ab6 100644 --- a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js @@ -37,13 +37,13 @@ exports.x = 10; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var server_1 = require("./server"); -exports.c = server_1.c; +Object.defineProperty(exports, "c", { enumerable: true, get: () => server_1.c }); var server_2 = require("./server"); -exports.c2 = server_2.c; +Object.defineProperty(exports, "c2", { enumerable: true, get: () => server_2.c }); var server_3 = require("./server"); -exports.instantiatedModule = server_3.m; +Object.defineProperty(exports, "instantiatedModule", { enumerable: true, get: () => server_3.m }); var server_4 = require("./server"); -exports.x = server_4.x; +Object.defineProperty(exports, "x", { enumerable: true, get: () => server_4.x }); //// [server.d.ts] diff --git a/tests/baselines/reference/es6ExportEqualsInterop.js b/tests/baselines/reference/es6ExportEqualsInterop.js index 13908a29e2d6b..8b147c67a1c98 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.js +++ b/tests/baselines/reference/es6ExportEqualsInterop.js @@ -210,7 +210,18 @@ export * from "class-module"; "use strict"; /// function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; var z2 = require("variable"); diff --git a/tests/baselines/reference/exportStar-amd.js b/tests/baselines/reference/exportStar-amd.js index 7658c470e5574..85b797c104941 100644 --- a/tests/baselines/reference/exportStar-amd.js +++ b/tests/baselines/reference/exportStar-amd.js @@ -58,7 +58,18 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports", "./t1", "./t2", "./t3"], function (require, exports, t1_1, t2_1, t3_1) { "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } Object.defineProperty(exports, "__esModule", { value: true }); __export(t1_1); diff --git a/tests/baselines/reference/exportStar.js b/tests/baselines/reference/exportStar.js index 36818f8ae9b76..0cf156b501019 100644 --- a/tests/baselines/reference/exportStar.js +++ b/tests/baselines/reference/exportStar.js @@ -51,7 +51,18 @@ exports.z = z; //// [t4.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } Object.defineProperty(exports, "__esModule", { value: true }); __export(require("./t1")); diff --git a/tests/baselines/reference/exportStarForValues7.js b/tests/baselines/reference/exportStarForValues7.js index af213d1308028..ae6179411a91c 100644 --- a/tests/baselines/reference/exportStarForValues7.js +++ b/tests/baselines/reference/exportStarForValues7.js @@ -26,7 +26,18 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports", "file2"], function (require, exports, file2_1) { "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; __export(file2_1); diff --git a/tests/baselines/reference/exportStarForValues8.js b/tests/baselines/reference/exportStarForValues8.js index 7a0045c22cb23..265dddf82e27a 100644 --- a/tests/baselines/reference/exportStarForValues8.js +++ b/tests/baselines/reference/exportStarForValues8.js @@ -44,7 +44,18 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports", "file2", "file3"], function (require, exports, file2_1, file3_1) { "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; __export(file2_1); @@ -55,7 +66,18 @@ define(["require", "exports", "file2", "file3"], function (require, exports, fil define(["require", "exports", "file4"], function (require, exports, file4_1) { "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; __export(file4_1); diff --git a/tests/baselines/reference/exportStarForValues9.js b/tests/baselines/reference/exportStarForValues9.js index 8eb92c05e741f..54a7770a7046c 100644 --- a/tests/baselines/reference/exportStarForValues9.js +++ b/tests/baselines/reference/exportStarForValues9.js @@ -24,7 +24,18 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports", "file2"], function (require, exports, file2_1) { "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; __export(file2_1); @@ -34,7 +45,18 @@ define(["require", "exports", "file2"], function (require, exports, file2_1) { define(["require", "exports", "file3"], function (require, exports, file3_1) { "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; __export(file3_1); diff --git a/tests/baselines/reference/exportStarFromEmptyModule.js b/tests/baselines/reference/exportStarFromEmptyModule.js index be7de642a6a6e..543e8cc216589 100644 --- a/tests/baselines/reference/exportStarFromEmptyModule.js +++ b/tests/baselines/reference/exportStarFromEmptyModule.js @@ -36,7 +36,18 @@ exports.A = A; //// [exportStarFromEmptyModule_module3.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } Object.defineProperty(exports, "__esModule", { value: true }); __export(require("./exportStarFromEmptyModule_module2")); diff --git a/tests/baselines/reference/exportsAndImports1-amd.js b/tests/baselines/reference/exportsAndImports1-amd.js index f93abb906d2a7..4aa365a185691 100644 --- a/tests/baselines/reference/exportsAndImports1-amd.js +++ b/tests/baselines/reference/exportsAndImports1-amd.js @@ -65,21 +65,21 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports", "./t1"], function (require, exports, t1_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - exports.v = t1_1.v; - exports.f = t1_1.f; - exports.C = t1_1.C; - exports.E = t1_1.E; - exports.M = t1_1.M; - exports.a = t1_1.a; + Object.defineProperty(exports, "v", { enumerable: true, get: () => t1_1.v }); + Object.defineProperty(exports, "f", { enumerable: true, get: () => t1_1.f }); + Object.defineProperty(exports, "C", { enumerable: true, get: () => t1_1.C }); + Object.defineProperty(exports, "E", { enumerable: true, get: () => t1_1.E }); + Object.defineProperty(exports, "M", { enumerable: true, get: () => t1_1.M }); + Object.defineProperty(exports, "a", { enumerable: true, get: () => t1_1.a }); }); //// [t3.js] define(["require", "exports", "./t1"], function (require, exports, t1_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - exports.v = t1_1.v; - exports.f = t1_1.f; - exports.C = t1_1.C; - exports.E = t1_1.E; - exports.M = t1_1.M; - exports.a = t1_1.a; + Object.defineProperty(exports, "v", { enumerable: true, get: () => t1_1.v }); + Object.defineProperty(exports, "f", { enumerable: true, get: () => t1_1.f }); + Object.defineProperty(exports, "C", { enumerable: true, get: () => t1_1.C }); + Object.defineProperty(exports, "E", { enumerable: true, get: () => t1_1.E }); + Object.defineProperty(exports, "M", { enumerable: true, get: () => t1_1.M }); + Object.defineProperty(exports, "a", { enumerable: true, get: () => t1_1.a }); }); diff --git a/tests/baselines/reference/exportsAndImports1-es6.js b/tests/baselines/reference/exportsAndImports1-es6.js index 71e8de6f9faa0..2fb1fa197d7d6 100644 --- a/tests/baselines/reference/exportsAndImports1-es6.js +++ b/tests/baselines/reference/exportsAndImports1-es6.js @@ -60,19 +60,19 @@ exports.a = a; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var t1_1 = require("./t1"); -exports.v = t1_1.v; -exports.f = t1_1.f; -exports.C = t1_1.C; -exports.E = t1_1.E; -exports.M = t1_1.M; -exports.a = t1_1.a; +Object.defineProperty(exports, "v", { enumerable: true, get: () => t1_1.v }); +Object.defineProperty(exports, "f", { enumerable: true, get: () => t1_1.f }); +Object.defineProperty(exports, "C", { enumerable: true, get: () => t1_1.C }); +Object.defineProperty(exports, "E", { enumerable: true, get: () => t1_1.E }); +Object.defineProperty(exports, "M", { enumerable: true, get: () => t1_1.M }); +Object.defineProperty(exports, "a", { enumerable: true, get: () => t1_1.a }); //// [t3.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const t1_1 = require("./t1"); -exports.v = t1_1.v; -exports.f = t1_1.f; -exports.C = t1_1.C; -exports.E = t1_1.E; -exports.M = t1_1.M; -exports.a = t1_1.a; +Object.defineProperty(exports, "v", { enumerable: true, get: () => t1_1.v }); +Object.defineProperty(exports, "f", { enumerable: true, get: () => t1_1.f }); +Object.defineProperty(exports, "C", { enumerable: true, get: () => t1_1.C }); +Object.defineProperty(exports, "E", { enumerable: true, get: () => t1_1.E }); +Object.defineProperty(exports, "M", { enumerable: true, get: () => t1_1.M }); +Object.defineProperty(exports, "a", { enumerable: true, get: () => t1_1.a }); diff --git a/tests/baselines/reference/exportsAndImports2-amd.js b/tests/baselines/reference/exportsAndImports2-amd.js index 04685dcaa332a..17c51eced3671 100644 --- a/tests/baselines/reference/exportsAndImports2-amd.js +++ b/tests/baselines/reference/exportsAndImports2-amd.js @@ -23,13 +23,13 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports", "./t1"], function (require, exports, t1_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - exports.y = t1_1.x; - exports.x = t1_1.y; + Object.defineProperty(exports, "y", { enumerable: true, get: () => t1_1.x }); + Object.defineProperty(exports, "x", { enumerable: true, get: () => t1_1.y }); }); //// [t3.js] define(["require", "exports", "./t1"], function (require, exports, t1_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - exports.y = t1_1.x; - exports.x = t1_1.y; + Object.defineProperty(exports, "y", { enumerable: true, get: () => t1_1.x }); + Object.defineProperty(exports, "x", { enumerable: true, get: () => t1_1.y }); }); diff --git a/tests/baselines/reference/exportsAndImports2-es6.js b/tests/baselines/reference/exportsAndImports2-es6.js index 2a57a43f1a5ff..fed2b3712cdfa 100644 --- a/tests/baselines/reference/exportsAndImports2-es6.js +++ b/tests/baselines/reference/exportsAndImports2-es6.js @@ -21,11 +21,11 @@ exports.y = "y"; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var t1_1 = require("./t1"); -exports.y = t1_1.x; -exports.x = t1_1.y; +Object.defineProperty(exports, "y", { enumerable: true, get: () => t1_1.x }); +Object.defineProperty(exports, "x", { enumerable: true, get: () => t1_1.y }); //// [t3.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const t1_1 = require("./t1"); -exports.y = t1_1.x; -exports.x = t1_1.y; +Object.defineProperty(exports, "y", { enumerable: true, get: () => t1_1.x }); +Object.defineProperty(exports, "x", { enumerable: true, get: () => t1_1.y }); diff --git a/tests/baselines/reference/exportsAndImports3-amd.js b/tests/baselines/reference/exportsAndImports3-amd.js index 6ee327f979d8a..a31a8bd50300b 100644 --- a/tests/baselines/reference/exportsAndImports3-amd.js +++ b/tests/baselines/reference/exportsAndImports3-amd.js @@ -67,21 +67,21 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports", "./t1"], function (require, exports, t1_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - exports.v = t1_1.v1; - exports.f = t1_1.f1; - exports.C = t1_1.C1; - exports.E = t1_1.E1; - exports.M = t1_1.M1; - exports.a = t1_1.a1; + Object.defineProperty(exports, "v", { enumerable: true, get: () => t1_1.v1 }); + Object.defineProperty(exports, "f", { enumerable: true, get: () => t1_1.f1 }); + Object.defineProperty(exports, "C", { enumerable: true, get: () => t1_1.C1 }); + Object.defineProperty(exports, "E", { enumerable: true, get: () => t1_1.E1 }); + Object.defineProperty(exports, "M", { enumerable: true, get: () => t1_1.M1 }); + Object.defineProperty(exports, "a", { enumerable: true, get: () => t1_1.a1 }); }); //// [t3.js] define(["require", "exports", "./t1"], function (require, exports, t1_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - exports.v = t1_1.v1; - exports.f = t1_1.f1; - exports.C = t1_1.C1; - exports.E = t1_1.E1; - exports.M = t1_1.M1; - exports.a = t1_1.a1; + Object.defineProperty(exports, "v", { enumerable: true, get: () => t1_1.v1 }); + Object.defineProperty(exports, "f", { enumerable: true, get: () => t1_1.f1 }); + Object.defineProperty(exports, "C", { enumerable: true, get: () => t1_1.C1 }); + Object.defineProperty(exports, "E", { enumerable: true, get: () => t1_1.E1 }); + Object.defineProperty(exports, "M", { enumerable: true, get: () => t1_1.M1 }); + Object.defineProperty(exports, "a", { enumerable: true, get: () => t1_1.a1 }); }); diff --git a/tests/baselines/reference/exportsAndImports3-es6.js b/tests/baselines/reference/exportsAndImports3-es6.js index 541223717773e..640f00ab7b9de 100644 --- a/tests/baselines/reference/exportsAndImports3-es6.js +++ b/tests/baselines/reference/exportsAndImports3-es6.js @@ -62,19 +62,19 @@ exports.a1 = exports.a; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var t1_1 = require("./t1"); -exports.v = t1_1.v1; -exports.f = t1_1.f1; -exports.C = t1_1.C1; -exports.E = t1_1.E1; -exports.M = t1_1.M1; -exports.a = t1_1.a1; +Object.defineProperty(exports, "v", { enumerable: true, get: () => t1_1.v1 }); +Object.defineProperty(exports, "f", { enumerable: true, get: () => t1_1.f1 }); +Object.defineProperty(exports, "C", { enumerable: true, get: () => t1_1.C1 }); +Object.defineProperty(exports, "E", { enumerable: true, get: () => t1_1.E1 }); +Object.defineProperty(exports, "M", { enumerable: true, get: () => t1_1.M1 }); +Object.defineProperty(exports, "a", { enumerable: true, get: () => t1_1.a1 }); //// [t3.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const t1_1 = require("./t1"); -exports.v = t1_1.v1; -exports.f = t1_1.f1; -exports.C = t1_1.C1; -exports.E = t1_1.E1; -exports.M = t1_1.M1; -exports.a = t1_1.a1; +Object.defineProperty(exports, "v", { enumerable: true, get: () => t1_1.v1 }); +Object.defineProperty(exports, "f", { enumerable: true, get: () => t1_1.f1 }); +Object.defineProperty(exports, "C", { enumerable: true, get: () => t1_1.C1 }); +Object.defineProperty(exports, "E", { enumerable: true, get: () => t1_1.E1 }); +Object.defineProperty(exports, "M", { enumerable: true, get: () => t1_1.M1 }); +Object.defineProperty(exports, "a", { enumerable: true, get: () => t1_1.a1 }); diff --git a/tests/baselines/reference/exportsAndImports4-amd.js b/tests/baselines/reference/exportsAndImports4-amd.js index 52a41a0a4512b..d12b1e12493ed 100644 --- a/tests/baselines/reference/exportsAndImports4-amd.js +++ b/tests/baselines/reference/exportsAndImports4-amd.js @@ -54,7 +54,7 @@ define(["require", "exports", "./t1", "./t1", "./t1", "./t1", "./t1", "./t1"], f t1_1.default; exports.c = c; c.default; - exports.d = t1_2.default; + Object.defineProperty(exports, "d", { enumerable: true, get: () => t1_2.default }); t1_2.default; var e2 = t1_3; exports.e1 = t1_3.default; @@ -62,7 +62,7 @@ define(["require", "exports", "./t1", "./t1", "./t1", "./t1", "./t1", "./t1"], f t1_3.default; e2.default; exports.f1 = t1_4.default; - exports.f2 = t1_4.default; + Object.defineProperty(exports, "f2", { enumerable: true, get: () => t1_4.default }); t1_4.default; t1_4.default; }); diff --git a/tests/baselines/reference/exportsAndImports4-es6.js b/tests/baselines/reference/exportsAndImports4-es6.js index ee35571942f6c..9106af8ffa734 100644 --- a/tests/baselines/reference/exportsAndImports4-es6.js +++ b/tests/baselines/reference/exportsAndImports4-es6.js @@ -55,7 +55,7 @@ const c = require("./t1"); exports.c = c; c.default; const t1_2 = require("./t1"); -exports.d = t1_2.default; +Object.defineProperty(exports, "d", { enumerable: true, get: () => t1_2.default }); t1_2.default; const t1_3 = require("./t1"), e2 = t1_3; exports.e1 = t1_3.default; @@ -64,6 +64,6 @@ t1_3.default; e2.default; const t1_4 = require("./t1"); exports.f1 = t1_4.default; -exports.f2 = t1_4.default; +Object.defineProperty(exports, "f2", { enumerable: true, get: () => t1_4.default }); t1_4.default; t1_4.default; diff --git a/tests/baselines/reference/exportsAndImports4.js b/tests/baselines/reference/exportsAndImports4.js index efb93eeebf62e..07c38506733dd 100644 --- a/tests/baselines/reference/exportsAndImports4.js +++ b/tests/baselines/reference/exportsAndImports4.js @@ -55,7 +55,7 @@ var c = require("./t1"); exports.c = c; c.default; var t1_2 = require("./t1"); -exports.d = t1_2.default; +Object.defineProperty(exports, "d", { enumerable: true, get: () => t1_2.default }); t1_2.default; var t1_3 = require("./t1"), e2 = t1_3; exports.e1 = t1_3.default; @@ -64,6 +64,6 @@ t1_3.default; e2.default; var t1_4 = require("./t1"); exports.f1 = t1_4.default; -exports.f2 = t1_4.default; +Object.defineProperty(exports, "f2", { enumerable: true, get: () => t1_4.default }); t1_4.default; t1_4.default; diff --git a/tests/baselines/reference/inlineJsxFactoryDeclarations.js b/tests/baselines/reference/inlineJsxFactoryDeclarations.js index 958c43af83f68..4e4ad9c384c09 100644 --- a/tests/baselines/reference/inlineJsxFactoryDeclarations.js +++ b/tests/baselines/reference/inlineJsxFactoryDeclarations.js @@ -63,7 +63,18 @@ exports.prerendered3 = renderer_1["default"].createElement("h", null); //// [index.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; /** @jsx dom */ diff --git a/tests/baselines/reference/isolatedModulesImportExportElision.js b/tests/baselines/reference/isolatedModulesImportExportElision.js index 1122fc12d0637..a1837ad39d6cf 100644 --- a/tests/baselines/reference/isolatedModulesImportExportElision.js +++ b/tests/baselines/reference/isolatedModulesImportExportElision.js @@ -41,5 +41,5 @@ var C = /** @class */ (function (_super) { var x = new module_1.c(); var y = ns.value; var module_3 = require("module"); -exports.c1 = module_3.c1; +Object.defineProperty(exports, "c1", { enumerable: true, get: () => module_3.c1 }); exports.z = x; diff --git a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js index c4d451ba9f9d3..0aa04849c6f0b 100644 --- a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js +++ b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js @@ -17,14 +17,36 @@ exports.foo = 42; //// [b.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; __export(require("./c")); //// [a.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; __export(require("./b")); diff --git a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js index d1f6dc7abc7cf..3731436506313 100644 --- a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js +++ b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js @@ -30,7 +30,18 @@ exports.Animals = c_1.Animals; //// [a.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; __export(require("./b")); diff --git a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js index 8cf2fab6fb4b5..3d2e3ad162761 100644 --- a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js +++ b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js @@ -42,7 +42,18 @@ exports.BindingKey = BindingKey; //// [index.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) + Object.create + ? Object.defineProperty(exports, p, { + enumerable: true, + get: function() { + return m[p]; + } + }) + : (exports[p] = m[p]); + } } exports.__esModule = true; __export(require("./src/bindingkey")); diff --git a/tests/baselines/reference/transformApi/transformsCorrectly.transformAddCommentToImport.js b/tests/baselines/reference/transformApi/transformsCorrectly.transformAddCommentToImport.js index de19b854d20a7..5b8c52928d616 100644 --- a/tests/baselines/reference/transformApi/transformsCorrectly.transformAddCommentToImport.js +++ b/tests/baselines/reference/transformApi/transformsCorrectly.transformAddCommentToImport.js @@ -1,16 +1,24 @@ "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + for (var p in m) b(p); + function b(p) { + if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { + enumerable: true, + get: function () { + return m[p]; + } + }); + } } Object.defineProperty(exports, "__esModule", { value: true }); /*comment*/ var somewhere_1 = require("somewhere"); -exports.Value = somewhere_1.Value; +Object.defineProperty(exports, "Value", { enumerable: true, get: () => somewhere_1.Value }); /*comment*/ var somewhere_2 = require("somewhere"); /*comment*/ -exports.X = somewhere_2.X; +Object.defineProperty(exports, "X", { enumerable: true, get: () => somewhere_2.X }); /*comment*/ -exports.Y = somewhere_2.Y; +Object.defineProperty(exports, "Y", { enumerable: true, get: () => somewhere_2.Y }); /*comment*/ __export(require("somewhere")); diff --git a/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module-with-isolatedModules.js b/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module-with-isolatedModules.js index 568116485a416..3bf821165ada8 100644 --- a/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module-with-isolatedModules.js +++ b/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module-with-isolatedModules.js @@ -61,7 +61,7 @@ export { default as bar } from './bar'; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var bar_1 = require("./bar"); -exports.bar = bar_1.default; +Object.defineProperty(exports, "bar", { enumerable: true, get: () => bar_1.default }); //// [/src/obj/tsconfig.tsbuildinfo] diff --git a/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module.js b/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module.js index a04669bd97159..29d385cb96d45 100644 --- a/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module.js +++ b/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module.js @@ -61,7 +61,7 @@ export { default as bar } from './bar'; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var bar_1 = require("./bar"); -exports.bar = bar_1.default; +Object.defineProperty(exports, "bar", { enumerable: true, get: () => bar_1.default }); //// [/src/obj/tsconfig.tsbuildinfo]