Skip to content

Commit

Permalink
Merge pull request #8086 from webpack/bugfix/comments-concat-export-d…
Browse files Browse the repository at this point in the history
…efault

fixes #8085
  • Loading branch information
sokra committed Sep 25, 2018
2 parents 54e30e0 + aab3afb commit 79ea087
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/optimize/ConcatenatedModule.js
Expand Up @@ -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
);
}
}

Expand Down
15 changes: 15 additions & 0 deletions 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;
});
@@ -0,0 +1,9 @@
let value = 42;

const inc = () => {
value++;
};

export default /*#__PURE__*/inc();

export { value };
@@ -0,0 +1,9 @@
let value = 42;

const inc = () => {
value++;
};

export default (/*#__PURE__*/inc());

export { value };
@@ -0,0 +1,9 @@
let value = 42;

const inc = () => {
value++;
};

export default /*#__PURE__*/(inc());

export { value };
15 changes: 15 additions & 0 deletions 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 };
@@ -0,0 +1,7 @@
module.exports = {
mode: "production",
optimization: {
minimize: true,
concatenateModules: true
}
};

0 comments on commit 79ea087

Please sign in to comment.