From 27941d05b640148554dd60516144d04a2488536c Mon Sep 17 00:00:00 2001 From: Michael Rawlings Date: Wed, 25 Sep 2019 08:41:38 -1000 Subject: [PATCH] fix scoping in export* helper --- src/compiler/transformers/module/module.ts | 15 ++++++---- .../reference/ambientShorthand_reExport.js | 15 ++++++---- ...clarationEmitReexportedSymlinkReference.js | 15 ++++++---- ...larationEmitReexportedSymlinkReference2.js | 15 ++++++---- ...larationEmitReexportedSymlinkReference3.js | 15 ++++++---- .../doubleUnderscoreExportStarConflict.js | 15 ++++++---- .../baselines/reference/es6ExportAllInEs5.js | 15 ++++++---- .../reference/es6ExportEqualsInterop.js | 15 ++++++---- tests/baselines/reference/exportStar-amd.js | 15 ++++++---- tests/baselines/reference/exportStar.js | 15 ++++++---- .../reference/exportStarForValues7.js | 15 ++++++---- .../reference/exportStarForValues8.js | 30 +++++++++++-------- .../reference/exportStarForValues9.js | 30 +++++++++++-------- .../reference/exportStarFromEmptyModule.js | 15 ++++++---- .../reference/inlineJsxFactoryDeclarations.js | 15 ++++++---- ...duleSameValueDuplicateExportedBindings1.js | 30 +++++++++++-------- ...duleSameValueDuplicateExportedBindings2.js | 15 ++++++---- .../symbolLinkDeclarationEmitModuleNames.js | 15 ++++++---- ...msCorrectly.transformAddCommentToImport.js | 15 ++++++---- 19 files changed, 198 insertions(+), 132 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 49d72b4a2b15e..79d234e03a0e4 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -1807,12 +1807,15 @@ namespace ts { scoped: true, text: ` function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } }` }; diff --git a/tests/baselines/reference/ambientShorthand_reExport.js b/tests/baselines/reference/ambientShorthand_reExport.js index aed1f10c81cce..94fa992a67b16 100644 --- a/tests/baselines/reference/ambientShorthand_reExport.js +++ b/tests/baselines/reference/ambientShorthand_reExport.js @@ -24,12 +24,15 @@ Object.defineProperty(exports, "x", { enumerable: true, get: () => jquery_1.x }) //// [reExportAll.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; __export(require("jquery")); diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js index 7df9712f85172..a6e3a59de40b4 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js @@ -51,12 +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)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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 b88d7273fe678..efa32f1284b81 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js @@ -54,12 +54,15 @@ exports.ADMIN = pkg2_1.MetadataAccessor.create('1'); //// [index.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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/declarationEmitReexportedSymlinkReference3.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js index ad6502bf48bf4..7b9b8412e9f64 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js @@ -51,12 +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)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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 bf281f94f3441..1d071a6684229 100644 --- a/tests/baselines/reference/doubleUnderscoreExportStarConflict.js +++ b/tests/baselines/reference/doubleUnderscoreExportStarConflict.js @@ -24,12 +24,15 @@ exports.__foo = __foo; //// [index.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; __export(require("./b")); diff --git a/tests/baselines/reference/es6ExportAllInEs5.js b/tests/baselines/reference/es6ExportAllInEs5.js index c1bb72c57cd6f..b8df994dda539 100644 --- a/tests/baselines/reference/es6ExportAllInEs5.js +++ b/tests/baselines/reference/es6ExportAllInEs5.js @@ -32,12 +32,15 @@ exports.x = 10; //// [client.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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("./server")); diff --git a/tests/baselines/reference/es6ExportEqualsInterop.js b/tests/baselines/reference/es6ExportEqualsInterop.js index 1651191298620..f80c961cea1ec 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.js +++ b/tests/baselines/reference/es6ExportEqualsInterop.js @@ -210,12 +210,15 @@ export * from "class-module"; "use strict"; /// function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; var z2 = require("variable"); diff --git a/tests/baselines/reference/exportStar-amd.js b/tests/baselines/reference/exportStar-amd.js index 94bf8f378be18..be9cb59d23524 100644 --- a/tests/baselines/reference/exportStar-amd.js +++ b/tests/baselines/reference/exportStar-amd.js @@ -58,12 +58,15 @@ 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)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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(t1_1); diff --git a/tests/baselines/reference/exportStar.js b/tests/baselines/reference/exportStar.js index aeb9723e99edc..b9dcf17dfb666 100644 --- a/tests/baselines/reference/exportStar.js +++ b/tests/baselines/reference/exportStar.js @@ -51,12 +51,15 @@ exports.z = z; //// [t4.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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("./t1")); diff --git a/tests/baselines/reference/exportStarForValues7.js b/tests/baselines/reference/exportStarForValues7.js index 7e34ee1514574..6500a7c03b743 100644 --- a/tests/baselines/reference/exportStarForValues7.js +++ b/tests/baselines/reference/exportStarForValues7.js @@ -26,12 +26,15 @@ 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)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; __export(file2_1); diff --git a/tests/baselines/reference/exportStarForValues8.js b/tests/baselines/reference/exportStarForValues8.js index b8c09a166b1aa..ad40e4a1c0fd2 100644 --- a/tests/baselines/reference/exportStarForValues8.js +++ b/tests/baselines/reference/exportStarForValues8.js @@ -44,12 +44,15 @@ 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)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; __export(file2_1); @@ -60,12 +63,15 @@ 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)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; __export(file4_1); diff --git a/tests/baselines/reference/exportStarForValues9.js b/tests/baselines/reference/exportStarForValues9.js index 678c12e5c47ad..beef678bbbbfd 100644 --- a/tests/baselines/reference/exportStarForValues9.js +++ b/tests/baselines/reference/exportStarForValues9.js @@ -24,12 +24,15 @@ 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)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; __export(file2_1); @@ -39,12 +42,15 @@ 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)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; __export(file3_1); diff --git a/tests/baselines/reference/exportStarFromEmptyModule.js b/tests/baselines/reference/exportStarFromEmptyModule.js index 2d839e8080643..b6562175ca25c 100644 --- a/tests/baselines/reference/exportStarFromEmptyModule.js +++ b/tests/baselines/reference/exportStarFromEmptyModule.js @@ -36,12 +36,15 @@ exports.A = A; //// [exportStarFromEmptyModule_module3.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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("./exportStarFromEmptyModule_module2")); diff --git a/tests/baselines/reference/inlineJsxFactoryDeclarations.js b/tests/baselines/reference/inlineJsxFactoryDeclarations.js index a67efd74c8d2f..528c70444c809 100644 --- a/tests/baselines/reference/inlineJsxFactoryDeclarations.js +++ b/tests/baselines/reference/inlineJsxFactoryDeclarations.js @@ -63,12 +63,15 @@ exports.prerendered3 = renderer_1["default"].createElement("h", null); //// [index.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; /** @jsx dom */ diff --git a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js index 7b8af14040b06..3ebb8bd59ec36 100644 --- a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js +++ b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js @@ -17,24 +17,30 @@ exports.foo = 42; //// [b.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; __export(require("./c")); //// [a.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; __export(require("./b")); diff --git a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js index 6e135b6817daf..8bc530aa8d9d1 100644 --- a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js +++ b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js @@ -30,12 +30,15 @@ Object.defineProperty(exports, "Animals", { enumerable: true, get: () => c_1.Ani //// [a.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } exports.__esModule = true; __export(require("./b")); diff --git a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js index bb4b203b4253e..4696c589feab5 100644 --- a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js +++ b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js @@ -42,12 +42,15 @@ exports.BindingKey = BindingKey; //// [index.js] "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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]; + } + }); + } } 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 4ce97f24b4943..5b8c52928d616 100644 --- a/tests/baselines/reference/transformApi/transformsCorrectly.transformAddCommentToImport.js +++ b/tests/baselines/reference/transformApi/transformsCorrectly.transformAddCommentToImport.js @@ -1,11 +1,14 @@ "use strict"; function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) Object.defineProperty(exports, p, { - enumerable: true, - get: function () { - return 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*/