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.
Files changed (118) hide show
  1. package/lib/AmdMainTemplatePlugin.js +3 -1
  2. package/lib/AsyncDependencyToInitialChunkError.js +4 -4
  3. package/lib/BannerPlugin.js +3 -1
  4. package/lib/BasicEvaluatedExpression.js +14 -11
  5. package/lib/CachePlugin.js +12 -5
  6. package/lib/CaseSensitiveModulesWarning.js +41 -45
  7. package/lib/Chunk.js +56 -19
  8. package/lib/ChunkGroup.js +14 -6
  9. package/lib/CommentCompilationWarning.js +22 -0
  10. package/lib/Compilation.js +72 -29
  11. package/lib/Compiler.js +22 -10
  12. package/lib/ConstPlugin.js +25 -9
  13. package/lib/ContextModule.js +88 -36
  14. package/lib/ContextModuleFactory.js +18 -7
  15. package/lib/ContextReplacementPlugin.js +14 -7
  16. package/lib/DefinePlugin.js +15 -6
  17. package/lib/DependenciesBlock.js +3 -1
  18. package/lib/DependenciesBlockVariable.js +2 -1
  19. package/lib/DllPlugin.js +4 -2
  20. package/lib/DynamicEntryPlugin.js +4 -2
  21. package/lib/EntryModuleNotFoundError.js +21 -22
  22. package/lib/ErrorHelpers.js +5 -2
  23. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  24. package/lib/FlagDependencyUsagePlugin.js +11 -5
  25. package/lib/FunctionModuleTemplatePlugin.js +8 -6
  26. package/lib/HarmonyLinkingError.js +1 -2
  27. package/lib/HotModuleReplacement.runtime.js +13 -4
  28. package/lib/HotModuleReplacementPlugin.js +13 -6
  29. package/lib/JavascriptGenerator.js +2 -1
  30. package/lib/JavascriptModulesPlugin.js +4 -9
  31. package/lib/JsonParser.js +2 -1
  32. package/lib/LibraryTemplatePlugin.js +2 -1
  33. package/lib/LoaderOptionsPlugin.js +2 -1
  34. package/lib/MainTemplate.js +2 -1
  35. package/lib/Module.js +13 -5
  36. package/lib/ModuleBuildError.js +22 -12
  37. package/lib/ModuleDependencyError.js +4 -4
  38. package/lib/ModuleDependencyWarning.js +4 -4
  39. package/lib/ModuleError.js +13 -5
  40. package/lib/ModuleFilenameHelpers.js +20 -8
  41. package/lib/ModuleNotFoundError.js +23 -26
  42. package/lib/ModuleParseError.js +27 -14
  43. package/lib/ModuleWarning.js +13 -7
  44. package/lib/MultiCompiler.js +19 -7
  45. package/lib/MultiModule.js +5 -2
  46. package/lib/NodeStuffPlugin.js +2 -1
  47. package/lib/NormalModule.js +80 -16
  48. package/lib/NormalModuleFactory.js +67 -24
  49. package/lib/OptionsDefaulter.js +7 -3
  50. package/lib/Parser.js +182 -75
  51. package/lib/ParserHelpers.js +6 -3
  52. package/lib/ProgressPlugin.js +17 -2
  53. package/lib/RawModule.js +4 -2
  54. package/lib/RecordIdsPlugin.js +77 -9
  55. package/lib/RemovedPluginError.js +1 -3
  56. package/lib/RequestShortener.js +15 -6
  57. package/lib/RuleSet.js +51 -18
  58. package/lib/RuntimeTemplate.js +21 -10
  59. package/lib/SourceMapDevToolPlugin.js +4 -3
  60. package/lib/Stats.js +74 -31
  61. package/lib/Template.js +7 -4
  62. package/lib/TemplatedPathPlugin.js +6 -3
  63. package/lib/UmdMainTemplatePlugin.js +8 -3
  64. package/lib/UnsupportedFeatureWarning.js +22 -21
  65. package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
  66. package/lib/Watching.js +3 -2
  67. package/lib/WebpackOptionsApply.js +51 -23
  68. package/lib/WebpackOptionsDefaulter.js +15 -9
  69. package/lib/WebpackOptionsValidationError.js +63 -34
  70. package/lib/debug/ProfilingPlugin.js +11 -2
  71. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
  72. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -4
  73. package/lib/dependencies/HarmonyDetectionParserPlugin.js +4 -2
  74. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -3
  75. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -3
  76. package/lib/dependencies/ImportParserPlugin.js +42 -11
  77. package/lib/dependencies/LoaderPlugin.js +12 -7
  78. package/lib/dependencies/LocalModulesHelpers.js +13 -6
  79. package/lib/dependencies/RequireContextPlugin.js +4 -2
  80. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +8 -4
  81. package/lib/dependencies/SystemPlugin.js +6 -6
  82. package/lib/dependencies/WebAssemblyExportImportedDependency.js +29 -0
  83. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  84. package/lib/formatLocation.js +15 -7
  85. package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
  86. package/lib/node/NodeMainTemplatePlugin.js +6 -3
  87. package/lib/node/NodeSourcePlugin.js +9 -5
  88. package/lib/node/NodeWatchFileSystem.js +29 -12
  89. package/lib/node/ReadFileCompileWasmTemplatePlugin.js +11 -2
  90. package/lib/optimize/AggressiveSplittingPlugin.js +12 -6
  91. package/lib/optimize/ConcatenatedModule.js +19 -8
  92. package/lib/optimize/MergeDuplicateChunksPlugin.js +6 -3
  93. package/lib/optimize/ModuleConcatenationPlugin.js +23 -10
  94. package/lib/optimize/OccurrenceOrderPlugin.js +11 -4
  95. package/lib/optimize/RemoveParentModulesPlugin.js +17 -7
  96. package/lib/optimize/SideEffectsFlagPlugin.js +14 -3
  97. package/lib/optimize/SplitChunksPlugin.js +33 -20
  98. package/lib/performance/AssetsOverSizeLimitWarning.js +7 -7
  99. package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -7
  100. package/lib/performance/NoAsyncChunksWarning.js +5 -5
  101. package/lib/util/SortableSet.js +5 -2
  102. package/lib/util/StackedSetMap.js +12 -5
  103. package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +1 -2
  104. package/lib/wasm/WasmFinalizeExportsPlugin.js +66 -0
  105. package/lib/wasm/WasmMainTemplatePlugin.js +87 -43
  106. package/lib/wasm/WebAssemblyGenerator.js +117 -74
  107. package/lib/wasm/WebAssemblyJavascriptGenerator.js +92 -49
  108. package/lib/wasm/WebAssemblyModulesPlugin.js +11 -1
  109. package/lib/wasm/WebAssemblyParser.js +96 -24
  110. package/lib/wasm/WebAssemblyUtils.js +17 -6
  111. package/lib/web/FetchCompileWasmTemplatePlugin.js +13 -1
  112. package/lib/web/JsonpChunkTemplatePlugin.js +7 -0
  113. package/lib/web/JsonpMainTemplate.runtime.js +2 -1
  114. package/lib/web/JsonpMainTemplatePlugin.js +68 -63
  115. package/lib/webpack.js +2 -1
  116. package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
  117. package/package.json +12 -11
  118. package/schemas/WebpackOptions.json +8 -0
@@ -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) this.errors.push(err);
306
- for (const err of cacheModule.warnings) this.warnings.push(err);
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) cb(err);
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) this.warnings.push(err);
374
- else this.errors.push(err);
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, dependencies)
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) cb(err);
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
- if (shouldRecord) this.hooks.recordChunks.call(this.chunks, this.records);
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) this.hooks.recordHash.call(this.records);
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) this.hooks.record.call(this, this.records);
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) newAvailableModules.add(m);
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) module2.id = unusedIds.pop();
1536
- else module2.id = nextFreeModuleId++;
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) chunk.id = unusedIds.pop();
1591
- else chunk.id = nextFreeChunkId++;
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) hash.update(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
- for (const child of this.children) hash.update(child.hash);
1706
- for (const warning of this.warnings) hash.update(`${warning.message}`);
1707
- for (const error of this.errors) hash.update(`${error.message}`);
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) chunkHash.update(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 writeOut();
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) return writeFile();
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) plugin.apply(childCompiler);
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
- if (this.records[relativeCompilerName][compilerIndex])
412
+ }
413
+ if (this.records[relativeCompilerName][compilerIndex]) {
404
414
  childCompiler.records = this.records[relativeCompilerName][compilerIndex];
405
- else this.records[relativeCompilerName].push((childCompiler.records = {}));
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);
@@ -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) if (element) stack.push(element);
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) stack.push(property.value);
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) stack.push(stmt);
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) stack.push(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) stack.push(node.handler.body);
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
  }
@@ -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
- if (this.options.mode) identifier += ` ${this.options.mode}`;
79
- if (!this.options.recursive) identifier += " nonrecursive";
80
- if (this.options.addon) identifier += ` ${this.options.addon}`;
81
- if (this.options.regExp) identifier += ` ${this.options.regExp}`;
82
- if (this.options.include) identifier += ` include: ${this.options.include}`;
83
- if (this.options.exclude) identifier += ` exclude: ${this.options.exclude}`;
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) identifier += " namespace object";
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
- if (this.options.mode) identifier += ` ${this.options.mode}`;
105
- if (!this.options.recursive) identifier += " nonrecursive";
106
- if (this.options.addon)
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
- if (this.options.regExp)
130
+ }
131
+ if (this.options.regExp) {
109
132
  identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
110
- if (this.options.include)
133
+ }
134
+ if (this.options.include) {
111
135
  identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
112
- if (this.options.exclude)
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) identifier += " namespace object";
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) identifier += ` ${this.options.mode}`;
129
- if (this.options.recursive) identifier += " recursive";
130
- if (this.options.addon)
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
- if (this.options.regExp)
165
+ }
166
+ if (this.options.regExp) {
133
167
  identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
134
- if (this.options.include)
168
+ }
169
+ if (this.options.include) {
135
170
  identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
136
- if (this.options.exclude)
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)) chunkName += "[index]";
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) return 9;
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
- if (hasNamespace && !hasNonHarmony && !hasNamed) return 9;
287
- if (!hasNamespace && !hasNonHarmony && hasNamed) return 3;
288
- if (!hasNamespace && !hasNonHarmony && !hasNamed) return 9;
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) return "__webpack_require__(id)";
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
- loaders = request.substr(0, idx + 1);
70
+ let loadersRequest = request.substr(0, idx + 1);
71
71
  let i;
72
- for (i = 0; i < loaders.length && loaders[i] === "!"; i++) {
72
+ for (
73
+ i = 0;
74
+ i < loadersRequest.length && loadersRequest[i] === "!";
75
+ i++
76
+ ) {
73
77
  loadersPrefix += "!";
74
78
  }
75
- loaders = loaders
79
+ loadersRequest = loadersRequest
76
80
  .substr(i)
77
81
  .replace(/!+$/, "")
78
82
  .replace(/!!+/g, "!");
79
- if (loaders === "") loaders = [];
80
- else loaders = loaders.split("!");
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 callback();
232
+ } else {
233
+ callback();
234
+ }
226
235
  });
227
- } else callback();
236
+ } else {
237
+ callback();
238
+ }
228
239
  },
229
240
  (err, result) => {
230
241
  if (err) return callback(err);