Skip to content

Commit 316d4b9

Browse files
authored
Merge pull request #5084 from timse/remove-duplicate-code
Remove duplicate code
2 parents ab636b0 + ae18552 commit 316d4b9

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

‎lib/optimize/ConcatenatedModule.js‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,29 @@ class ConcatenatedModule extends Module {
143143
this.cacheable = modules.every(m => m.cacheable);
144144
const modulesSet = new Set(modules);
145145
this.reasons = rootModule.reasons.filter(reason => !modulesSet.has(reason.module));
146-
this.dependencies = [].concat.apply([], modules.map(m => m.dependencies.filter(dep => !modulesSet.has(dep.module))));
147146
this.meta = rootModule.meta;
148-
this.dependenciesWarnings = modules.reduce((w, m) => m.dependenciesWarnings.forEach(x => w.push(x)), []);
149-
this.dependenciesErrors = modules.reduce((w, m) => m.dependenciesErrors.forEach(x => w.push(x)), []);
150-
this.warnings = modules.reduce((w, m) => m.warnings.forEach(x => w.push(x)), []);
151-
this.errors = modules.reduce((w, m) => m.errors.forEach(x => w.push(x)), []);
152147
this.moduleArgument = rootModule.moduleArgument;
153148
this.exportsArgument = rootModule.exportsArgument;
154149
this.strict = true;
155-
modules.forEach((m, idx) => {
156-
for(const dep of m.dependencies.filter(dep => !modulesSet.has(dep.module))) {
157-
this.dependencies.push(dep);
158-
}
159-
});
150+
151+
this.dependencies = [];
152+
this.dependenciesWarnings = [];
153+
this.dependenciesErrors = [];
154+
this.warnings = [];
155+
this.errors = [];
156+
for(const m of modules) {
157+
// populate dependencies
158+
m.dependencies.filter(dep => !modulesSet.has(dep.module))
159+
.forEach(d => this.dependencies.push(d));
160+
// populate dep warning
161+
m.dependenciesWarnings.forEach(depWarning => this.dependenciesWarnings.push(depWarning));
162+
// populate dep errors
163+
m.dependenciesErrors.forEach(depError => this.dependenciesErrors.push(depError));
164+
// populate warnings
165+
m.warnings.forEach(warning => this.warnings.push(warning));
166+
// populate errors
167+
m.errors.forEach(error => this.errors.push(error));
168+
}
160169
}
161170

162171
identifier() {

‎test/statsCases/scope-hoisting-multi/expected.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Hash: 731069e082cf620521ced84ccc10b5c4fc7695db
1+
Hash: 731069e082cf620521ce1e4286719458d8076cfc
22
Child
33
Hash: 731069e082cf620521ce
44
Time: Xms
@@ -14,7 +14,7 @@ Child
1414
[9] (webpack)/test/statsCases/scope-hoisting-multi/second.js 177 bytes {4} [built]
1515
[10] (webpack)/test/statsCases/scope-hoisting-multi/lazy_second.js 55 bytes {1} [built]
1616
Child
17-
Hash: d84ccc10b5c4fc7695db
17+
Hash: 1e4286719458d8076cfc
1818
Time: Xms
1919
[0] (webpack)/test/statsCases/scope-hoisting-multi/common_lazy_shared.js 25 bytes {0} {1} {2} [built]
2020
[1] (webpack)/test/statsCases/scope-hoisting-multi/vendor.js 25 bytes {5} [built]

0 commit comments

Comments
 (0)