Skip to content

Commit 4c81b9a

Browse files
committed
move weak into getReference
1 parent 9ca96a5 commit 4c81b9a

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

lib/Compilation.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -857,17 +857,22 @@ class Compilation extends Tapable {
857857
};
858858

859859
const iteratorDependency = d => {
860-
if(!d.module) {
860+
const ref = d.getReference();
861+
if(!ref) {
862+
return;
863+
}
864+
const refModule = ref.module;
865+
if(!refModule) {
861866
return;
862867
}
863868
if(d.weak) {
864869
return;
865870
}
866-
if(chunk.addModule(d.module)) {
867-
d.module.addChunk(chunk);
871+
if(chunk.addModule(refModule)) {
872+
refModule.addChunk(chunk);
868873
queue.push({
869-
block: d.module,
870-
module: d.module,
874+
block: refModule,
875+
module: refModule,
871876
chunk
872877
});
873878
}

lib/Dependency.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const compareLocations = require("./compareLocations");
88
class Dependency {
99
constructor() {
1010
this.module = null;
11+
this.weak = false;
1112
}
1213

1314
isEqualResource() {
@@ -19,6 +20,7 @@ class Dependency {
1920
if(!this.module) return null;
2021
return {
2122
module: this.module,
23+
weak: this.weak,
2224
importedNames: true, // true: full object, false: only sideeffects/no export, array of strings: the exports with this names
2325
};
2426
}

lib/FlagInitialModulesAsUsedPlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class FlagInitialModulesAsUsedPlugin {
1313
return;
1414
}
1515
chunk.forEachModule((module) => {
16+
module.used = true;
1617
module.usedExports = true;
1718
});
1819
});

test/RequireJsStuffPlugin.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe("RequireJsStuffPlugin", () => {
113113
const addDependencySpy = parserEventContext.state.current.addDependency;
114114
const addedDependency = JSON.stringify(addDependencySpy.getCall(0).args[0]);
115115
addDependencySpy.callCount.should.be.exactly(1);
116-
addedDependency.should.be.exactly('{"module":null,"expression":"undefined","range":10,"loc":5}');
116+
addedDependency.should.be.exactly('{"module":null,"weak":false,"expression":"undefined","range":10,"loc":5}');
117117
});
118118
});
119119
});
@@ -132,7 +132,7 @@ describe("RequireJsStuffPlugin", () => {
132132
const addDependencySpy = parserEventContext.state.current.addDependency;
133133
const addedDependency = JSON.stringify(addDependencySpy.getCall(0).args[0]);
134134
addDependencySpy.callCount.should.be.exactly(1);
135-
addedDependency.should.be.exactly('{"module":null,"expression":"undefined","range":10,"loc":5}');
135+
addedDependency.should.be.exactly('{"module":null,"weak":false,"expression":"undefined","range":10,"loc":5}');
136136
});
137137
});
138138
});
@@ -151,7 +151,7 @@ describe("RequireJsStuffPlugin", () => {
151151
const addDependencySpy = parserEventContext.state.current.addDependency;
152152
const addedDependency = JSON.stringify(addDependencySpy.getCall(0).args[0]);
153153
addDependencySpy.callCount.should.be.exactly(1);
154-
addedDependency.should.be.exactly('{"module":null,"expression":"\\"0.0.0\\"","range":10,"loc":5}');
154+
addedDependency.should.be.exactly('{"module":null,"weak":false,"expression":"\\"0.0.0\\"","range":10,"loc":5}');
155155
});
156156
});
157157
});
@@ -170,7 +170,7 @@ describe("RequireJsStuffPlugin", () => {
170170
const addDependencySpy = parserEventContext.state.current.addDependency;
171171
const addedDependency = JSON.stringify(addDependencySpy.getCall(0).args[0]);
172172
addDependencySpy.callCount.should.be.exactly(1);
173-
addedDependency.should.be.exactly('{"module":null,"expression":"__webpack_require__.oe","range":10,"loc":5}');
173+
addedDependency.should.be.exactly('{"module":null,"weak":false,"expression":"__webpack_require__.oe","range":10,"loc":5}');
174174
});
175175
});
176176
});

0 commit comments

Comments
 (0)