webpack 4.10.1 → 4.12.0
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/AsyncDependencyToInitialChunkError.js +4 -4
- package/lib/BannerPlugin.js +3 -1
- package/lib/BasicEvaluatedExpression.js +14 -11
- package/lib/CachePlugin.js +12 -5
- package/lib/CaseSensitiveModulesWarning.js +41 -45
- package/lib/Chunk.js +56 -19
- package/lib/ChunkGroup.js +14 -6
- package/lib/CommentCompilationWarning.js +22 -0
- package/lib/Compilation.js +72 -29
- 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/EntryModuleNotFoundError.js +21 -22
- 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/HarmonyLinkingError.js +1 -2
- package/lib/HotModuleReplacement.runtime.js +13 -4
- 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 +13 -5
- package/lib/ModuleBuildError.js +22 -12
- package/lib/ModuleDependencyError.js +4 -4
- package/lib/ModuleDependencyWarning.js +4 -4
- package/lib/ModuleError.js +13 -5
- package/lib/ModuleFilenameHelpers.js +20 -8
- package/lib/ModuleNotFoundError.js +23 -26
- package/lib/ModuleParseError.js +27 -14
- package/lib/ModuleWarning.js +13 -7
- package/lib/MultiCompiler.js +19 -7
- package/lib/MultiModule.js +5 -2
- package/lib/NodeStuffPlugin.js +2 -1
- package/lib/NormalModule.js +80 -16
- package/lib/NormalModuleFactory.js +67 -24
- package/lib/OptionsDefaulter.js +7 -3
- package/lib/Parser.js +182 -75
- package/lib/ParserHelpers.js +6 -3
- package/lib/ProgressPlugin.js +17 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +77 -9
- package/lib/RemovedPluginError.js +1 -3
- package/lib/RequestShortener.js +15 -6
- package/lib/RuleSet.js +51 -18
- package/lib/RuntimeTemplate.js +21 -10
- package/lib/SourceMapDevToolPlugin.js +4 -3
- package/lib/Stats.js +74 -31
- package/lib/Template.js +7 -4
- package/lib/TemplatedPathPlugin.js +6 -3
- package/lib/UmdMainTemplatePlugin.js +8 -3
- package/lib/UnsupportedFeatureWarning.js +22 -21
- package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
- package/lib/Watching.js +3 -2
- package/lib/WebpackOptionsApply.js +51 -23
- package/lib/WebpackOptionsDefaulter.js +15 -9
- package/lib/WebpackOptionsValidationError.js +63 -34
- package/lib/debug/ProfilingPlugin.js +11 -2
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -4
- 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 +42 -11
- 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/dependencies/SystemPlugin.js +6 -6
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +29 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- 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/node/ReadFileCompileWasmTemplatePlugin.js +11 -2
- 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 +14 -3
- package/lib/optimize/SplitChunksPlugin.js +33 -20
- package/lib/performance/AssetsOverSizeLimitWarning.js +7 -7
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -7
- package/lib/performance/NoAsyncChunksWarning.js +5 -5
- package/lib/util/SortableSet.js +5 -2
- package/lib/util/StackedSetMap.js +12 -5
- package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +1 -2
- package/lib/wasm/WasmFinalizeExportsPlugin.js +66 -0
- package/lib/wasm/WasmMainTemplatePlugin.js +87 -43
- package/lib/wasm/WebAssemblyGenerator.js +117 -74
- package/lib/wasm/WebAssemblyJavascriptGenerator.js +92 -49
- package/lib/wasm/WebAssemblyModulesPlugin.js +11 -1
- package/lib/wasm/WebAssemblyParser.js +96 -24
- package/lib/wasm/WebAssemblyUtils.js +17 -6
- package/lib/web/FetchCompileWasmTemplatePlugin.js +13 -1
- package/lib/web/JsonpChunkTemplatePlugin.js +7 -0
- package/lib/web/JsonpMainTemplate.runtime.js +2 -1
- package/lib/web/JsonpMainTemplatePlugin.js +68 -63
- package/lib/webpack.js +2 -1
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
- package/package.json +12 -11
- package/schemas/WebpackOptions.json +8 -0
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);
|
@@ -475,6 +487,7 @@ class Compilation extends Tapable {
|
|
475
487
|
|
476
488
|
const errorAndCallback = err => {
|
477
489
|
err.origin = module;
|
490
|
+
err.dependencies = dependencies;
|
478
491
|
this.errors.push(err);
|
479
492
|
if (bail) {
|
480
493
|
callback(err);
|
@@ -519,7 +532,7 @@ class Compilation extends Tapable {
|
|
519
532
|
if (err) {
|
520
533
|
semaphore.release();
|
521
534
|
return errorOrWarningAndCallback(
|
522
|
-
new ModuleNotFoundError(module, err
|
535
|
+
new ModuleNotFoundError(module, err)
|
523
536
|
);
|
524
537
|
}
|
525
538
|
if (!dependentModule) {
|
@@ -781,7 +794,9 @@ class Compilation extends Tapable {
|
|
781
794
|
|
782
795
|
const callback = err => {
|
783
796
|
this._rebuildingModules.delete(module);
|
784
|
-
for (const cb of callbackList)
|
797
|
+
for (const cb of callbackList) {
|
798
|
+
cb(err);
|
799
|
+
}
|
785
800
|
};
|
786
801
|
|
787
802
|
this.hooks.rebuildModule.call(module);
|
@@ -925,15 +940,18 @@ class Compilation extends Tapable {
|
|
925
940
|
|
926
941
|
this.sortItemsWithChunkIds();
|
927
942
|
|
928
|
-
if (shouldRecord)
|
943
|
+
if (shouldRecord) {
|
929
944
|
this.hooks.recordModules.call(this.modules, this.records);
|
930
|
-
|
945
|
+
this.hooks.recordChunks.call(this.chunks, this.records);
|
946
|
+
}
|
931
947
|
|
932
948
|
this.hooks.beforeHash.call();
|
933
949
|
this.createHash();
|
934
950
|
this.hooks.afterHash.call();
|
935
951
|
|
936
|
-
if (shouldRecord)
|
952
|
+
if (shouldRecord) {
|
953
|
+
this.hooks.recordHash.call(this.records);
|
954
|
+
}
|
937
955
|
|
938
956
|
this.hooks.beforeModuleAssets.call();
|
939
957
|
this.createModuleAssets();
|
@@ -943,7 +961,9 @@ class Compilation extends Tapable {
|
|
943
961
|
}
|
944
962
|
this.hooks.additionalChunkAssets.call(this.chunks);
|
945
963
|
this.summarizeDependencies();
|
946
|
-
if (shouldRecord)
|
964
|
+
if (shouldRecord) {
|
965
|
+
this.hooks.record.call(this, this.records);
|
966
|
+
}
|
947
967
|
|
948
968
|
this.hooks.additionalAssets.callAsync(err => {
|
949
969
|
if (err) {
|
@@ -1378,8 +1398,11 @@ class Compilation extends Tapable {
|
|
1378
1398
|
|
1379
1399
|
// 3. Create a new Set of available modules at this points
|
1380
1400
|
newAvailableModules = new Set(availableModules);
|
1381
|
-
for (const chunk of chunkGroup.chunks)
|
1382
|
-
for (const m of chunk.modulesIterable)
|
1401
|
+
for (const chunk of chunkGroup.chunks) {
|
1402
|
+
for (const m of chunk.modulesIterable) {
|
1403
|
+
newAvailableModules.add(m);
|
1404
|
+
}
|
1405
|
+
}
|
1383
1406
|
|
1384
1407
|
// 4. Filter edges with available modules
|
1385
1408
|
const filteredDeps = deps.filter(filterFn);
|
@@ -1532,8 +1555,11 @@ class Compilation extends Tapable {
|
|
1532
1555
|
for (let indexModule2 = 0; indexModule2 < modules2.length; indexModule2++) {
|
1533
1556
|
const module2 = modules2[indexModule2];
|
1534
1557
|
if (module2.id === null) {
|
1535
|
-
if (unusedIds.length > 0)
|
1536
|
-
|
1558
|
+
if (unusedIds.length > 0) {
|
1559
|
+
module2.id = unusedIds.pop();
|
1560
|
+
} else {
|
1561
|
+
module2.id = nextFreeModuleId++;
|
1562
|
+
}
|
1537
1563
|
}
|
1538
1564
|
}
|
1539
1565
|
}
|
@@ -1587,8 +1613,11 @@ class Compilation extends Tapable {
|
|
1587
1613
|
for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
|
1588
1614
|
const chunk = chunks[indexChunk];
|
1589
1615
|
if (chunk.id === null) {
|
1590
|
-
if (unusedIds.length > 0)
|
1591
|
-
|
1616
|
+
if (unusedIds.length > 0) {
|
1617
|
+
chunk.id = unusedIds.pop();
|
1618
|
+
} else {
|
1619
|
+
chunk.id = nextFreeChunkId++;
|
1620
|
+
}
|
1592
1621
|
}
|
1593
1622
|
if (!chunk.ids) {
|
1594
1623
|
chunk.ids = [chunk.id];
|
@@ -1697,14 +1726,23 @@ class Compilation extends Tapable {
|
|
1697
1726
|
const hashDigest = outputOptions.hashDigest;
|
1698
1727
|
const hashDigestLength = outputOptions.hashDigestLength;
|
1699
1728
|
const hash = createHash(hashFunction);
|
1700
|
-
if (outputOptions.hashSalt)
|
1729
|
+
if (outputOptions.hashSalt) {
|
1730
|
+
hash.update(outputOptions.hashSalt);
|
1731
|
+
}
|
1701
1732
|
this.mainTemplate.updateHash(hash);
|
1702
1733
|
this.chunkTemplate.updateHash(hash);
|
1703
|
-
for (const key of Object.keys(this.moduleTemplates).sort())
|
1734
|
+
for (const key of Object.keys(this.moduleTemplates).sort()) {
|
1704
1735
|
this.moduleTemplates[key].updateHash(hash);
|
1705
|
-
|
1706
|
-
for (const
|
1707
|
-
|
1736
|
+
}
|
1737
|
+
for (const child of this.children) {
|
1738
|
+
hash.update(child.hash);
|
1739
|
+
}
|
1740
|
+
for (const warning of this.warnings) {
|
1741
|
+
hash.update(`${warning.message}`);
|
1742
|
+
}
|
1743
|
+
for (const error of this.errors) {
|
1744
|
+
hash.update(`${error.message}`);
|
1745
|
+
}
|
1708
1746
|
const modules = this.modules;
|
1709
1747
|
for (let i = 0; i < modules.length; i++) {
|
1710
1748
|
const module = modules[i];
|
@@ -1730,7 +1768,9 @@ class Compilation extends Tapable {
|
|
1730
1768
|
for (let i = 0; i < chunks.length; i++) {
|
1731
1769
|
const chunk = chunks[i];
|
1732
1770
|
const chunkHash = createHash(hashFunction);
|
1733
|
-
if (outputOptions.hashSalt)
|
1771
|
+
if (outputOptions.hashSalt) {
|
1772
|
+
chunkHash.update(outputOptions.hashSalt);
|
1773
|
+
}
|
1734
1774
|
chunk.updateHash(chunkHash);
|
1735
1775
|
const template = chunk.hasRuntime()
|
1736
1776
|
? this.mainTemplate
|
@@ -1823,10 +1863,11 @@ class Compilation extends Tapable {
|
|
1823
1863
|
}
|
1824
1864
|
}
|
1825
1865
|
file = this.getPath(filenameTemplate, fileManifest.pathOptions);
|
1826
|
-
if (this.assets[file] && this.assets[file] !== source)
|
1866
|
+
if (this.assets[file] && this.assets[file] !== source) {
|
1827
1867
|
throw new Error(
|
1828
1868
|
`Conflict: Multiple assets emit to the same filename ${file}`
|
1829
1869
|
);
|
1870
|
+
}
|
1830
1871
|
this.assets[file] = source;
|
1831
1872
|
chunk.files.push(file);
|
1832
1873
|
this.hooks.chunkAsset.call(chunk, file);
|
@@ -1864,18 +1905,20 @@ class Compilation extends Tapable {
|
|
1864
1905
|
for (let indexModule = 0; indexModule < modules.length; indexModule++) {
|
1865
1906
|
const moduleId = modules[indexModule].id;
|
1866
1907
|
if (moduleId === null) continue;
|
1867
|
-
if (usedIds.has(moduleId))
|
1908
|
+
if (usedIds.has(moduleId)) {
|
1868
1909
|
throw new Error(`checkConstraints: duplicate module id ${moduleId}`);
|
1910
|
+
}
|
1869
1911
|
usedIds.add(moduleId);
|
1870
1912
|
}
|
1871
1913
|
|
1872
1914
|
const chunks = this.chunks;
|
1873
1915
|
for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
|
1874
1916
|
const chunk = chunks[indexChunk];
|
1875
|
-
if (chunks.indexOf(chunk) !== indexChunk)
|
1917
|
+
if (chunks.indexOf(chunk) !== indexChunk) {
|
1876
1918
|
throw new Error(
|
1877
1919
|
`checkConstraints: duplicate chunk in compilation ${chunk.debugId}`
|
1878
1920
|
);
|
1921
|
+
}
|
1879
1922
|
}
|
1880
1923
|
|
1881
1924
|
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
|
}
|
package/lib/ContextModule.js
CHANGED
@@ -35,14 +35,16 @@ class ContextModule extends Module {
|
|
35
35
|
resource: resource,
|
36
36
|
resourceQuery: resourceQuery
|
37
37
|
});
|
38
|
-
if (options.resolveOptions !== undefined)
|
38
|
+
if (options.resolveOptions !== undefined) {
|
39
39
|
this.resolveOptions = options.resolveOptions;
|
40
|
+
}
|
40
41
|
|
41
42
|
// Info from Build
|
42
43
|
this._contextDependencies = new Set([this.context]);
|
43
44
|
|
44
|
-
if (typeof options.mode !== "string")
|
45
|
+
if (typeof options.mode !== "string") {
|
45
46
|
throw new Error("options.mode is a required option");
|
47
|
+
}
|
46
48
|
|
47
49
|
this._identifier = this._createIdentifier();
|
48
50
|
}
|
@@ -73,22 +75,37 @@ class ContextModule extends Module {
|
|
73
75
|
|
74
76
|
_createIdentifier() {
|
75
77
|
let identifier = this.context;
|
76
|
-
if (this.options.resourceQuery)
|
78
|
+
if (this.options.resourceQuery) {
|
77
79
|
identifier += ` ${this.options.resourceQuery}`;
|
78
|
-
|
79
|
-
if (
|
80
|
-
|
81
|
-
|
82
|
-
if (this.options.
|
83
|
-
|
80
|
+
}
|
81
|
+
if (this.options.mode) {
|
82
|
+
identifier += ` ${this.options.mode}`;
|
83
|
+
}
|
84
|
+
if (!this.options.recursive) {
|
85
|
+
identifier += " nonrecursive";
|
86
|
+
}
|
87
|
+
if (this.options.addon) {
|
88
|
+
identifier += ` ${this.options.addon}`;
|
89
|
+
}
|
90
|
+
if (this.options.regExp) {
|
91
|
+
identifier += ` ${this.options.regExp}`;
|
92
|
+
}
|
93
|
+
if (this.options.include) {
|
94
|
+
identifier += ` include: ${this.options.include}`;
|
95
|
+
}
|
96
|
+
if (this.options.exclude) {
|
97
|
+
identifier += ` exclude: ${this.options.exclude}`;
|
98
|
+
}
|
84
99
|
if (this.options.groupOptions) {
|
85
100
|
identifier += ` groupOptions: ${JSON.stringify(
|
86
101
|
this.options.groupOptions
|
87
102
|
)}`;
|
88
103
|
}
|
89
|
-
if (this.options.namespaceObject === "strict")
|
104
|
+
if (this.options.namespaceObject === "strict") {
|
90
105
|
identifier += " strict namespace object";
|
91
|
-
else if (this.options.namespaceObject)
|
106
|
+
} else if (this.options.namespaceObject) {
|
107
|
+
identifier += " namespace object";
|
108
|
+
}
|
92
109
|
|
93
110
|
return identifier;
|
94
111
|
}
|
@@ -99,42 +116,62 @@ class ContextModule extends Module {
|
|
99
116
|
|
100
117
|
readableIdentifier(requestShortener) {
|
101
118
|
let identifier = requestShortener.shorten(this.context);
|
102
|
-
if (this.options.resourceQuery)
|
119
|
+
if (this.options.resourceQuery) {
|
103
120
|
identifier += ` ${this.options.resourceQuery}`;
|
104
|
-
|
105
|
-
if (
|
106
|
-
|
121
|
+
}
|
122
|
+
if (this.options.mode) {
|
123
|
+
identifier += ` ${this.options.mode}`;
|
124
|
+
}
|
125
|
+
if (!this.options.recursive) {
|
126
|
+
identifier += " nonrecursive";
|
127
|
+
}
|
128
|
+
if (this.options.addon) {
|
107
129
|
identifier += ` ${requestShortener.shorten(this.options.addon)}`;
|
108
|
-
|
130
|
+
}
|
131
|
+
if (this.options.regExp) {
|
109
132
|
identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
|
110
|
-
|
133
|
+
}
|
134
|
+
if (this.options.include) {
|
111
135
|
identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
|
112
|
-
|
136
|
+
}
|
137
|
+
if (this.options.exclude) {
|
113
138
|
identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
|
139
|
+
}
|
114
140
|
if (this.options.groupOptions) {
|
115
141
|
const groupOptions = this.options.groupOptions;
|
116
|
-
for (const key of Object.keys(groupOptions))
|
142
|
+
for (const key of Object.keys(groupOptions)) {
|
117
143
|
identifier += ` ${key}: ${groupOptions[key]}`;
|
144
|
+
}
|
118
145
|
}
|
119
|
-
if (this.options.namespaceObject === "strict")
|
146
|
+
if (this.options.namespaceObject === "strict") {
|
120
147
|
identifier += " strict namespace object";
|
121
|
-
else if (this.options.namespaceObject)
|
148
|
+
} else if (this.options.namespaceObject) {
|
149
|
+
identifier += " namespace object";
|
150
|
+
}
|
122
151
|
|
123
152
|
return identifier;
|
124
153
|
}
|
125
154
|
|
126
155
|
libIdent(options) {
|
127
156
|
let identifier = this.contextify(options.context, this.context);
|
128
|
-
if (this.options.mode)
|
129
|
-
|
130
|
-
|
157
|
+
if (this.options.mode) {
|
158
|
+
identifier += ` ${this.options.mode}`;
|
159
|
+
}
|
160
|
+
if (this.options.recursive) {
|
161
|
+
identifier += " recursive";
|
162
|
+
}
|
163
|
+
if (this.options.addon) {
|
131
164
|
identifier += ` ${this.contextify(options.context, this.options.addon)}`;
|
132
|
-
|
165
|
+
}
|
166
|
+
if (this.options.regExp) {
|
133
167
|
identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
|
134
|
-
|
168
|
+
}
|
169
|
+
if (this.options.include) {
|
135
170
|
identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
|
136
|
-
|
171
|
+
}
|
172
|
+
if (this.options.exclude) {
|
137
173
|
identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
|
174
|
+
}
|
138
175
|
|
139
176
|
return identifier;
|
140
177
|
}
|
@@ -206,7 +243,9 @@ class ContextModule extends Module {
|
|
206
243
|
for (const dep of dependencies) {
|
207
244
|
let chunkName = this.options.chunkName;
|
208
245
|
if (chunkName) {
|
209
|
-
if (!/\[(index|request)\]/.test(chunkName))
|
246
|
+
if (!/\[(index|request)\]/.test(chunkName)) {
|
247
|
+
chunkName += "[index]";
|
248
|
+
}
|
210
249
|
chunkName = chunkName.replace(/\[index\]/g, index++);
|
211
250
|
chunkName = chunkName.replace(
|
212
251
|
/\[request\]/g,
|
@@ -253,7 +292,9 @@ class ContextModule extends Module {
|
|
253
292
|
}
|
254
293
|
|
255
294
|
getFakeMap(dependencies) {
|
256
|
-
if (!this.options.namespaceObject)
|
295
|
+
if (!this.options.namespaceObject) {
|
296
|
+
return 9;
|
297
|
+
}
|
257
298
|
// if we filter first we get a new array
|
258
299
|
// therefor we dont need to create a clone of dependencies explicitly
|
259
300
|
// therefore the order of this is !important!
|
@@ -281,11 +322,18 @@ class ContextModule extends Module {
|
|
281
322
|
}
|
282
323
|
return map;
|
283
324
|
}, Object.create(null));
|
284
|
-
if (!hasNamespace && hasNonHarmony && !hasNamed)
|
325
|
+
if (!hasNamespace && hasNonHarmony && !hasNamed) {
|
285
326
|
return this.options.namespaceObject === "strict" ? 1 : 7;
|
286
|
-
|
287
|
-
if (
|
288
|
-
|
327
|
+
}
|
328
|
+
if (hasNamespace && !hasNonHarmony && !hasNamed) {
|
329
|
+
return 9;
|
330
|
+
}
|
331
|
+
if (!hasNamespace && !hasNonHarmony && hasNamed) {
|
332
|
+
return 3;
|
333
|
+
}
|
334
|
+
if (!hasNamespace && !hasNonHarmony && !hasNamed) {
|
335
|
+
return 9;
|
336
|
+
}
|
289
337
|
return fakeMap;
|
290
338
|
}
|
291
339
|
|
@@ -296,13 +344,16 @@ class ContextModule extends Module {
|
|
296
344
|
}
|
297
345
|
|
298
346
|
getReturn(type) {
|
299
|
-
if (type === 9)
|
347
|
+
if (type === 9) {
|
348
|
+
return "__webpack_require__(id)";
|
349
|
+
}
|
300
350
|
return `__webpack_require__.t(id, ${type})`;
|
301
351
|
}
|
302
352
|
|
303
353
|
getReturnModuleObjectSource(fakeMap, fakeMapDataExpression = "fakeMap[id]") {
|
304
|
-
if (typeof fakeMap === "number")
|
354
|
+
if (typeof fakeMap === "number") {
|
305
355
|
return `return ${this.getReturn(fakeMap)};`;
|
356
|
+
}
|
306
357
|
return `return __webpack_require__.t(id, ${fakeMapDataExpression})`;
|
307
358
|
}
|
308
359
|
|
@@ -504,8 +555,9 @@ module.exports = webpackAsyncContext;`;
|
|
504
555
|
hasMultipleOrNoChunks = true;
|
505
556
|
}
|
506
557
|
const arrayStart = [item.dependency.module.id];
|
507
|
-
if (typeof fakeMap === "object")
|
558
|
+
if (typeof fakeMap === "object") {
|
508
559
|
arrayStart.push(fakeMap[item.dependency.module.id]);
|
560
|
+
}
|
509
561
|
map[item.userRequest] = arrayStart.concat(
|
510
562
|
chunks.map(chunk => chunk.id)
|
511
563
|
);
|
@@ -67,17 +67,24 @@ module.exports = class ContextModuleFactory extends Tapable {
|
|
67
67
|
loadersPrefix = "";
|
68
68
|
const idx = request.lastIndexOf("!");
|
69
69
|
if (idx >= 0) {
|
70
|
-
|
70
|
+
let loadersRequest = request.substr(0, idx + 1);
|
71
71
|
let i;
|
72
|
-
for (
|
72
|
+
for (
|
73
|
+
i = 0;
|
74
|
+
i < loadersRequest.length && loadersRequest[i] === "!";
|
75
|
+
i++
|
76
|
+
) {
|
73
77
|
loadersPrefix += "!";
|
74
78
|
}
|
75
|
-
|
79
|
+
loadersRequest = loadersRequest
|
76
80
|
.substr(i)
|
77
81
|
.replace(/!+$/, "")
|
78
82
|
.replace(/!!+/g, "!");
|
79
|
-
if (
|
80
|
-
|
83
|
+
if (loadersRequest === "") {
|
84
|
+
loaders = [];
|
85
|
+
} else {
|
86
|
+
loaders = loadersRequest.split("!");
|
87
|
+
}
|
81
88
|
resource = request.substr(idx + 1);
|
82
89
|
} else {
|
83
90
|
loaders = [];
|
@@ -222,9 +229,13 @@ module.exports = class ContextModuleFactory extends Tapable {
|
|
222
229
|
callback(null, alternatives);
|
223
230
|
}
|
224
231
|
);
|
225
|
-
} else
|
232
|
+
} else {
|
233
|
+
callback();
|
234
|
+
}
|
226
235
|
});
|
227
|
-
} else
|
236
|
+
} else {
|
237
|
+
callback();
|
238
|
+
}
|
228
239
|
},
|
229
240
|
(err, result) => {
|
230
241
|
if (err) return callback(err);
|