diff --git a/lib/optimize/ConcatenatedModule.js b/lib/optimize/ConcatenatedModule.js index 52d33e6f35b..aa244a2f550 100644 --- a/lib/optimize/ConcatenatedModule.js +++ b/lib/optimize/ConcatenatedModule.js @@ -1364,12 +1364,20 @@ class HarmonyExportExpressionDependencyConcatenatedTemplate { } if (dep.range) { - source.replace(dep.rangeStatement[0], dep.range[0] - 1, content + "("); + source.replace( + dep.rangeStatement[0], + dep.range[0] - 1, + content + "(" + dep.prefix + ); source.replace(dep.range[1], dep.rangeStatement[1] - 1, ");"); return; } - source.replace(dep.rangeStatement[0], dep.rangeStatement[1] - 1, content); + source.replace( + dep.rangeStatement[0], + dep.rangeStatement[1] - 1, + content + dep.prefix + ); } } diff --git a/test/configCases/scope-hoisting/harmony-pure-default/index.js b/test/configCases/scope-hoisting/harmony-pure-default/index.js new file mode 100644 index 00000000000..9aa10c3e9fb --- /dev/null +++ b/test/configCases/scope-hoisting/harmony-pure-default/index.js @@ -0,0 +1,15 @@ +import x1, { value as v1 } from "./module1"; +import x2, { value as v2 } from "./module2"; +import { value as v3 } from "./module3"; +import x4, { value as v4 } from "./module4"; + +it("should not execute exports when annotated with pure comment", () => { + expect(v1).toBe(42); + expect(v2).toBe(42); + expect(v3).toBe(42); + expect(v4).toBe(42); +}); + +var x = /*#__PURE__*/(function() { + return x1 + x2 + x4; +}); diff --git a/test/configCases/scope-hoisting/harmony-pure-default/module1.js b/test/configCases/scope-hoisting/harmony-pure-default/module1.js new file mode 100644 index 00000000000..ff5746bdac4 --- /dev/null +++ b/test/configCases/scope-hoisting/harmony-pure-default/module1.js @@ -0,0 +1,9 @@ +let value = 42; + +const inc = () => { + value++; +}; + +export default /*#__PURE__*/inc(); + +export { value }; diff --git a/test/configCases/scope-hoisting/harmony-pure-default/module2.js b/test/configCases/scope-hoisting/harmony-pure-default/module2.js new file mode 100644 index 00000000000..cf69c28f83d --- /dev/null +++ b/test/configCases/scope-hoisting/harmony-pure-default/module2.js @@ -0,0 +1,9 @@ +let value = 42; + +const inc = () => { + value++; +}; + +export default (/*#__PURE__*/inc()); + +export { value }; diff --git a/test/configCases/scope-hoisting/harmony-pure-default/module3.js b/test/configCases/scope-hoisting/harmony-pure-default/module3.js new file mode 100644 index 00000000000..e7e874cd6d3 --- /dev/null +++ b/test/configCases/scope-hoisting/harmony-pure-default/module3.js @@ -0,0 +1,9 @@ +let value = 42; + +const inc = () => { + value++; +}; + +export default /*#__PURE__*/(inc()); + +export { value }; diff --git a/test/configCases/scope-hoisting/harmony-pure-default/module4.js b/test/configCases/scope-hoisting/harmony-pure-default/module4.js new file mode 100644 index 00000000000..c312ca1772a --- /dev/null +++ b/test/configCases/scope-hoisting/harmony-pure-default/module4.js @@ -0,0 +1,15 @@ +let value = 42; + +const inc = () => { + value++; +}; + +export +// hello +default +// world +/*#__PURE__*/ +inc() +; + +export { value }; diff --git a/test/configCases/scope-hoisting/harmony-pure-default/webpack.config.js b/test/configCases/scope-hoisting/harmony-pure-default/webpack.config.js new file mode 100644 index 00000000000..e963f03420a --- /dev/null +++ b/test/configCases/scope-hoisting/harmony-pure-default/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + mode: "production", + optimization: { + minimize: true, + concatenateModules: true + } +};