Skip to content

Commit

Permalink
set compatiblity flag correctly even after incremental build
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Aug 16, 2017
1 parent 990563f commit c5deb59
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/optimize/ConcatenatedModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ class ConcatenatedModule extends Module {
internalNames: new Map(),
exportMap: exportMap,
reexportMap: reexportMap,
needCompatibilityFlag: false,
hasNamespaceObject: false,
namespaceObjectSource: null
};
Expand Down Expand Up @@ -576,7 +575,8 @@ class ConcatenatedModule extends Module {
const result = new ConcatSource();

// add harmony compatibility flag (must be first because of possible circular dependencies)
if(moduleToInfoMap.get(this.rootModule).needCompatibilityFlag) {
const usedExports = this.rootModule.usedExports;
if(usedExports === true) {
result.add(`Object.defineProperty(${this.exportsArgument || "exports"}, "__esModule", { value: true });\n`);
}

Expand Down Expand Up @@ -807,9 +807,7 @@ class HarmonyCompatibilityDependencyConcatenatedTemplate {
}

apply(dep, source, outputOptions, requestShortener, dependencyTemplates) {
if(dep.originModule === this.rootModule) {
this.modulesMap.get(this.rootModule).needCompatibilityFlag = true;
}
// do nothing
}
}

Expand Down
1 change: 1 addition & 0 deletions test/hotCases/concat/reload-compat-flag/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 1;
17 changes: 17 additions & 0 deletions test/hotCases/concat/reload-compat-flag/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var x = require("./module");

it("should allow to hot replace modules in a ConcatenatedModule", function(done) {
x.should.be.eql({
default: "ok1",
__esModule: true
});
module.hot.accept("./module", function() {
x = require("./module");
x.should.be.eql({
default: "ok2",
__esModule: true
});
done();
});
NEXT(require("../../update")(done));
});
7 changes: 7 additions & 0 deletions test/hotCases/concat/reload-compat-flag/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import "./a";

export default "ok1";
---
import "./a";

export default "ok2";
9 changes: 9 additions & 0 deletions test/hotCases/concat/reload-compat-flag/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

const webpack = require("../../../../");

module.exports = {
plugins: [
new webpack.optimize.ModuleConcatenationPlugin()
]
};

0 comments on commit c5deb59

Please sign in to comment.