Skip to content

Commit 29c1fd2

Browse files
sokraTheLarkInn
authored andcommitted
Test/library with external (webpack#3753)
* fixes position of __esModule flag (should be on top) * add testcase for library with external * updated stats test cases
1 parent 80e177a commit 29c1fd2

9 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎lib/dependencies/HarmonyExportDependencyParserPlugin.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ module.exports = class HarmonyExportDependencyParserPlugin {
2626
apply(parser) {
2727
parser.plugin("export", statement => {
2828
const dep = new HarmonyExportHeaderDependency(statement.declaration && statement.declaration.range, statement.range);
29+
makeHarmonyModule(parser.state.module, statement.loc);
2930
dep.loc = statement.loc;
3031
parser.state.current.addDependency(dep);
31-
makeHarmonyModule(parser.state.module, statement.loc);
3232
return true;
3333
});
3434
parser.plugin("export import", (statement, source) => {
3535
const dep = new HarmonyImportDependency(source, HarmonyModulesHelpers.getNewModuleVar(parser.state, source), statement.range);
36+
makeHarmonyModule(parser.state.module, statement.loc);
3637
dep.loc = statement.loc;
3738
parser.state.current.addDependency(dep);
3839
parser.state.lastHarmoryImport = dep;
39-
makeHarmonyModule(parser.state.module, statement.loc);
4040
return true;
4141
});
4242
parser.plugin("export expression", (statement, expr) => {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export var a = "a";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from "./a";
2+
export default "default-value";
3+
export var b = "b";
4+
export { default as external } from "external";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.noTests = true;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
output: {
3+
libraryTarget: "commonjs2"
4+
},
5+
externals: ["external"]
6+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import d from "library";
2+
import { a, b, external } from "library";
3+
4+
it("should be able to import hamorny exports from library", function() {
5+
d.should.be.eql("default-value");
6+
a.should.be.eql("a");
7+
b.should.be.eql("b");
8+
external.should.be.eql(["external"]);
9+
external.should.be.equal(require("external"));
10+
});

‎test/configCases/library/3-use-library-with-external/node_modules/external.js‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var path = require("path");
2+
module.exports = {
3+
resolve: {
4+
alias: {
5+
library: path.resolve(__dirname, "../../../js/config/library/2-create-library-with-external/bundle0.js"),
6+
external: path.resolve(__dirname, "node_modules/external.js")
7+
}
8+
}
9+
};

‎test/statsCases/tree-shaking/expected.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Hash: e94a2c6bee98efb02ae8
1+
Hash: 264630d9963a6039f9e0
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
bundle.js 7.16 kB 0 [emitted] main

0 commit comments

Comments
 (0)