From 72417f4b0c64cbbb44761e3519a4d175f4d99efb Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 24 Sep 2020 17:17:34 +0200 Subject: [PATCH] Fix SystemJS default variable conflict (#3796) --- src/Chunk.ts | 4 +--- .../_config.js | 7 +++++++ .../_expected/amd/main.js | 7 +++++++ .../_expected/amd/other.js | 9 +++++++++ .../_expected/cjs/main.js | 7 +++++++ .../_expected/cjs/other.js | 7 +++++++ .../_expected/es/main.js | 5 +++++ .../_expected/es/other.js | 3 +++ .../_expected/system/main.js | 14 ++++++++++++++ .../_expected/system/other.js | 10 ++++++++++ .../main.js | 3 +++ .../other.js | 1 + .../_expected/system/main.js | 6 +++--- .../_expected/system/main.js | 6 +++--- test/form/samples/export-default-global/dynamic.js | 0 15 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 test/chunking-form/samples/deconflict-system-default-export-variable/_config.js create mode 100644 test/chunking-form/samples/deconflict-system-default-export-variable/_expected/amd/main.js create mode 100644 test/chunking-form/samples/deconflict-system-default-export-variable/_expected/amd/other.js create mode 100644 test/chunking-form/samples/deconflict-system-default-export-variable/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/deconflict-system-default-export-variable/_expected/cjs/other.js create mode 100644 test/chunking-form/samples/deconflict-system-default-export-variable/_expected/es/main.js create mode 100644 test/chunking-form/samples/deconflict-system-default-export-variable/_expected/es/other.js create mode 100644 test/chunking-form/samples/deconflict-system-default-export-variable/_expected/system/main.js create mode 100644 test/chunking-form/samples/deconflict-system-default-export-variable/_expected/system/other.js create mode 100644 test/chunking-form/samples/deconflict-system-default-export-variable/main.js create mode 100644 test/chunking-form/samples/deconflict-system-default-export-variable/other.js delete mode 100644 test/form/samples/export-default-global/dynamic.js diff --git a/src/Chunk.ts b/src/Chunk.ts index cbaeaf76529..72a2a8a0b5c 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -994,7 +994,6 @@ export default class Chunk { private getDependenciesToBeDeconflicted( addNonNamespacesAndInteropHelpers: boolean, - addInternalDependencies: boolean, addDependenciesWithoutBindings: boolean, interop: GetInterop ): DependenciesToBeDeconflicted { @@ -1017,7 +1016,7 @@ export default class Chunk { } } } - } else if (addInternalDependencies) { + } else { const chunk = this.chunkByModule.get(module)!; if (chunk !== this) { dependencies.add(chunk); @@ -1259,7 +1258,6 @@ export default class Chunk { this.orderedModules, this.getDependenciesToBeDeconflicted( format !== 'es' && format !== 'system', - format !== 'system', format === 'amd' || format === 'umd' || format === 'iife', interop ), diff --git a/test/chunking-form/samples/deconflict-system-default-export-variable/_config.js b/test/chunking-form/samples/deconflict-system-default-export-variable/_config.js new file mode 100644 index 00000000000..f0300a3c472 --- /dev/null +++ b/test/chunking-form/samples/deconflict-system-default-export-variable/_config.js @@ -0,0 +1,7 @@ +module.exports = { + description: 'deconflicts SystemJS default export variable with namespace imports', + options: { + external: 'external', + output: { preserveModules: true } + } +}; diff --git a/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/amd/main.js b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/amd/main.js new file mode 100644 index 00000000000..b32a1761b50 --- /dev/null +++ b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/amd/main.js @@ -0,0 +1,7 @@ +define(['./other'], function (other) { 'use strict'; + + var main = other + "extended"; + + return main; + +}); diff --git a/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/amd/other.js b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/amd/other.js new file mode 100644 index 00000000000..a32f525eb6d --- /dev/null +++ b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/amd/other.js @@ -0,0 +1,9 @@ +define(['exports'], function (exports) { 'use strict'; + + const foo = 'bar'; + + exports.foo = foo; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/cjs/main.js b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/cjs/main.js new file mode 100644 index 00000000000..51fb736492a --- /dev/null +++ b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/cjs/main.js @@ -0,0 +1,7 @@ +'use strict'; + +var other = require('./other.js'); + +var main = other + "extended"; + +module.exports = main; diff --git a/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/cjs/other.js b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/cjs/other.js new file mode 100644 index 00000000000..f2628893cb0 --- /dev/null +++ b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/cjs/other.js @@ -0,0 +1,7 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +const foo = 'bar'; + +exports.foo = foo; diff --git a/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/es/main.js b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/es/main.js new file mode 100644 index 00000000000..bceb98a95d2 --- /dev/null +++ b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/es/main.js @@ -0,0 +1,5 @@ +import * as other from './other.js'; + +var main = other + "extended"; + +export default main; diff --git a/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/es/other.js b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/es/other.js new file mode 100644 index 00000000000..978472167c0 --- /dev/null +++ b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/es/other.js @@ -0,0 +1,3 @@ +const foo = 'bar'; + +export { foo }; diff --git a/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/system/main.js b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/system/main.js new file mode 100644 index 00000000000..b5317f1c0a6 --- /dev/null +++ b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/system/main.js @@ -0,0 +1,14 @@ +System.register(['./other.js'], function (exports) { + 'use strict'; + var other; + return { + setters: [function (module) { + other = module; + }], + execute: function () { + + var main = exports('default', other + "extended"); + + } + }; +}); diff --git a/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/system/other.js b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/system/other.js new file mode 100644 index 00000000000..bd30d4938ef --- /dev/null +++ b/test/chunking-form/samples/deconflict-system-default-export-variable/_expected/system/other.js @@ -0,0 +1,10 @@ +System.register([], function (exports) { + 'use strict'; + return { + execute: function () { + + const foo = exports('foo', 'bar'); + + } + }; +}); diff --git a/test/chunking-form/samples/deconflict-system-default-export-variable/main.js b/test/chunking-form/samples/deconflict-system-default-export-variable/main.js new file mode 100644 index 00000000000..b47741c0828 --- /dev/null +++ b/test/chunking-form/samples/deconflict-system-default-export-variable/main.js @@ -0,0 +1,3 @@ +import * as main from './other.js'; + +export default main + "extended"; \ No newline at end of file diff --git a/test/chunking-form/samples/deconflict-system-default-export-variable/other.js b/test/chunking-form/samples/deconflict-system-default-export-variable/other.js new file mode 100644 index 00000000000..7212fb6787a --- /dev/null +++ b/test/chunking-form/samples/deconflict-system-default-export-variable/other.js @@ -0,0 +1 @@ +export const foo = 'bar' \ No newline at end of file diff --git a/test/chunking-form/samples/deprecated/preserve-modules-dynamic-namespace/_expected/system/main.js b/test/chunking-form/samples/deprecated/preserve-modules-dynamic-namespace/_expected/system/main.js index 7d19155def8..8ee4b05a8af 100644 --- a/test/chunking-form/samples/deprecated/preserve-modules-dynamic-namespace/_expected/system/main.js +++ b/test/chunking-form/samples/deprecated/preserve-modules-dynamic-namespace/_expected/system/main.js @@ -1,13 +1,13 @@ System.register(['./m1.js'], function () { 'use strict'; - var ms; + var m1; return { setters: [function (module) { - ms = module; + m1 = module; }], execute: function () { - console.log(ms); + console.log(m1); } }; diff --git a/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/system/main.js b/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/system/main.js index 7d19155def8..8ee4b05a8af 100644 --- a/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/system/main.js +++ b/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/system/main.js @@ -1,13 +1,13 @@ System.register(['./m1.js'], function () { 'use strict'; - var ms; + var m1; return { setters: [function (module) { - ms = module; + m1 = module; }], execute: function () { - console.log(ms); + console.log(m1); } }; diff --git a/test/form/samples/export-default-global/dynamic.js b/test/form/samples/export-default-global/dynamic.js deleted file mode 100644 index e69de29bb2d..00000000000