Skip to content

Commit

Permalink
fixed webpack#1840
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jan 6, 2016
1 parent 4a9bb29 commit 6bc4585
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
13 changes: 10 additions & 3 deletions lib/dependencies/HarmonyExportDependencyParserPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ module.exports = AbstractPlugin.create({
},
"export declaration": function() {},
"export specifier": function(statement, id, name) {
var immutable = statement.declaration && isImmutableStatement(statement.declaration);
var hoisted = statement.declaration && isHoistedStatement(statement.declaration);
var dep = new HarmonyExportSpecifierDependency(this.state.module, id, name, hoisted ? 0 : (statement.range[1] + 0.5), immutable);
var rename = this.scope.renames["$" + id];
var dep;
if(rename === "imported var") {
var settings = this.state.harmonySpecifier["$" + id];
dep = new HarmonyExportImportedSpecifierDependency(this.state.module, settings[0], settings[1], settings[2], name, statement.range[1]);
} else {
var immutable = statement.declaration && isImmutableStatement(statement.declaration);
var hoisted = statement.declaration && isHoistedStatement(statement.declaration);
dep = new HarmonyExportSpecifierDependency(this.state.module, id, name, hoisted ? 0 : (statement.range[1] + 0.5), immutable);
}
dep.loc = statement.loc;
this.state.current.addDependency(dep);
return true;
Expand Down
8 changes: 5 additions & 3 deletions lib/dependencies/HarmonyExportImportedSpecifierDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ HarmonyExportImportedSpecifierDependency.Template.prototype.apply = function(dep
if(outputOptions.pathinfo) comment = "/*! " + requestShortener.shorten(dep.request) + " */ ";
var content;
if(!used) {
content = "/* unused harmony reexport " + (dep.name || "namespace") + " */;";
content = "/* unused harmony reexport " + (dep.name || "namespace") + " */";
} else if(!active) {
content = "/* inactive harmony reexport " + (dep.name || "namespace") + " */;";
content = "/* inactive harmony reexport " + (dep.name || "namespace") + " */";
} else if(dep.name === "default" && !dep.importDependency.module.meta.harmonyModule) {
content = "/* harmony reexport */ Object.defineProperty(exports, " + JSON.stringify(dep.name) + ", {configurable: false, enumerable: true, get: function() { return " + comment + name + "_default.a; }});";
} else if(dep.name) {
} else if(dep.name && dep.id) {
content = "/* harmony reexport */ Object.defineProperty(exports, " + JSON.stringify(dep.name) + ", {configurable: false, enumerable: true, get: function() { return " + comment + (name + "[" + JSON.stringify(dep.id) + "]") + "; }});";
} else if(dep.name) {
content = "/* harmony reexport */ Object.defineProperty(exports, " + JSON.stringify(dep.name) + ", {configurable: false, enumerable: true, get: function() { return " + comment + name + "; }});";
} else {
var activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule);
content = "/* harmony namespace reexport */ for(var __WEBPACK_IMPORT_KEY__ in " + comment + name + ") ";
Expand Down
4 changes: 2 additions & 2 deletions lib/dependencies/HarmonyExportSpecifierDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ HarmonyExportSpecifierDependency.Template.prototype.apply = function(dep, source
var active = HarmonyModulesHelpers.isActive(dep.originModule, dep);
var content;
if(!used) {
content = "/* unused harmony export " + (dep.name || "namespace") + " */;";
content = "/* unused harmony export " + (dep.name || "namespace") + " */";
} else if(!active) {
content = "/* inactive harmony export " + (dep.name || "namespace") + " */;";
content = "/* inactive harmony export " + (dep.name || "namespace") + " */";
} else if(dep.immutable) {
content = "/* harmony export */ exports[" + JSON.stringify(dep.name) + "] = " + dep.id + ";";
} else {
Expand Down
2 changes: 2 additions & 0 deletions test/cases/parsing/harmony/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ it("should import a whole module", function() {
abc.b.should.be.eql("b");
abc.c.should.be.eql("c");
abc.d.c.should.be.eql("c");
abc.e.should.be.eql("c");
var copy = (function(a) { return a; }(abc));
copy.a.should.be.eql("a");
copy.b.should.be.eql("b");
copy.c.should.be.eql("c");
copy.d.c.should.be.eql("c");
copy.e.should.be.eql("c");
(typeof abc).should.be.eql("object");
});

Expand Down
3 changes: 3 additions & 0 deletions test/cases/parsing/harmony/node_modules/abc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6bc4585

Please sign in to comment.