Skip to content

Commit 7bc08e1

Browse files
authored
Merge pull request webpack#4816 from webpack/bugfix/hoist-immutable-export
hoist exports
2 parents bf3652b + a952bb9 commit 7bc08e1

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

lib/dependencies/HarmonyCompatibilityDependency.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate
2222
if(usedExports && !Array.isArray(usedExports)) {
2323
const exportName = dep.originModule.exportsArgument || "exports";
2424
const content = `Object.defineProperty(${exportName}, \"__esModule\", { value: true });\n`;
25-
source.insert(-1, content);
25+
source.insert(-10, content);
2626
}
2727
}
2828
};

lib/dependencies/HarmonyExportDependencyParserPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
4545
} else {
4646
const immutable = statement.declaration && isImmutableStatement(statement.declaration);
4747
const hoisted = statement.declaration && isHoistedStatement(statement.declaration);
48-
dep = new HarmonyExportSpecifierDependency(parser.state.module, id, name, !immutable || hoisted ? -0.5 : (statement.range[1] + 0.5), immutable);
48+
dep = new HarmonyExportSpecifierDependency(parser.state.module, id, name, !immutable || hoisted ? -2 : (statement.range[1] + 0.5), immutable);
4949
}
5050
dep.loc = Object.create(statement.loc);
5151
dep.loc.index = idx;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { foo, foo2 } from "./foo";
2+
3+
export default {
4+
foo: foo,
5+
foo2: foo2
6+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {bar} from "./bar";
2+
3+
export function foo() {
4+
return "ok";
5+
}
6+
7+
function foo2() {
8+
return "ok";
9+
}
10+
export { foo2 }
11+
12+
export { default } from "./bar";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
it("should hoist exports", function() {
4+
var result = require("./foo").default;
5+
(typeof result.foo).should.have.eql("function");
6+
(typeof result.foo2).should.have.eql("function");
7+
result.foo().should.be.eql("ok");
8+
result.foo2().should.be.eql("ok");
9+
});

0 commit comments

Comments
 (0)