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
@@ -0,0 +1,29 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const DependencyReference = require("./DependencyReference");
8
+ const ModuleDependency = require("./ModuleDependency");
9
+
10
+ class WebAssemblyExportImportedDependency extends ModuleDependency {
11
+ constructor(exportName, request, name) {
12
+ super(request);
13
+ /** @type {string} */
14
+ this.exportName = exportName;
15
+ /** @type {string} */
16
+ this.name = name;
17
+ }
18
+
19
+ getReference() {
20
+ if (!this.module) return null;
21
+ return new DependencyReference(this.module, [this.name], false);
22
+ }
23
+
24
+ get type() {
25
+ return "wasm export import";
26
+ }
27
+ }
28
+
29
+ module.exports = WebAssemblyExportImportedDependency;
@@ -32,7 +32,7 @@ class WebAssemblyImportDependency extends ModuleDependency {
32
32
  ) {
33
33
  return [
34
34
  new UnsupportedWebAssemblyFeatureError(
35
- `Import with ${
35
+ `Import "${this.name}" from "${this.request}" with ${
36
36
  this.onlyDirectImport
37
37
  } can only be used for direct wasm to wasm dependencies`
38
38
  )
@@ -14,11 +14,15 @@ const formatPosition = pos => {
14
14
  case "number":
15
15
  return `${pos}`;
16
16
  case "object":
17
- if (typeof pos.line === "number" && typeof pos.column === "number")
17
+ if (typeof pos.line === "number" && typeof pos.column === "number") {
18
18
  return `${pos.line}:${pos.column}`;
19
- else if (typeof pos.line === "number") return `${pos.line}:?`;
20
- else if (typeof pos.index === "number") return `+${pos.index}`;
21
- else return "";
19
+ } else if (typeof pos.line === "number") {
20
+ return `${pos.line}:?`;
21
+ } else if (typeof pos.index === "number") {
22
+ return `+${pos.index}`;
23
+ } else {
24
+ return "";
25
+ }
22
26
  default:
23
27
  return "";
24
28
  }
@@ -39,11 +43,15 @@ const formatLocation = loc => {
39
43
  typeof loc.end.line === "number" &&
40
44
  typeof loc.end.column === "number" &&
41
45
  loc.start.line === loc.end.line
42
- )
46
+ ) {
43
47
  return `${formatPosition(loc.start)}-${loc.end.column}`;
44
- return `${formatPosition(loc.start)}-${formatPosition(loc.end)}`;
48
+ } else {
49
+ return `${formatPosition(loc.start)}-${formatPosition(loc.end)}`;
50
+ }
51
+ }
52
+ if (loc.start) {
53
+ return formatPosition(loc.start);
45
54
  }
46
- if (loc.start) return formatPosition(loc.start);
47
55
  return formatPosition(loc);
48
56
  default:
49
57
  return "";
@@ -10,7 +10,7 @@ module.exports = function() {
10
10
  require("fs").readFile(filename, "utf-8", function(err, content) {
11
11
  if (err) {
12
12
  if ($require$.onError) return $require$.oe(err);
13
- else throw err;
13
+ throw err;
14
14
  }
15
15
  var chunk = {};
16
16
  require("vm").runInThisContext(
@@ -116,10 +116,11 @@ module.exports = class NodeMainTemplatePlugin {
116
116
  hashWithLength: length => {
117
117
  const shortChunkHashMap = {};
118
118
  for (const chunkId of Object.keys(chunkMaps.hash)) {
119
- if (typeof chunkMaps.hash[chunkId] === "string")
119
+ if (typeof chunkMaps.hash[chunkId] === "string") {
120
120
  shortChunkHashMap[chunkId] = chunkMaps.hash[
121
121
  chunkId
122
122
  ].substr(0, length);
123
+ }
123
124
  }
124
125
  return `" + ${JSON.stringify(
125
126
  shortChunkHashMap
@@ -201,10 +202,11 @@ module.exports = class NodeMainTemplatePlugin {
201
202
  hashWithLength: length => {
202
203
  const shortChunkHashMap = {};
203
204
  for (const chunkId of Object.keys(chunkMaps.hash)) {
204
- if (typeof chunkMaps.hash[chunkId] === "string")
205
+ if (typeof chunkMaps.hash[chunkId] === "string") {
205
206
  shortChunkHashMap[chunkId] = chunkMaps.hash[
206
207
  chunkId
207
208
  ].substr(0, length);
209
+ }
208
210
  }
209
211
  return `" + ${JSON.stringify(
210
212
  shortChunkHashMap
@@ -278,11 +280,12 @@ module.exports = class NodeMainTemplatePlugin {
278
280
  hashWithLength: length => {
279
281
  const shortChunkHashMap = {};
280
282
  for (const chunkId of Object.keys(chunkMaps.hash)) {
281
- if (typeof chunkMaps.hash[chunkId] === "string")
283
+ if (typeof chunkMaps.hash[chunkId] === "string") {
282
284
  shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(
283
285
  0,
284
286
  length
285
287
  );
288
+ }
286
289
  }
287
290
  return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
288
291
  },
@@ -13,22 +13,26 @@ module.exports = class NodeSourcePlugin {
13
13
  }
14
14
  apply(compiler) {
15
15
  const options = this.options;
16
- if (options === false)
16
+ if (options === false) {
17
17
  // allow single kill switch to turn off this plugin
18
18
  return;
19
+ }
19
20
 
20
21
  const getPathToModule = (module, type) => {
21
22
  if (type === true || (type === undefined && nodeLibsBrowser[module])) {
22
- if (!nodeLibsBrowser[module])
23
+ if (!nodeLibsBrowser[module]) {
23
24
  throw new Error(
24
25
  `No browser version for node.js core module ${module} available`
25
26
  );
27
+ }
26
28
  return nodeLibsBrowser[module];
27
29
  } else if (type === "mock") {
28
30
  return require.resolve(`node-libs-browser/mock/${module}`);
29
31
  } else if (type === "empty") {
30
32
  return require.resolve("node-libs-browser/mock/empty");
31
- } else return module;
33
+ } else {
34
+ return module;
35
+ }
32
36
  };
33
37
 
34
38
  const addExpression = (parser, name, module, type, suffix) => {
@@ -58,9 +62,9 @@ module.exports = class NodeSourcePlugin {
58
62
  if (parserOptions.node === false) return;
59
63
 
60
64
  let localOptions = options;
61
- if (parserOptions.node)
65
+ if (parserOptions.node) {
62
66
  localOptions = Object.assign({}, localOptions, parserOptions.node);
63
-
67
+ }
64
68
  if (localOptions.global) {
65
69
  parser.hooks.expression
66
70
  .for("global")
@@ -17,22 +17,33 @@ class NodeWatchFileSystem {
17
17
  }
18
18
 
19
19
  watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
20
- if (!Array.isArray(files)) throw new Error("Invalid arguments: 'files'");
21
- if (!Array.isArray(dirs)) throw new Error("Invalid arguments: 'dirs'");
22
- if (!Array.isArray(missing))
20
+ if (!Array.isArray(files)) {
21
+ throw new Error("Invalid arguments: 'files'");
22
+ }
23
+ if (!Array.isArray(dirs)) {
24
+ throw new Error("Invalid arguments: 'dirs'");
25
+ }
26
+ if (!Array.isArray(missing)) {
23
27
  throw new Error("Invalid arguments: 'missing'");
24
- if (typeof callback !== "function")
28
+ }
29
+ if (typeof callback !== "function") {
25
30
  throw new Error("Invalid arguments: 'callback'");
26
- if (typeof startTime !== "number" && startTime)
31
+ }
32
+ if (typeof startTime !== "number" && startTime) {
27
33
  throw new Error("Invalid arguments: 'startTime'");
28
- if (typeof options !== "object")
34
+ }
35
+ if (typeof options !== "object") {
29
36
  throw new Error("Invalid arguments: 'options'");
30
- if (typeof callbackUndelayed !== "function" && callbackUndelayed)
37
+ }
38
+ if (typeof callbackUndelayed !== "function" && callbackUndelayed) {
31
39
  throw new Error("Invalid arguments: 'callbackUndelayed'");
40
+ }
32
41
  const oldWatcher = this.watcher;
33
42
  this.watcher = new Watchpack(options);
34
43
 
35
- if (callbackUndelayed) this.watcher.once("change", callbackUndelayed);
44
+ if (callbackUndelayed) {
45
+ this.watcher.once("change", callbackUndelayed);
46
+ }
36
47
 
37
48
  this.watcher.once("aggregated", (changes, removals) => {
38
49
  changes = changes.concat(removals);
@@ -68,12 +79,18 @@ class NodeWatchFileSystem {
68
79
  }
69
80
  },
70
81
  getFileTimestamps: () => {
71
- if (this.watcher) return objectToMap(this.watcher.getTimes());
72
- else return new Map();
82
+ if (this.watcher) {
83
+ return objectToMap(this.watcher.getTimes());
84
+ } else {
85
+ return new Map();
86
+ }
73
87
  },
74
88
  getContextTimestamps: () => {
75
- if (this.watcher) return objectToMap(this.watcher.getTimes());
76
- else return new Map();
89
+ if (this.watcher) {
90
+ return objectToMap(this.watcher.getTimes());
91
+ } else {
92
+ return new Map();
93
+ }
77
94
  }
78
95
  };
79
96
  }
@@ -8,6 +8,10 @@ const Template = require("../Template");
8
8
  const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
9
9
 
10
10
  class ReadFileCompileWasmTemplatePlugin {
11
+ constructor(options) {
12
+ this.options = options || {};
13
+ }
14
+
11
15
  apply(compiler) {
12
16
  compiler.hooks.thisCompilation.tap(
13
17
  "ReadFileCompileWasmTemplatePlugin",
@@ -40,8 +44,13 @@ class ReadFileCompileWasmTemplatePlugin {
40
44
  ]);
41
45
 
42
46
  const plugin = new WasmMainTemplatePlugin(
43
- generateLoadBinaryCode,
44
- false
47
+ Object.assign(
48
+ {
49
+ generateLoadBinaryCode,
50
+ supportsStreaming: false
51
+ },
52
+ this.options
53
+ )
45
54
  );
46
55
  plugin.apply(compilation.mainTemplate);
47
56
  }
@@ -26,14 +26,18 @@ class AggressiveSplittingPlugin {
26
26
  validateOptions(schema, options || {}, "Aggressive Splitting Plugin");
27
27
 
28
28
  this.options = options || {};
29
- if (typeof this.options.minSize !== "number")
29
+ if (typeof this.options.minSize !== "number") {
30
30
  this.options.minSize = 30 * 1024;
31
- if (typeof this.options.maxSize !== "number")
31
+ }
32
+ if (typeof this.options.maxSize !== "number") {
32
33
  this.options.maxSize = 50 * 1024;
33
- if (typeof this.options.chunkOverhead !== "number")
34
+ }
35
+ if (typeof this.options.chunkOverhead !== "number") {
34
36
  this.options.chunkOverhead = 0;
35
- if (typeof this.options.entryChunkMultiplicator !== "number")
37
+ }
38
+ if (typeof this.options.entryChunkMultiplicator !== "number") {
36
39
  this.options.entryChunkMultiplicator = 1;
40
+ }
37
41
  }
38
42
  apply(compiler) {
39
43
  compiler.hooks.thisCompilation.tap(
@@ -82,8 +86,9 @@ class AggressiveSplittingPlugin {
82
86
 
83
87
  const applySplit = splitData => {
84
88
  // Cannot split if id is already taken
85
- if (splitData.id !== undefined && usedIds.has(splitData.id))
89
+ if (splitData.id !== undefined && usedIds.has(splitData.id)) {
86
90
  return false;
91
+ }
87
92
 
88
93
  // Get module objects from names
89
94
  const selectedModules = splitData.modules.map(name =>
@@ -188,8 +193,9 @@ class AggressiveSplittingPlugin {
188
193
  for (let k = 0; k < modules.length; k++) {
189
194
  const module = modules[k];
190
195
  const newSize = selectedModulesSize + module.size();
191
- if (newSize > maxSize && selectedModulesSize >= minSize)
196
+ if (newSize > maxSize && selectedModulesSize >= minSize) {
192
197
  break;
198
+ }
193
199
  selectedModulesSize = newSize;
194
200
  selectedModules.push(module);
195
201
  }
@@ -114,20 +114,22 @@ const getFinalName = (
114
114
  case "concatenated": {
115
115
  const directExport = info.exportMap.get(exportName);
116
116
  if (directExport) {
117
- if (exportName === true)
117
+ if (exportName === true) {
118
118
  ensureNsObjSource(
119
119
  info,
120
120
  moduleToInfoMap,
121
121
  requestShortener,
122
122
  strictHarmonyModule
123
123
  );
124
+ }
124
125
  const name = info.internalNames.get(directExport);
125
- if (!name)
126
+ if (!name) {
126
127
  throw new Error(
127
128
  `The export "${directExport}" in "${info.module.readableIdentifier(
128
129
  requestShortener
129
130
  )}" has no internal name`
130
131
  );
132
+ }
131
133
  return name;
132
134
  }
133
135
  const reexport = info.reexportMap.get(exportName);
@@ -325,13 +327,18 @@ class ConcatenatedModule extends Module {
325
327
  }
326
328
  }
327
329
  // populate warnings
328
- for (const warning of m.warnings) this.warnings.push(warning);
330
+ for (const warning of m.warnings) {
331
+ this.warnings.push(warning);
332
+ }
329
333
  // populate errors
330
- for (const error of m.errors) this.errors.push(error);
334
+ for (const error of m.errors) {
335
+ this.errors.push(error);
336
+ }
331
337
 
332
338
  if (m.buildInfo.assets) {
333
- if (this.buildInfo.assets === undefined)
339
+ if (this.buildInfo.assets === undefined) {
334
340
  this.buildInfo.assets = Object.create(null);
341
+ }
335
342
  Object.assign(this.buildInfo.assets, m.buildInfo.assets);
336
343
  }
337
344
  }
@@ -450,10 +457,13 @@ class ConcatenatedModule extends Module {
450
457
  const reexportMap = new Map();
451
458
  for (const dep of info.module.dependencies) {
452
459
  if (dep instanceof HarmonyExportSpecifierDependency) {
453
- if (!exportMap.has(dep.name)) exportMap.set(dep.name, dep.id);
460
+ if (!exportMap.has(dep.name)) {
461
+ exportMap.set(dep.name, dep.id);
462
+ }
454
463
  } else if (dep instanceof HarmonyExportExpressionDependency) {
455
- if (!exportMap.has("default"))
464
+ if (!exportMap.has("default")) {
456
465
  exportMap.set("default", "__WEBPACK_MODULE_DEFAULT_EXPORT__");
466
+ }
457
467
  } else if (
458
468
  dep instanceof HarmonyExportImportedSpecifierDependency
459
469
  ) {
@@ -478,8 +488,9 @@ class ConcatenatedModule extends Module {
478
488
  }
479
489
  } else if (importedModule) {
480
490
  for (const name of importedModule.buildMeta.providedExports) {
481
- if (dep.activeExports.has(name) || name === "default")
491
+ if (dep.activeExports.has(name) || name === "default") {
482
492
  continue;
493
+ }
483
494
  if (!reexportMap.has(name)) {
484
495
  reexportMap.set(name, {
485
496
  module: importedModule,
@@ -31,8 +31,9 @@ class MergeDuplicateChunksPlugin {
31
31
  !notDuplicates.has(dup)
32
32
  ) {
33
33
  // delay allocating the new Set until here, reduce memory pressure
34
- if (possibleDuplicates === undefined)
34
+ if (possibleDuplicates === undefined) {
35
35
  possibleDuplicates = new Set();
36
+ }
36
37
  possibleDuplicates.add(dup);
37
38
  }
38
39
  }
@@ -42,8 +43,9 @@ class MergeDuplicateChunksPlugin {
42
43
  // validate existing possible duplicates
43
44
  for (const dup of possibleDuplicates) {
44
45
  // remove possible duplicate when module is not contained
45
- if (!dup.containsModule(module))
46
+ if (!dup.containsModule(module)) {
46
47
  possibleDuplicates.delete(dup);
48
+ }
47
49
  }
48
50
  // when all chunks has been removed we can break here
49
51
  if (possibleDuplicates.size === 0) break;
@@ -58,8 +60,9 @@ class MergeDuplicateChunksPlugin {
58
60
  for (const otherChunk of possibleDuplicates) {
59
61
  if (otherChunk.hasRuntime() !== chunk.hasRuntime()) continue;
60
62
  // merge them
61
- if (chunk.integrate(otherChunk, "duplicate"))
63
+ if (chunk.integrate(otherChunk, "duplicate")) {
62
64
  chunks.splice(chunks.indexOf(otherChunk), 1);
65
+ }
63
66
  }
64
67
  }
65
68
 
@@ -172,19 +172,21 @@ class ModuleConcatenationPlugin {
172
172
  )
173
173
  .sort();
174
174
  const explanations = Array.from(importingExplanations).sort();
175
- if (names.length > 0 && explanations.length === 0)
175
+ if (names.length > 0 && explanations.length === 0) {
176
176
  return `Module is referenced from these modules with unsupported syntax: ${names.join(
177
177
  ", "
178
178
  )}`;
179
- else if (names.length === 0 && explanations.length > 0)
179
+ } else if (names.length === 0 && explanations.length > 0) {
180
180
  return `Module is referenced by: ${explanations.join(
181
181
  ", "
182
182
  )}`;
183
- else if (names.length > 0 && explanations.length > 0)
183
+ } else if (names.length > 0 && explanations.length > 0) {
184
184
  return `Module is referenced from these modules with unsupported syntax: ${names.join(
185
185
  ", "
186
186
  )} and by: ${explanations.join(", ")}`;
187
- else return "Module is referenced in a unsupported way";
187
+ } else {
188
+ return "Module is referenced in a unsupported way";
189
+ }
188
190
  });
189
191
  continue;
190
192
  }
@@ -226,8 +228,9 @@ class ModuleConcatenationPlugin {
226
228
  if (!currentConfiguration.isEmpty()) {
227
229
  concatConfigurations.push(currentConfiguration);
228
230
  for (const module of currentConfiguration.getModules()) {
229
- if (module !== currentConfiguration.rootModule)
231
+ if (module !== currentConfiguration.rootModule) {
230
232
  usedAsInner.add(module);
233
+ }
231
234
  }
232
235
  }
233
236
  }
@@ -250,13 +253,13 @@ class ModuleConcatenationPlugin {
250
253
  newModule.optimizationBailout.push(requestShortener => {
251
254
  const reason = getBailoutReason(warning[0], requestShortener);
252
255
  const reasonWithPrefix = reason ? ` (<- ${reason})` : "";
253
- if (warning[0] === warning[1])
256
+ if (warning[0] === warning[1]) {
254
257
  return formatBailoutReason(
255
258
  `Cannot concat with ${warning[0].readableIdentifier(
256
259
  requestShortener
257
260
  )}${reasonWithPrefix}`
258
261
  );
259
- else
262
+ } else {
260
263
  return formatBailoutReason(
261
264
  `Cannot concat with ${warning[0].readableIdentifier(
262
265
  requestShortener
@@ -264,6 +267,7 @@ class ModuleConcatenationPlugin {
264
267
  requestShortener
265
268
  )}${reasonWithPrefix}`
266
269
  );
270
+ }
267
271
  });
268
272
  }
269
273
  const chunks = concatConfiguration.rootModule.getChunks();
@@ -276,12 +280,19 @@ class ModuleConcatenationPlugin {
276
280
  for (const chunk of chunks) {
277
281
  chunk.addModule(newModule);
278
282
  newModule.addChunk(chunk);
279
- if (chunk.entryModule === concatConfiguration.rootModule)
283
+ if (chunk.entryModule === concatConfiguration.rootModule) {
280
284
  chunk.entryModule = newModule;
285
+ }
281
286
  }
282
287
  compilation.modules.push(newModule);
283
288
  for (const reason of newModule.reasons) {
284
- reason.dependency.module = newModule;
289
+ if (reason.dependency.module === concatConfiguration.rootModule)
290
+ reason.dependency.module = newModule;
291
+ if (
292
+ reason.dependency.redirectedModule ===
293
+ concatConfiguration.rootModule
294
+ )
295
+ reason.dependency.redirectedModule = newModule;
285
296
  }
286
297
  // TODO: remove when LTS node version contains fixed v8 version
287
298
  // @see https://github.com/webpack/webpack/pull/6613
@@ -293,7 +304,9 @@ class ModuleConcatenationPlugin {
293
304
  let reasons = dep.module.reasons;
294
305
  for (let j = 0; j < reasons.length; j++) {
295
306
  let reason = reasons[j];
296
- if (reason.dependency === dep) reason.module = newModule;
307
+ if (reason.dependency === dep) {
308
+ reason.module = newModule;
309
+ }
297
310
  }
298
311
  }
299
312
  }
@@ -36,15 +36,22 @@ class OccurrenceOrderPlugin {
36
36
  }
37
37
 
38
38
  const countOccursInEntry = (sum, r) => {
39
- if (!r.module) return sum;
39
+ if (!r.module) {
40
+ return sum;
41
+ }
40
42
  return sum + initialChunkChunkMap.get(r.module);
41
43
  };
42
44
  const countOccurs = (sum, r) => {
43
- if (!r.module) return sum;
45
+ if (!r.module) {
46
+ return sum;
47
+ }
44
48
  let factor = 1;
45
- if (typeof r.dependency.getNumberOfIdOccurrences === "function")
49
+ if (typeof r.dependency.getNumberOfIdOccurrences === "function") {
46
50
  factor = r.dependency.getNumberOfIdOccurrences();
47
- if (factor === 0) return sum;
51
+ }
52
+ if (factor === 0) {
53
+ return sum;
54
+ }
48
55
  return sum + factor * r.module.getNumberOfChunks();
49
56
  };
50
57
 
@@ -34,7 +34,9 @@ class RemoveParentModulesPlugin {
34
34
  for (const chunkGroup of compilation.entrypoints.values()) {
35
35
  // initialize available modules for chunks without parents
36
36
  availableModulesMap.set(chunkGroup, new Set());
37
- for (const child of chunkGroup.childrenIterable) queue.enqueue(child);
37
+ for (const child of chunkGroup.childrenIterable) {
38
+ queue.enqueue(child);
39
+ }
38
40
  }
39
41
 
40
42
  while (queue.length > 0) {
@@ -49,8 +51,9 @@ class RemoveParentModulesPlugin {
49
51
  // if we have not own info yet: create new entry
50
52
  availableModules = new Set(availableModulesInParent);
51
53
  for (const chunk of parent.chunks) {
52
- for (const m of chunk.modulesIterable)
54
+ for (const m of chunk.modulesIterable) {
53
55
  availableModules.add(m);
56
+ }
54
57
  }
55
58
  availableModulesMap.set(chunkGroup, availableModules);
56
59
  changed = true;
@@ -69,8 +72,9 @@ class RemoveParentModulesPlugin {
69
72
  }
70
73
  if (changed) {
71
74
  // if something changed: enqueue our children
72
- for (const child of chunkGroup.childrenIterable)
75
+ for (const child of chunkGroup.childrenIterable) {
73
76
  queue.enqueue(child);
77
+ }
74
78
  }
75
79
  }
76
80
 
@@ -88,11 +92,17 @@ class RemoveParentModulesPlugin {
88
92
  const numberOfModules = chunk.getNumberOfModules();
89
93
  const toRemove = new Set();
90
94
  if (numberOfModules < availableModules.size) {
91
- for (const m of chunk.modulesIterable)
92
- if (availableModules.has(m)) toRemove.add(m);
95
+ for (const m of chunk.modulesIterable) {
96
+ if (availableModules.has(m)) {
97
+ toRemove.add(m);
98
+ }
99
+ }
93
100
  } else {
94
- for (const m of availableModules)
95
- if (chunk.containsModule(m)) toRemove.add(m);
101
+ for (const m of availableModules) {
102
+ if (chunk.containsModule(m)) {
103
+ toRemove.add(m);
104
+ }
105
+ }
96
106
  }
97
107
  for (const module of toRemove) {
98
108
  module.rewriteChunkInReasons(
@@ -41,10 +41,11 @@ class SideEffectsFlagPlugin {
41
41
  return module;
42
42
  });
43
43
  nmf.hooks.module.tap("SideEffectsFlagPlugin", (module, data) => {
44
- if (data.settings.sideEffects === false)
44
+ if (data.settings.sideEffects === false) {
45
45
  module.factoryMeta.sideEffectFree = true;
46
- else if (data.settings.sideEffects === true)
46
+ } else if (data.settings.sideEffects === true) {
47
47
  module.factoryMeta.sideEffectFree = false;
48
+ }
48
49
  });
49
50
  });
50
51
  compiler.hooks.compilation.tap("SideEffectsFlagPlugin", compilation => {
@@ -105,6 +106,7 @@ class SideEffectsFlagPlugin {
105
106
  for (const pair of reexportMaps) {
106
107
  const module = pair[0];
107
108
  const map = pair[1];
109
+ let newReasons = undefined;
108
110
  for (let i = 0; i < module.reasons.length; i++) {
109
111
  const reason = module.reasons[i];
110
112
  const dep = reason.dependency;
@@ -116,7 +118,6 @@ class SideEffectsFlagPlugin {
116
118
  if (mapping) {
117
119
  dep.redirectedModule = mapping.module;
118
120
  dep.redirectedId = mapping.exportName;
119
- module.reasons.splice(i--, 1);
120
121
  mapping.module.addReason(
121
122
  reason.module,
122
123
  dep,
@@ -125,8 +126,18 @@ class SideEffectsFlagPlugin {
125
126
  " (skipped side-effect-free modules)"
126
127
  : "(skipped side-effect-free modules)"
127
128
  );
129
+ // removing the currect reason, by not adding it to the newReasons array
130
+ // lazily create the newReasons array
131
+ if (newReasons === undefined) {
132
+ newReasons = i === 0 ? [] : module.reasons.slice(0, i);
133
+ }
134
+ continue;
128
135
  }
129
136
  }
137
+ if (newReasons !== undefined) newReasons.push(reason);
138
+ }
139
+ if (newReasons !== undefined) {
140
+ module.reasons = newReasons;
130
141
  }
131
142
  }
132
143
  }