webpack 4.10.1 → 4.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/AmdMainTemplatePlugin.js +3 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/BasicEvaluatedExpression.js +14 -11
- package/lib/CachePlugin.js +12 -5
- package/lib/Chunk.js +44 -16
- package/lib/ChunkGroup.js +13 -5
- package/lib/Compilation.js +70 -28
- package/lib/Compiler.js +22 -10
- package/lib/ConstPlugin.js +25 -9
- package/lib/ContextModule.js +88 -36
- package/lib/ContextModuleFactory.js +18 -7
- package/lib/ContextReplacementPlugin.js +14 -7
- package/lib/DefinePlugin.js +15 -6
- package/lib/DependenciesBlock.js +3 -1
- package/lib/DependenciesBlockVariable.js +2 -1
- package/lib/DllPlugin.js +4 -2
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/ErrorHelpers.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/FlagDependencyUsagePlugin.js +11 -5
- package/lib/FunctionModuleTemplatePlugin.js +8 -6
- package/lib/HotModuleReplacement.runtime.js +7 -3
- package/lib/HotModuleReplacementPlugin.js +13 -6
- package/lib/JavascriptGenerator.js +2 -1
- package/lib/JavascriptModulesPlugin.js +4 -9
- package/lib/JsonParser.js +2 -1
- package/lib/LibraryTemplatePlugin.js +2 -1
- package/lib/LoaderOptionsPlugin.js +2 -1
- package/lib/MainTemplate.js +2 -1
- package/lib/Module.js +9 -5
- package/lib/ModuleFilenameHelpers.js +20 -8
- package/lib/MultiCompiler.js +19 -7
- package/lib/MultiModule.js +5 -2
- package/lib/NodeStuffPlugin.js +2 -1
- package/lib/NormalModule.js +11 -4
- package/lib/NormalModuleFactory.js +30 -12
- package/lib/OptionsDefaulter.js +7 -3
- package/lib/Parser.js +137 -59
- package/lib/ParserHelpers.js +5 -2
- package/lib/ProgressPlugin.js +2 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +11 -7
- package/lib/RequestShortener.js +13 -6
- package/lib/RuleSet.js +39 -18
- package/lib/RuntimeTemplate.js +21 -10
- package/lib/SourceMapDevToolPlugin.js +4 -3
- package/lib/Stats.js +64 -28
- package/lib/Template.js +4 -2
- package/lib/TemplatedPathPlugin.js +6 -3
- package/lib/UmdMainTemplatePlugin.js +8 -3
- package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
- package/lib/Watching.js +3 -2
- package/lib/WebpackOptionsApply.js +32 -16
- package/lib/WebpackOptionsDefaulter.js +7 -4
- package/lib/WebpackOptionsValidationError.js +48 -19
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +6 -3
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +4 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -3
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -3
- package/lib/dependencies/ImportParserPlugin.js +2 -1
- package/lib/dependencies/LoaderPlugin.js +12 -7
- package/lib/dependencies/LocalModulesHelpers.js +13 -6
- package/lib/dependencies/RequireContextPlugin.js +4 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +8 -4
- package/lib/formatLocation.js +15 -7
- package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
- package/lib/node/NodeMainTemplatePlugin.js +6 -3
- package/lib/node/NodeSourcePlugin.js +9 -5
- package/lib/node/NodeWatchFileSystem.js +29 -12
- package/lib/optimize/AggressiveSplittingPlugin.js +12 -6
- package/lib/optimize/ConcatenatedModule.js +19 -8
- package/lib/optimize/MergeDuplicateChunksPlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +23 -10
- package/lib/optimize/OccurrenceOrderPlugin.js +11 -4
- package/lib/optimize/RemoveParentModulesPlugin.js +17 -7
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +33 -20
- package/lib/util/SortableSet.js +5 -2
- package/lib/util/StackedSetMap.js +12 -5
- package/lib/wasm/WasmMainTemplatePlugin.js +4 -2
- package/lib/wasm/WebAssemblyGenerator.js +7 -0
- package/lib/web/JsonpMainTemplate.runtime.js +2 -1
- package/lib/web/JsonpMainTemplatePlugin.js +2 -1
- package/lib/webpack.js +2 -1
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
- package/package.json +9 -9
package/lib/BannerPlugin.js
CHANGED
@@ -13,7 +13,9 @@ const validateOptions = require("schema-utils");
|
|
13
13
|
const schema = require("../schemas/plugins/BannerPlugin.json");
|
14
14
|
|
15
15
|
const wrapComment = str => {
|
16
|
-
if (!str.includes("\n"))
|
16
|
+
if (!str.includes("\n")) {
|
17
|
+
return Template.toComment(str);
|
18
|
+
}
|
17
19
|
return `/*!\n * ${str
|
18
20
|
.replace(/\*\//g, "* /")
|
19
21
|
.split("\n")
|
@@ -90,20 +90,21 @@ class BasicEvaluatedExpression {
|
|
90
90
|
|
91
91
|
asBool() {
|
92
92
|
if (this.truthy) return true;
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
93
|
+
if (this.falsy) return false;
|
94
|
+
if (this.isBoolean()) return this.bool;
|
95
|
+
if (this.isNull()) return false;
|
96
|
+
if (this.isString()) return this.string !== "";
|
97
|
+
if (this.isNumber()) return this.number !== 0;
|
98
|
+
if (this.isRegExp()) return true;
|
99
|
+
if (this.isArray()) return true;
|
100
|
+
if (this.isConstArray()) return true;
|
101
|
+
if (this.isWrapped()) {
|
102
102
|
return (this.prefix && this.prefix.asBool()) ||
|
103
103
|
(this.postfix && this.postfix.asBool())
|
104
104
|
? true
|
105
105
|
: undefined;
|
106
|
-
|
106
|
+
}
|
107
|
+
if (this.isTemplateString()) {
|
107
108
|
for (const quasi of this.quasis) {
|
108
109
|
if (quasi.asBool()) return true;
|
109
110
|
}
|
@@ -165,7 +166,9 @@ class BasicEvaluatedExpression {
|
|
165
166
|
this.type = TypeConditional;
|
166
167
|
this.options = [];
|
167
168
|
}
|
168
|
-
for (const item of options)
|
169
|
+
for (const item of options) {
|
170
|
+
this.options.push(item);
|
171
|
+
}
|
169
172
|
return this;
|
170
173
|
}
|
171
174
|
|
package/lib/CachePlugin.js
CHANGED
@@ -26,12 +26,17 @@ class CachePlugin {
|
|
26
26
|
(childCompiler, compilerName, compilerIndex) => {
|
27
27
|
if (cache) {
|
28
28
|
let childCache;
|
29
|
-
if (!cache.children)
|
30
|
-
|
29
|
+
if (!cache.children) {
|
30
|
+
cache.children = {};
|
31
|
+
}
|
32
|
+
if (!cache.children[compilerName]) {
|
31
33
|
cache.children[compilerName] = [];
|
32
|
-
|
34
|
+
}
|
35
|
+
if (cache.children[compilerName][compilerIndex]) {
|
33
36
|
childCache = cache.children[compilerName][compilerIndex];
|
34
|
-
else
|
37
|
+
} else {
|
38
|
+
cache.children[compilerName].push((childCache = {}));
|
39
|
+
}
|
35
40
|
registerCacheToCompiler(childCompiler, childCache);
|
36
41
|
}
|
37
42
|
}
|
@@ -43,7 +48,9 @@ class CachePlugin {
|
|
43
48
|
this.watching = true;
|
44
49
|
});
|
45
50
|
compiler.hooks.run.tapAsync("CachePlugin", (compiler, callback) => {
|
46
|
-
if (!compiler._lastCompilationFileDependencies)
|
51
|
+
if (!compiler._lastCompilationFileDependencies) {
|
52
|
+
return callback();
|
53
|
+
}
|
47
54
|
const fs = compiler.inputFileSystem;
|
48
55
|
const fileTs = (compiler.fileTimestamps = new Map());
|
49
56
|
asyncLib.forEach(
|
package/lib/Chunk.js
CHANGED
@@ -378,13 +378,14 @@ class Chunk {
|
|
378
378
|
otherChunk._groups.clear();
|
379
379
|
|
380
380
|
if (this.name && otherChunk.name) {
|
381
|
-
if (this.name.length !== otherChunk.name.length)
|
381
|
+
if (this.name.length !== otherChunk.name.length) {
|
382
382
|
this.name =
|
383
383
|
this.name.length < otherChunk.name.length
|
384
384
|
? this.name
|
385
385
|
: otherChunk.name;
|
386
|
-
else
|
386
|
+
} else {
|
387
387
|
this.name = this.name < otherChunk.name ? this.name : otherChunk.name;
|
388
|
+
}
|
388
389
|
}
|
389
390
|
|
390
391
|
return true;
|
@@ -420,12 +421,16 @@ class Chunk {
|
|
420
421
|
for (const chunkGroup of queue) {
|
421
422
|
if (a.isInGroup(chunkGroup)) continue;
|
422
423
|
if (chunkGroup.isInitial()) return false;
|
423
|
-
for (const parent of chunkGroup.parentsIterable)
|
424
|
+
for (const parent of chunkGroup.parentsIterable) {
|
425
|
+
queue.add(parent);
|
426
|
+
}
|
424
427
|
}
|
425
428
|
return true;
|
426
429
|
};
|
427
430
|
|
428
|
-
if (this.preventIntegration || otherChunk.preventIntegration)
|
431
|
+
if (this.preventIntegration || otherChunk.preventIntegration) {
|
432
|
+
return false;
|
433
|
+
}
|
429
434
|
|
430
435
|
if (this.hasRuntime() !== otherChunk.hasRuntime()) {
|
431
436
|
if (this.hasRuntime()) {
|
@@ -436,7 +441,11 @@ class Chunk {
|
|
436
441
|
return false;
|
437
442
|
}
|
438
443
|
}
|
439
|
-
|
444
|
+
|
445
|
+
if (this.hasEntryModule() || otherChunk.hasEntryModule()) {
|
446
|
+
return false;
|
447
|
+
}
|
448
|
+
|
440
449
|
return true;
|
441
450
|
}
|
442
451
|
|
@@ -509,14 +518,20 @@ class Chunk {
|
|
509
518
|
);
|
510
519
|
|
511
520
|
for (const chunkGroup of this.groupsIterable) {
|
512
|
-
for (const child of chunkGroup.childrenIterable)
|
521
|
+
for (const child of chunkGroup.childrenIterable) {
|
522
|
+
queue.add(child);
|
523
|
+
}
|
513
524
|
}
|
514
525
|
|
515
526
|
for (const chunkGroup of queue) {
|
516
527
|
for (const chunk of chunkGroup.chunks) {
|
517
|
-
if (!initialChunks.has(chunk))
|
528
|
+
if (!initialChunks.has(chunk)) {
|
529
|
+
chunks.add(chunk);
|
530
|
+
}
|
531
|
+
}
|
532
|
+
for (const child of chunkGroup.childrenIterable) {
|
533
|
+
queue.add(child);
|
518
534
|
}
|
519
|
-
for (const child of chunkGroup.childrenIterable) queue.add(child);
|
520
535
|
}
|
521
536
|
|
522
537
|
return chunks;
|
@@ -530,11 +545,14 @@ class Chunk {
|
|
530
545
|
for (const chunk of this.getAllAsyncChunks()) {
|
531
546
|
chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
|
532
547
|
for (const key of Object.keys(chunk.contentHash)) {
|
533
|
-
if (!chunkContentHashMap[key])
|
548
|
+
if (!chunkContentHashMap[key]) {
|
534
549
|
chunkContentHashMap[key] = Object.create(null);
|
550
|
+
}
|
535
551
|
chunkContentHashMap[key][chunk.id] = chunk.contentHash[key];
|
536
552
|
}
|
537
|
-
if (chunk.name)
|
553
|
+
if (chunk.name) {
|
554
|
+
chunkNameMap[chunk.id] = chunk.name;
|
555
|
+
}
|
538
556
|
}
|
539
557
|
|
540
558
|
return {
|
@@ -572,12 +590,16 @@ class Chunk {
|
|
572
590
|
const cmp = b.order - a.order;
|
573
591
|
if (cmp !== 0) return cmp;
|
574
592
|
// TOOD webpack 5 remove this check of compareTo
|
575
|
-
if (a.group.compareTo)
|
593
|
+
if (a.group.compareTo) {
|
594
|
+
return a.group.compareTo(b.group);
|
595
|
+
}
|
576
596
|
return 0;
|
577
597
|
});
|
578
598
|
result[name] = Array.from(
|
579
599
|
list.reduce((set, item) => {
|
580
|
-
for (const chunk of item.group.chunks)
|
600
|
+
for (const chunk of item.group.chunks) {
|
601
|
+
set.add(chunk.id);
|
602
|
+
}
|
581
603
|
return set;
|
582
604
|
}, new Set())
|
583
605
|
);
|
@@ -592,8 +614,9 @@ class Chunk {
|
|
592
614
|
const data = chunk.getChildIdsByOrders();
|
593
615
|
for (const key of Object.keys(data)) {
|
594
616
|
let chunkMap = chunkMaps[key];
|
595
|
-
if (chunkMap === undefined)
|
617
|
+
if (chunkMap === undefined) {
|
596
618
|
chunkMaps[key] = chunkMap = Object.create(null);
|
619
|
+
}
|
597
620
|
chunkMap[chunk.id] = data[key];
|
598
621
|
}
|
599
622
|
}
|
@@ -642,12 +665,17 @@ class Chunk {
|
|
642
665
|
if (!chunksProcessed.has(chunk)) {
|
643
666
|
chunksProcessed.add(chunk);
|
644
667
|
if (!filterChunkFn || filterChunkFn(chunk)) {
|
645
|
-
for (const module of chunk.modulesIterable)
|
646
|
-
if (filterFn(module))
|
668
|
+
for (const module of chunk.modulesIterable) {
|
669
|
+
if (filterFn(module)) {
|
670
|
+
return true;
|
671
|
+
}
|
672
|
+
}
|
647
673
|
}
|
648
674
|
}
|
649
675
|
}
|
650
|
-
for (const child of chunkGroup.childrenIterable)
|
676
|
+
for (const child of chunkGroup.childrenIterable) {
|
677
|
+
queue.add(child);
|
678
|
+
}
|
651
679
|
}
|
652
680
|
return false;
|
653
681
|
}
|
package/lib/ChunkGroup.js
CHANGED
@@ -259,7 +259,9 @@ class ChunkGroup {
|
|
259
259
|
|
260
260
|
setParents(newParents) {
|
261
261
|
this._parents.clear();
|
262
|
-
for (const p of newParents)
|
262
|
+
for (const p of newParents) {
|
263
|
+
this._parents.add(p);
|
264
|
+
}
|
263
265
|
}
|
264
266
|
|
265
267
|
getNumberOfParents() {
|
@@ -418,7 +420,9 @@ class ChunkGroup {
|
|
418
420
|
if (key.endsWith("Order")) {
|
419
421
|
const name = key.substr(0, key.length - "Order".length);
|
420
422
|
let list = lists.get(name);
|
421
|
-
if (list === undefined)
|
423
|
+
if (list === undefined) {
|
424
|
+
lists.set(name, (list = []));
|
425
|
+
}
|
422
426
|
list.push({
|
423
427
|
order: childGroup.options[key],
|
424
428
|
group: childGroup
|
@@ -433,7 +437,9 @@ class ChunkGroup {
|
|
433
437
|
const cmp = b.order - a.order;
|
434
438
|
if (cmp !== 0) return cmp;
|
435
439
|
// TOOD webpack 5 remove this check of compareTo
|
436
|
-
if (a.group.compareTo)
|
440
|
+
if (a.group.compareTo) {
|
441
|
+
return a.group.compareTo(b.group);
|
442
|
+
}
|
437
443
|
return 0;
|
438
444
|
});
|
439
445
|
result[name] = list.map(i => i.group);
|
@@ -444,20 +450,22 @@ class ChunkGroup {
|
|
444
450
|
checkConstraints() {
|
445
451
|
const chunk = this;
|
446
452
|
for (const child of chunk._children) {
|
447
|
-
if (!child._parents.has(chunk))
|
453
|
+
if (!child._parents.has(chunk)) {
|
448
454
|
throw new Error(
|
449
455
|
`checkConstraints: child missing parent ${chunk.debugId} -> ${
|
450
456
|
child.debugId
|
451
457
|
}`
|
452
458
|
);
|
459
|
+
}
|
453
460
|
}
|
454
461
|
for (const parentChunk of chunk._parents) {
|
455
|
-
if (!parentChunk._children.has(chunk))
|
462
|
+
if (!parentChunk._children.has(chunk)) {
|
456
463
|
throw new Error(
|
457
464
|
`checkConstraints: parent missing child ${parentChunk.debugId} <- ${
|
458
465
|
chunk.debugId
|
459
466
|
}`
|
460
467
|
);
|
468
|
+
}
|
461
469
|
}
|
462
470
|
}
|
463
471
|
}
|
package/lib/Compilation.js
CHANGED
@@ -287,8 +287,9 @@ class Compilation extends Tapable {
|
|
287
287
|
if (this.cache && this.cache[cacheName]) {
|
288
288
|
const cacheModule = this.cache[cacheName];
|
289
289
|
|
290
|
-
if (typeof cacheModule.updateCacheModule === "function")
|
290
|
+
if (typeof cacheModule.updateCacheModule === "function") {
|
291
291
|
cacheModule.updateCacheModule(module);
|
292
|
+
}
|
292
293
|
|
293
294
|
let rebuild = true;
|
294
295
|
if (this.fileTimestamps && this.contextTimestamps) {
|
@@ -302,8 +303,12 @@ class Compilation extends Tapable {
|
|
302
303
|
cacheModule.disconnect();
|
303
304
|
this._modules.set(identifier, cacheModule);
|
304
305
|
this.modules.push(cacheModule);
|
305
|
-
for (const err of cacheModule.errors)
|
306
|
-
|
306
|
+
for (const err of cacheModule.errors) {
|
307
|
+
this.errors.push(err);
|
308
|
+
}
|
309
|
+
for (const err of cacheModule.warnings) {
|
310
|
+
this.warnings.push(err);
|
311
|
+
}
|
307
312
|
return {
|
308
313
|
module: cacheModule,
|
309
314
|
issuer: true,
|
@@ -355,7 +360,9 @@ class Compilation extends Tapable {
|
|
355
360
|
|
356
361
|
const callback = err => {
|
357
362
|
this._buildingModules.delete(module);
|
358
|
-
for (const cb of callbackList)
|
363
|
+
for (const cb of callbackList) {
|
364
|
+
cb(err);
|
365
|
+
}
|
359
366
|
};
|
360
367
|
|
361
368
|
this.hooks.buildModule.call(module);
|
@@ -370,8 +377,11 @@ class Compilation extends Tapable {
|
|
370
377
|
const err = errors[indexError];
|
371
378
|
err.origin = origin;
|
372
379
|
err.dependencies = dependencies;
|
373
|
-
if (optional)
|
374
|
-
|
380
|
+
if (optional) {
|
381
|
+
this.warnings.push(err);
|
382
|
+
} else {
|
383
|
+
this.errors.push(err);
|
384
|
+
}
|
375
385
|
}
|
376
386
|
|
377
387
|
const warnings = module.warnings;
|
@@ -403,15 +413,17 @@ class Compilation extends Tapable {
|
|
403
413
|
const resourceIdent = dep.getResourceIdentifier();
|
404
414
|
if (resourceIdent) {
|
405
415
|
const factory = this.dependencyFactories.get(dep.constructor);
|
406
|
-
if (factory === undefined)
|
416
|
+
if (factory === undefined) {
|
407
417
|
throw new Error(
|
408
418
|
`No module factory available for dependency type: ${
|
409
419
|
dep.constructor.name
|
410
420
|
}`
|
411
421
|
);
|
422
|
+
}
|
412
423
|
let innerMap = dependencies.get(factory);
|
413
|
-
if (innerMap === undefined)
|
424
|
+
if (innerMap === undefined) {
|
414
425
|
dependencies.set(factory, (innerMap = new Map()));
|
426
|
+
}
|
415
427
|
let list = innerMap.get(resourceIdent);
|
416
428
|
if (list === undefined) innerMap.set(resourceIdent, (list = []));
|
417
429
|
list.push(dep);
|
@@ -781,7 +793,9 @@ class Compilation extends Tapable {
|
|
781
793
|
|
782
794
|
const callback = err => {
|
783
795
|
this._rebuildingModules.delete(module);
|
784
|
-
for (const cb of callbackList)
|
796
|
+
for (const cb of callbackList) {
|
797
|
+
cb(err);
|
798
|
+
}
|
785
799
|
};
|
786
800
|
|
787
801
|
this.hooks.rebuildModule.call(module);
|
@@ -925,15 +939,18 @@ class Compilation extends Tapable {
|
|
925
939
|
|
926
940
|
this.sortItemsWithChunkIds();
|
927
941
|
|
928
|
-
if (shouldRecord)
|
942
|
+
if (shouldRecord) {
|
929
943
|
this.hooks.recordModules.call(this.modules, this.records);
|
930
|
-
|
944
|
+
this.hooks.recordChunks.call(this.chunks, this.records);
|
945
|
+
}
|
931
946
|
|
932
947
|
this.hooks.beforeHash.call();
|
933
948
|
this.createHash();
|
934
949
|
this.hooks.afterHash.call();
|
935
950
|
|
936
|
-
if (shouldRecord)
|
951
|
+
if (shouldRecord) {
|
952
|
+
this.hooks.recordHash.call(this.records);
|
953
|
+
}
|
937
954
|
|
938
955
|
this.hooks.beforeModuleAssets.call();
|
939
956
|
this.createModuleAssets();
|
@@ -943,7 +960,9 @@ class Compilation extends Tapable {
|
|
943
960
|
}
|
944
961
|
this.hooks.additionalChunkAssets.call(this.chunks);
|
945
962
|
this.summarizeDependencies();
|
946
|
-
if (shouldRecord)
|
963
|
+
if (shouldRecord) {
|
964
|
+
this.hooks.record.call(this, this.records);
|
965
|
+
}
|
947
966
|
|
948
967
|
this.hooks.additionalAssets.callAsync(err => {
|
949
968
|
if (err) {
|
@@ -1378,8 +1397,11 @@ class Compilation extends Tapable {
|
|
1378
1397
|
|
1379
1398
|
// 3. Create a new Set of available modules at this points
|
1380
1399
|
newAvailableModules = new Set(availableModules);
|
1381
|
-
for (const chunk of chunkGroup.chunks)
|
1382
|
-
for (const m of chunk.modulesIterable)
|
1400
|
+
for (const chunk of chunkGroup.chunks) {
|
1401
|
+
for (const m of chunk.modulesIterable) {
|
1402
|
+
newAvailableModules.add(m);
|
1403
|
+
}
|
1404
|
+
}
|
1383
1405
|
|
1384
1406
|
// 4. Filter edges with available modules
|
1385
1407
|
const filteredDeps = deps.filter(filterFn);
|
@@ -1532,8 +1554,11 @@ class Compilation extends Tapable {
|
|
1532
1554
|
for (let indexModule2 = 0; indexModule2 < modules2.length; indexModule2++) {
|
1533
1555
|
const module2 = modules2[indexModule2];
|
1534
1556
|
if (module2.id === null) {
|
1535
|
-
if (unusedIds.length > 0)
|
1536
|
-
|
1557
|
+
if (unusedIds.length > 0) {
|
1558
|
+
module2.id = unusedIds.pop();
|
1559
|
+
} else {
|
1560
|
+
module2.id = nextFreeModuleId++;
|
1561
|
+
}
|
1537
1562
|
}
|
1538
1563
|
}
|
1539
1564
|
}
|
@@ -1587,8 +1612,11 @@ class Compilation extends Tapable {
|
|
1587
1612
|
for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
|
1588
1613
|
const chunk = chunks[indexChunk];
|
1589
1614
|
if (chunk.id === null) {
|
1590
|
-
if (unusedIds.length > 0)
|
1591
|
-
|
1615
|
+
if (unusedIds.length > 0) {
|
1616
|
+
chunk.id = unusedIds.pop();
|
1617
|
+
} else {
|
1618
|
+
chunk.id = nextFreeChunkId++;
|
1619
|
+
}
|
1592
1620
|
}
|
1593
1621
|
if (!chunk.ids) {
|
1594
1622
|
chunk.ids = [chunk.id];
|
@@ -1697,14 +1725,23 @@ class Compilation extends Tapable {
|
|
1697
1725
|
const hashDigest = outputOptions.hashDigest;
|
1698
1726
|
const hashDigestLength = outputOptions.hashDigestLength;
|
1699
1727
|
const hash = createHash(hashFunction);
|
1700
|
-
if (outputOptions.hashSalt)
|
1728
|
+
if (outputOptions.hashSalt) {
|
1729
|
+
hash.update(outputOptions.hashSalt);
|
1730
|
+
}
|
1701
1731
|
this.mainTemplate.updateHash(hash);
|
1702
1732
|
this.chunkTemplate.updateHash(hash);
|
1703
|
-
for (const key of Object.keys(this.moduleTemplates).sort())
|
1733
|
+
for (const key of Object.keys(this.moduleTemplates).sort()) {
|
1704
1734
|
this.moduleTemplates[key].updateHash(hash);
|
1705
|
-
|
1706
|
-
for (const
|
1707
|
-
|
1735
|
+
}
|
1736
|
+
for (const child of this.children) {
|
1737
|
+
hash.update(child.hash);
|
1738
|
+
}
|
1739
|
+
for (const warning of this.warnings) {
|
1740
|
+
hash.update(`${warning.message}`);
|
1741
|
+
}
|
1742
|
+
for (const error of this.errors) {
|
1743
|
+
hash.update(`${error.message}`);
|
1744
|
+
}
|
1708
1745
|
const modules = this.modules;
|
1709
1746
|
for (let i = 0; i < modules.length; i++) {
|
1710
1747
|
const module = modules[i];
|
@@ -1730,7 +1767,9 @@ class Compilation extends Tapable {
|
|
1730
1767
|
for (let i = 0; i < chunks.length; i++) {
|
1731
1768
|
const chunk = chunks[i];
|
1732
1769
|
const chunkHash = createHash(hashFunction);
|
1733
|
-
if (outputOptions.hashSalt)
|
1770
|
+
if (outputOptions.hashSalt) {
|
1771
|
+
chunkHash.update(outputOptions.hashSalt);
|
1772
|
+
}
|
1734
1773
|
chunk.updateHash(chunkHash);
|
1735
1774
|
const template = chunk.hasRuntime()
|
1736
1775
|
? this.mainTemplate
|
@@ -1823,10 +1862,11 @@ class Compilation extends Tapable {
|
|
1823
1862
|
}
|
1824
1863
|
}
|
1825
1864
|
file = this.getPath(filenameTemplate, fileManifest.pathOptions);
|
1826
|
-
if (this.assets[file] && this.assets[file] !== source)
|
1865
|
+
if (this.assets[file] && this.assets[file] !== source) {
|
1827
1866
|
throw new Error(
|
1828
1867
|
`Conflict: Multiple assets emit to the same filename ${file}`
|
1829
1868
|
);
|
1869
|
+
}
|
1830
1870
|
this.assets[file] = source;
|
1831
1871
|
chunk.files.push(file);
|
1832
1872
|
this.hooks.chunkAsset.call(chunk, file);
|
@@ -1864,18 +1904,20 @@ class Compilation extends Tapable {
|
|
1864
1904
|
for (let indexModule = 0; indexModule < modules.length; indexModule++) {
|
1865
1905
|
const moduleId = modules[indexModule].id;
|
1866
1906
|
if (moduleId === null) continue;
|
1867
|
-
if (usedIds.has(moduleId))
|
1907
|
+
if (usedIds.has(moduleId)) {
|
1868
1908
|
throw new Error(`checkConstraints: duplicate module id ${moduleId}`);
|
1909
|
+
}
|
1869
1910
|
usedIds.add(moduleId);
|
1870
1911
|
}
|
1871
1912
|
|
1872
1913
|
const chunks = this.chunks;
|
1873
1914
|
for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
|
1874
1915
|
const chunk = chunks[indexChunk];
|
1875
|
-
if (chunks.indexOf(chunk) !== indexChunk)
|
1916
|
+
if (chunks.indexOf(chunk) !== indexChunk) {
|
1876
1917
|
throw new Error(
|
1877
1918
|
`checkConstraints: duplicate chunk in compilation ${chunk.debugId}`
|
1878
1919
|
);
|
1920
|
+
}
|
1879
1921
|
}
|
1880
1922
|
|
1881
1923
|
for (const chunkGroup of this.chunkGroups) {
|
package/lib/Compiler.js
CHANGED
@@ -245,8 +245,9 @@ class Compiler extends Tapable {
|
|
245
245
|
}
|
246
246
|
|
247
247
|
purgeInputFileSystem() {
|
248
|
-
if (this.inputFileSystem && this.inputFileSystem.purge)
|
248
|
+
if (this.inputFileSystem && this.inputFileSystem.purge) {
|
249
249
|
this.inputFileSystem.purge();
|
250
|
+
}
|
250
251
|
}
|
251
252
|
|
252
253
|
emitAssets(compilation, callback) {
|
@@ -291,7 +292,9 @@ class Compiler extends Tapable {
|
|
291
292
|
this.outputFileSystem.join(outputPath, dir),
|
292
293
|
writeOut
|
293
294
|
);
|
294
|
-
} else
|
295
|
+
} else {
|
296
|
+
writeOut();
|
297
|
+
}
|
295
298
|
},
|
296
299
|
err => {
|
297
300
|
if (err) return callback(err);
|
@@ -317,10 +320,11 @@ class Compiler extends Tapable {
|
|
317
320
|
const idx1 = this.recordsOutputPath.lastIndexOf("/");
|
318
321
|
const idx2 = this.recordsOutputPath.lastIndexOf("\\");
|
319
322
|
let recordsOutputPathDirectory = null;
|
320
|
-
if (idx1 > idx2)
|
323
|
+
if (idx1 > idx2) {
|
321
324
|
recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx1);
|
322
|
-
if (idx1 < idx2)
|
325
|
+
} else if (idx1 < idx2) {
|
323
326
|
recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx2);
|
327
|
+
}
|
324
328
|
|
325
329
|
const writeFile = () => {
|
326
330
|
this.outputFileSystem.writeFile(
|
@@ -330,7 +334,9 @@ class Compiler extends Tapable {
|
|
330
334
|
);
|
331
335
|
};
|
332
336
|
|
333
|
-
if (!recordsOutputPathDirectory)
|
337
|
+
if (!recordsOutputPathDirectory) {
|
338
|
+
return writeFile();
|
339
|
+
}
|
334
340
|
this.outputFileSystem.mkdirp(recordsOutputPathDirectory, err => {
|
335
341
|
if (err) return callback(err);
|
336
342
|
writeFile();
|
@@ -371,7 +377,9 @@ class Compiler extends Tapable {
|
|
371
377
|
) {
|
372
378
|
const childCompiler = new Compiler(this.context);
|
373
379
|
if (Array.isArray(plugins)) {
|
374
|
-
for (const plugin of plugins)
|
380
|
+
for (const plugin of plugins) {
|
381
|
+
plugin.apply(childCompiler);
|
382
|
+
}
|
375
383
|
}
|
376
384
|
for (const name in this.hooks) {
|
377
385
|
if (
|
@@ -385,8 +393,9 @@ class Compiler extends Tapable {
|
|
385
393
|
"thisCompilation"
|
386
394
|
].includes(name)
|
387
395
|
) {
|
388
|
-
if (childCompiler.hooks[name])
|
396
|
+
if (childCompiler.hooks[name]) {
|
389
397
|
childCompiler.hooks[name].taps = this.hooks[name].taps.slice();
|
398
|
+
}
|
390
399
|
}
|
391
400
|
}
|
392
401
|
childCompiler.name = compilerName;
|
@@ -398,11 +407,14 @@ class Compiler extends Tapable {
|
|
398
407
|
childCompiler.contextTimestamps = this.contextTimestamps;
|
399
408
|
|
400
409
|
const relativeCompilerName = makePathsRelative(this.context, compilerName);
|
401
|
-
if (!this.records[relativeCompilerName])
|
410
|
+
if (!this.records[relativeCompilerName]) {
|
402
411
|
this.records[relativeCompilerName] = [];
|
403
|
-
|
412
|
+
}
|
413
|
+
if (this.records[relativeCompilerName][compilerIndex]) {
|
404
414
|
childCompiler.records = this.records[relativeCompilerName][compilerIndex];
|
405
|
-
else
|
415
|
+
} else {
|
416
|
+
this.records[relativeCompilerName].push((childCompiler.records = {}));
|
417
|
+
}
|
406
418
|
|
407
419
|
childCompiler.options = Object.create(this.options);
|
408
420
|
childCompiler.options.output = Object.create(childCompiler.options.output);
|
package/lib/ConstPlugin.js
CHANGED
@@ -21,13 +21,19 @@ const collectDeclaration = (declarations, pattern) => {
|
|
21
21
|
declarations.add(node.name);
|
22
22
|
break;
|
23
23
|
case "ArrayPattern":
|
24
|
-
for (const element of node.elements)
|
24
|
+
for (const element of node.elements) {
|
25
|
+
if (element) {
|
26
|
+
stack.push(element);
|
27
|
+
}
|
28
|
+
}
|
25
29
|
break;
|
26
30
|
case "AssignmentPattern":
|
27
31
|
stack.push(node.left);
|
28
32
|
break;
|
29
33
|
case "ObjectPattern":
|
30
|
-
for (const property of node.properties)
|
34
|
+
for (const property of node.properties) {
|
35
|
+
stack.push(property.value);
|
36
|
+
}
|
31
37
|
break;
|
32
38
|
case "RestElement":
|
33
39
|
stack.push(node.argument);
|
@@ -47,7 +53,9 @@ const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
|
|
47
53
|
// Walk through control statements to look for hoisted declarations.
|
48
54
|
// Some branches are skipped since they do not allow declarations.
|
49
55
|
case "BlockStatement":
|
50
|
-
for (const stmt of node.body)
|
56
|
+
for (const stmt of node.body) {
|
57
|
+
stack.push(stmt);
|
58
|
+
}
|
51
59
|
break;
|
52
60
|
case "IfStatement":
|
53
61
|
stack.push(node.consequent);
|
@@ -68,22 +76,30 @@ const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
|
|
68
76
|
stack.push(node.body);
|
69
77
|
break;
|
70
78
|
case "SwitchStatement":
|
71
|
-
for (const cs of node.cases)
|
72
|
-
for (const consequent of cs.consequent)
|
79
|
+
for (const cs of node.cases) {
|
80
|
+
for (const consequent of cs.consequent) {
|
81
|
+
stack.push(consequent);
|
82
|
+
}
|
83
|
+
}
|
73
84
|
break;
|
74
85
|
case "TryStatement":
|
75
86
|
stack.push(node.block);
|
76
|
-
if (node.handler)
|
87
|
+
if (node.handler) {
|
88
|
+
stack.push(node.handler.body);
|
89
|
+
}
|
77
90
|
stack.push(node.finalizer);
|
78
91
|
break;
|
79
92
|
case "FunctionDeclaration":
|
80
|
-
if (includeFunctionDeclarations)
|
93
|
+
if (includeFunctionDeclarations) {
|
81
94
|
collectDeclaration(declarations, node.id);
|
95
|
+
}
|
82
96
|
break;
|
83
97
|
case "VariableDeclaration":
|
84
|
-
if (node.kind === "var")
|
85
|
-
for (const decl of node.declarations)
|
98
|
+
if (node.kind === "var") {
|
99
|
+
for (const decl of node.declarations) {
|
86
100
|
collectDeclaration(declarations, decl.id);
|
101
|
+
}
|
102
|
+
}
|
87
103
|
break;
|
88
104
|
}
|
89
105
|
}
|