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.
Files changed (87) hide show
  1. package/lib/AmdMainTemplatePlugin.js +3 -1
  2. package/lib/BannerPlugin.js +3 -1
  3. package/lib/BasicEvaluatedExpression.js +14 -11
  4. package/lib/CachePlugin.js +12 -5
  5. package/lib/Chunk.js +44 -16
  6. package/lib/ChunkGroup.js +13 -5
  7. package/lib/Compilation.js +70 -28
  8. package/lib/Compiler.js +22 -10
  9. package/lib/ConstPlugin.js +25 -9
  10. package/lib/ContextModule.js +88 -36
  11. package/lib/ContextModuleFactory.js +18 -7
  12. package/lib/ContextReplacementPlugin.js +14 -7
  13. package/lib/DefinePlugin.js +15 -6
  14. package/lib/DependenciesBlock.js +3 -1
  15. package/lib/DependenciesBlockVariable.js +2 -1
  16. package/lib/DllPlugin.js +4 -2
  17. package/lib/DynamicEntryPlugin.js +4 -2
  18. package/lib/ErrorHelpers.js +5 -2
  19. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  20. package/lib/FlagDependencyUsagePlugin.js +11 -5
  21. package/lib/FunctionModuleTemplatePlugin.js +8 -6
  22. package/lib/HotModuleReplacement.runtime.js +7 -3
  23. package/lib/HotModuleReplacementPlugin.js +13 -6
  24. package/lib/JavascriptGenerator.js +2 -1
  25. package/lib/JavascriptModulesPlugin.js +4 -9
  26. package/lib/JsonParser.js +2 -1
  27. package/lib/LibraryTemplatePlugin.js +2 -1
  28. package/lib/LoaderOptionsPlugin.js +2 -1
  29. package/lib/MainTemplate.js +2 -1
  30. package/lib/Module.js +9 -5
  31. package/lib/ModuleFilenameHelpers.js +20 -8
  32. package/lib/MultiCompiler.js +19 -7
  33. package/lib/MultiModule.js +5 -2
  34. package/lib/NodeStuffPlugin.js +2 -1
  35. package/lib/NormalModule.js +11 -4
  36. package/lib/NormalModuleFactory.js +30 -12
  37. package/lib/OptionsDefaulter.js +7 -3
  38. package/lib/Parser.js +137 -59
  39. package/lib/ParserHelpers.js +5 -2
  40. package/lib/ProgressPlugin.js +2 -2
  41. package/lib/RawModule.js +4 -2
  42. package/lib/RecordIdsPlugin.js +11 -7
  43. package/lib/RequestShortener.js +13 -6
  44. package/lib/RuleSet.js +39 -18
  45. package/lib/RuntimeTemplate.js +21 -10
  46. package/lib/SourceMapDevToolPlugin.js +4 -3
  47. package/lib/Stats.js +64 -28
  48. package/lib/Template.js +4 -2
  49. package/lib/TemplatedPathPlugin.js +6 -3
  50. package/lib/UmdMainTemplatePlugin.js +8 -3
  51. package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
  52. package/lib/Watching.js +3 -2
  53. package/lib/WebpackOptionsApply.js +32 -16
  54. package/lib/WebpackOptionsDefaulter.js +7 -4
  55. package/lib/WebpackOptionsValidationError.js +48 -19
  56. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
  57. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +6 -3
  58. package/lib/dependencies/HarmonyDetectionParserPlugin.js +4 -2
  59. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -3
  60. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -3
  61. package/lib/dependencies/ImportParserPlugin.js +2 -1
  62. package/lib/dependencies/LoaderPlugin.js +12 -7
  63. package/lib/dependencies/LocalModulesHelpers.js +13 -6
  64. package/lib/dependencies/RequireContextPlugin.js +4 -2
  65. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +8 -4
  66. package/lib/formatLocation.js +15 -7
  67. package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
  68. package/lib/node/NodeMainTemplatePlugin.js +6 -3
  69. package/lib/node/NodeSourcePlugin.js +9 -5
  70. package/lib/node/NodeWatchFileSystem.js +29 -12
  71. package/lib/optimize/AggressiveSplittingPlugin.js +12 -6
  72. package/lib/optimize/ConcatenatedModule.js +19 -8
  73. package/lib/optimize/MergeDuplicateChunksPlugin.js +6 -3
  74. package/lib/optimize/ModuleConcatenationPlugin.js +23 -10
  75. package/lib/optimize/OccurrenceOrderPlugin.js +11 -4
  76. package/lib/optimize/RemoveParentModulesPlugin.js +17 -7
  77. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  78. package/lib/optimize/SplitChunksPlugin.js +33 -20
  79. package/lib/util/SortableSet.js +5 -2
  80. package/lib/util/StackedSetMap.js +12 -5
  81. package/lib/wasm/WasmMainTemplatePlugin.js +4 -2
  82. package/lib/wasm/WebAssemblyGenerator.js +7 -0
  83. package/lib/web/JsonpMainTemplate.runtime.js +2 -1
  84. package/lib/web/JsonpMainTemplatePlugin.js +2 -1
  85. package/lib/webpack.js +2 -1
  86. package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
  87. package/package.json +9 -9
@@ -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);
@@ -60,12 +60,15 @@ class ContextReplacementPlugin {
60
60
  cmf.hooks.beforeResolve.tap("ContextReplacementPlugin", result => {
61
61
  if (!result) return;
62
62
  if (resourceRegExp.test(result.request)) {
63
- if (typeof newContentResource !== "undefined")
63
+ if (typeof newContentResource !== "undefined") {
64
64
  result.request = newContentResource;
65
- if (typeof newContentRecursive !== "undefined")
65
+ }
66
+ if (typeof newContentRecursive !== "undefined") {
66
67
  result.recursive = newContentRecursive;
67
- if (typeof newContentRegExp !== "undefined")
68
+ }
69
+ if (typeof newContentRegExp !== "undefined") {
68
70
  result.regExp = newContentRegExp;
71
+ }
69
72
  if (typeof newContentCallback === "function") {
70
73
  newContentCallback(result);
71
74
  } else {
@@ -79,16 +82,20 @@ class ContextReplacementPlugin {
79
82
  cmf.hooks.afterResolve.tap("ContextReplacementPlugin", result => {
80
83
  if (!result) return;
81
84
  if (resourceRegExp.test(result.resource)) {
82
- if (typeof newContentResource !== "undefined")
85
+ if (typeof newContentResource !== "undefined") {
83
86
  result.resource = path.resolve(result.resource, newContentResource);
84
- if (typeof newContentRecursive !== "undefined")
87
+ }
88
+ if (typeof newContentRecursive !== "undefined") {
85
89
  result.recursive = newContentRecursive;
86
- if (typeof newContentRegExp !== "undefined")
90
+ }
91
+ if (typeof newContentRegExp !== "undefined") {
87
92
  result.regExp = newContentRegExp;
88
- if (typeof newContentCreateContextMap === "function")
93
+ }
94
+ if (typeof newContentCreateContextMap === "function") {
89
95
  result.resolveDependencies = createResolveDependenciesFromContextMap(
90
96
  newContentCreateContextMap
91
97
  );
98
+ }
92
99
  if (typeof newContentCallback === "function") {
93
100
  const origResource = result.resource;
94
101
  newContentCallback(result);
@@ -23,13 +23,22 @@ const stringifyObj = obj => {
23
23
  };
24
24
 
25
25
  const toCode = code => {
26
- if (code === null) return "null";
27
- else if (code === undefined) return "undefined";
28
- else if (code instanceof RegExp && code.toString) return code.toString();
29
- else if (typeof code === "function" && code.toString)
26
+ if (code === null) {
27
+ return "null";
28
+ }
29
+ if (code === undefined) {
30
+ return "undefined";
31
+ }
32
+ if (code instanceof RegExp && code.toString) {
33
+ return code.toString();
34
+ }
35
+ if (typeof code === "function" && code.toString) {
30
36
  return "(" + code.toString() + ")";
31
- else if (typeof code === "object") return stringifyObj(code);
32
- else return code + "";
37
+ }
38
+ if (typeof code === "object") {
39
+ return stringifyObj(code);
40
+ }
41
+ return code + "";
33
42
  };
34
43
 
35
44
  class DefinePlugin {
@@ -40,7 +40,9 @@ class DependenciesBlock {
40
40
 
41
41
  removeDependency(dependency) {
42
42
  const idx = this.dependencies.indexOf(dependency);
43
- if (idx >= 0) this.dependencies.splice(idx, 1);
43
+ if (idx >= 0) {
44
+ this.dependencies.splice(idx, 1);
45
+ }
44
46
  }
45
47
 
46
48
  updateHash(hash) {
@@ -25,8 +25,9 @@ class DependenciesBlockVariable {
25
25
  const source = new ReplaceSource(new RawSource(this.expression));
26
26
  for (const dep of this.dependencies) {
27
27
  const template = dependencyTemplates.get(dep.constructor);
28
- if (!template)
28
+ if (!template) {
29
29
  throw new Error(`No template for dependency: ${dep.constructor.name}`);
30
+ }
30
31
  template.apply(dep, source, runtimeTemplate, dependencyTemplates);
31
32
  }
32
33
  return source;
package/lib/DllPlugin.js CHANGED
@@ -20,8 +20,10 @@ class DllPlugin {
20
20
  apply(compiler) {
21
21
  compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => {
22
22
  const itemToPlugin = (item, name) => {
23
- if (Array.isArray(item)) return new DllEntryPlugin(context, item, name);
24
- else throw new Error("DllPlugin: supply an Array as entry");
23
+ if (Array.isArray(item)) {
24
+ return new DllEntryPlugin(context, item, name);
25
+ }
26
+ throw new Error("DllPlugin: supply an Array as entry");
25
27
  };
26
28
  if (typeof entry === "object" && !Array.isArray(entry)) {
27
29
  Object.keys(entry).forEach(name => {
@@ -65,7 +65,9 @@ class DynamicEntryPlugin {
65
65
  module.exports = DynamicEntryPlugin;
66
66
 
67
67
  DynamicEntryPlugin.createDependency = (entry, name) => {
68
- if (Array.isArray(entry))
68
+ if (Array.isArray(entry)) {
69
69
  return MultiEntryPlugin.createDependency(entry, name);
70
- else return SingleEntryPlugin.createDependency(entry, name);
70
+ } else {
71
+ return SingleEntryPlugin.createDependency(entry, name);
72
+ }
71
73
  };
@@ -10,8 +10,11 @@ const webpackOptionsFlag = "WEBPACK_OPTIONS";
10
10
 
11
11
  exports.cutOffByFlag = (stack, flag) => {
12
12
  stack = stack.split("\n");
13
- for (let i = 0; i < stack.length; i++)
14
- if (stack[i].includes(flag)) stack.length = i;
13
+ for (let i = 0; i < stack.length; i++) {
14
+ if (stack[i].includes(flag)) {
15
+ stack.length = i;
16
+ }
17
+ }
15
18
  return stack.join("\n");
16
19
  };
17
20
 
@@ -9,10 +9,11 @@ const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOpt
9
9
 
10
10
  class EvalSourceMapDevToolPlugin {
11
11
  constructor(options) {
12
- if (arguments.length > 1)
12
+ if (arguments.length > 1) {
13
13
  throw new Error(
14
14
  "EvalSourceMapDevToolPlugin only takes one argument (pass an options object)"
15
15
  );
16
+ }
16
17
  if (typeof options === "string") {
17
18
  options = {
18
19
  append: options
@@ -26,16 +26,22 @@ class FlagDependencyUsagePlugin {
26
26
  const processModule = (module, usedExports) => {
27
27
  module.used = true;
28
28
  if (module.usedExports === true) return;
29
- else if (usedExports === true) module.usedExports = true;
30
- else if (Array.isArray(usedExports)) {
29
+ if (usedExports === true) {
30
+ module.usedExports = true;
31
+ } else if (Array.isArray(usedExports)) {
31
32
  const old = module.usedExports ? module.usedExports.length : -1;
32
33
  module.usedExports = addToSet(
33
34
  module.usedExports || [],
34
35
  usedExports
35
36
  );
36
- if (module.usedExports.length === old) return;
37
- } else if (Array.isArray(module.usedExports)) return;
38
- else module.usedExports = false;
37
+ if (module.usedExports.length === old) {
38
+ return;
39
+ }
40
+ } else if (Array.isArray(module.usedExports)) {
41
+ return;
42
+ } else {
43
+ module.usedExports = false;
44
+ }
39
45
 
40
46
  // for a module without side effects we stop tracking usage here when no export is used
41
47
  // This module won't be evaluated in this case
@@ -47,30 +47,32 @@ class FunctionModuleTemplatePlugin {
47
47
  if (
48
48
  Array.isArray(module.buildMeta.providedExports) &&
49
49
  module.buildMeta.providedExports.length === 0
50
- )
50
+ ) {
51
51
  source.add(Template.toComment("no exports provided") + "\n");
52
- else if (Array.isArray(module.buildMeta.providedExports))
52
+ } else if (Array.isArray(module.buildMeta.providedExports)) {
53
53
  source.add(
54
54
  Template.toComment(
55
55
  "exports provided: " +
56
56
  module.buildMeta.providedExports.join(", ")
57
57
  ) + "\n"
58
58
  );
59
- else if (module.buildMeta.providedExports)
59
+ } else if (module.buildMeta.providedExports) {
60
60
  source.add(Template.toComment("no static exports found") + "\n");
61
+ }
61
62
  if (
62
63
  Array.isArray(module.usedExports) &&
63
64
  module.usedExports.length === 0
64
- )
65
+ ) {
65
66
  source.add(Template.toComment("no exports used") + "\n");
66
- else if (Array.isArray(module.usedExports))
67
+ } else if (Array.isArray(module.usedExports)) {
67
68
  source.add(
68
69
  Template.toComment(
69
70
  "exports used: " + module.usedExports.join(", ")
70
71
  ) + "\n"
71
72
  );
72
- else if (module.usedExports)
73
+ } else if (module.usedExports) {
73
74
  source.add(Template.toComment("all exports used") + "\n");
75
+ }
74
76
  if (module.optimizationBailout) {
75
77
  for (const text of module.optimizationBailout) {
76
78
  let code;
@@ -19,13 +19,16 @@ module.exports = function() {
19
19
  var fn = function(request) {
20
20
  if (me.hot.active) {
21
21
  if (installedModules[request]) {
22
- if (installedModules[request].parents.indexOf(moduleId) === -1)
22
+ if (installedModules[request].parents.indexOf(moduleId) === -1) {
23
23
  installedModules[request].parents.push(moduleId);
24
+ }
24
25
  } else {
25
26
  hotCurrentParents = [moduleId];
26
27
  hotCurrentChildModule = request;
27
28
  }
28
- if (me.children.indexOf(request) === -1) me.children.push(request);
29
+ if (me.children.indexOf(request) === -1) {
30
+ me.children.push(request);
31
+ }
29
32
  } else {
30
33
  console.warn(
31
34
  "[HMR] unexpected require(" +
@@ -167,8 +170,9 @@ module.exports = function() {
167
170
  }
168
171
 
169
172
  function hotCheck(apply) {
170
- if (hotStatus !== "idle")
173
+ if (hotStatus !== "idle") {
171
174
  throw new Error("check() is only allowed in idle status");
175
+ }
172
176
  hotApplyOnUpdate = apply;
173
177
  hotSetStatus("check");
174
178
  return hotDownloadManifest(hotRequestTimeout).then(function(update) {
@@ -255,8 +255,11 @@ module.exports = class HotModuleReplacementPlugin {
255
255
  mainTemplate.hooks.currentHash.tap(
256
256
  "HotModuleReplacementPlugin",
257
257
  (_, length) => {
258
- if (isFinite(length)) return `hotCurrentHash.substr(0, ${length})`;
259
- else return "hotCurrentHash";
258
+ if (isFinite(length)) {
259
+ return `hotCurrentHash.substr(0, ${length})`;
260
+ } else {
261
+ return "hotCurrentHash";
262
+ }
260
263
  }
261
264
  );
262
265
 
@@ -301,21 +304,24 @@ module.exports = class HotModuleReplacementPlugin {
301
304
  }
302
305
  );
303
306
  // TODO webpack 5: refactor this, no custom hooks
304
- if (!parser.hooks.hotAcceptCallback)
307
+ if (!parser.hooks.hotAcceptCallback) {
305
308
  parser.hooks.hotAcceptCallback = new SyncBailHook([
306
309
  "expression",
307
310
  "requests"
308
311
  ]);
309
- if (!parser.hooks.hotAcceptWithoutCallback)
312
+ }
313
+ if (!parser.hooks.hotAcceptWithoutCallback) {
310
314
  parser.hooks.hotAcceptWithoutCallback = new SyncBailHook([
311
315
  "expression",
312
316
  "requests"
313
317
  ]);
318
+ }
314
319
  parser.hooks.call
315
320
  .for("module.hot.accept")
316
321
  .tap("HotModuleReplacementPlugin", expr => {
317
- if (!parser.state.compilation.hotUpdateChunkTemplate)
322
+ if (!parser.state.compilation.hotUpdateChunkTemplate) {
318
323
  return false;
324
+ }
319
325
  if (expr.arguments.length >= 1) {
320
326
  const arg = parser.evaluateExpression(expr.arguments[0]);
321
327
  let params = [];
@@ -355,8 +361,9 @@ module.exports = class HotModuleReplacementPlugin {
355
361
  parser.hooks.call
356
362
  .for("module.hot.decline")
357
363
  .tap("HotModuleReplacementPlugin", expr => {
358
- if (!parser.state.compilation.hotUpdateChunkTemplate)
364
+ if (!parser.state.compilation.hotUpdateChunkTemplate) {
359
365
  return false;
366
+ }
360
367
  if (expr.arguments.length === 1) {
361
368
  const arg = parser.evaluateExpression(expr.arguments[0]);
362
369
  let params = [];
@@ -143,10 +143,11 @@ class JavascriptGenerator {
143
143
 
144
144
  sourceDependency(dependency, dependencyTemplates, source, runtimeTemplate) {
145
145
  const template = dependencyTemplates.get(dependency.constructor);
146
- if (!template)
146
+ if (!template) {
147
147
  throw new Error(
148
148
  "No template for dependency: " + dependency.constructor.name
149
149
  );
150
+ }
150
151
  template.apply(dependency, source, runtimeTemplate, dependencyTemplates);
151
152
  }
152
153
 
@@ -55,10 +55,8 @@ class JavascriptModulesPlugin {
55
55
  const moduleTemplates = options.moduleTemplates;
56
56
  const dependencyTemplates = options.dependencyTemplates;
57
57
 
58
- let filenameTemplate;
59
- if (chunk.filenameTemplate)
60
- filenameTemplate = chunk.filenameTemplate;
61
- else filenameTemplate = outputOptions.filename;
58
+ const filenameTemplate =
59
+ chunk.filenameTemplate || outputOptions.filename;
62
60
 
63
61
  const useChunkHash = compilation.mainTemplate.useChunkHash(chunk);
64
62
 
@@ -101,11 +99,8 @@ class JavascriptModulesPlugin {
101
99
  const outputOptions = options.outputOptions;
102
100
  const moduleTemplates = options.moduleTemplates;
103
101
  const dependencyTemplates = options.dependencyTemplates;
104
-
105
- let filenameTemplate;
106
- if (chunk.filenameTemplate)
107
- filenameTemplate = chunk.filenameTemplate;
108
- else filenameTemplate = outputOptions.chunkFilename;
102
+ const filenameTemplate =
103
+ chunk.filenameTemplate || outputOptions.chunkFilename;
109
104
 
110
105
  result.push({
111
106
  render: () =>
package/lib/JsonParser.js CHANGED
@@ -16,8 +16,9 @@ class JsonParser {
16
16
  const data = parseJson(source[0] === "\ufeff" ? source.slice(1) : source);
17
17
  state.module.buildInfo.jsonData = data;
18
18
  state.module.buildMeta.exportsType = "named";
19
- if (typeof data === "object" && data)
19
+ if (typeof data === "object" && data) {
20
20
  state.module.addDependency(new JsonExportsDependency(Object.keys(data)));
21
+ }
21
22
  state.module.addDependency(new JsonExportsDependency(["default"]));
22
23
  return state;
23
24
  }
@@ -30,8 +30,9 @@ const accessorAccess = (base, accessor, joinWith = "; ") => {
30
30
  ? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
31
31
  : accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
32
32
  if (idx === accessors.length - 1) return a;
33
- if (idx === 0 && typeof base === "undefined")
33
+ if (idx === 0 && typeof base === "undefined") {
34
34
  return `${a} = typeof ${a} === "object" ? ${a} : {}`;
35
+ }
35
36
  return `${a} = ${a} || {}`;
36
37
  })
37
38
  .join(joinWith);
@@ -14,10 +14,11 @@ class LoaderOptionsPlugin {
14
14
  validateOptions(schema, options || {}, "Loader Options Plugin");
15
15
 
16
16
  if (typeof options !== "object") options = {};
17
- if (!options.test)
17
+ if (!options.test) {
18
18
  options.test = {
19
19
  test: () => true
20
20
  };
21
+ }
21
22
  this.options = options;
22
23
  }
23
24
 
@@ -401,10 +401,11 @@ module.exports = class MainTemplate extends Tapable {
401
401
  if (chunk.hasEntryModule()) {
402
402
  source = this.hooks.renderWithEntry.call(source, chunk, hash);
403
403
  }
404
- if (!source)
404
+ if (!source) {
405
405
  throw new Error(
406
406
  "Compiler error: MainTemplate plugin 'render' should return something"
407
407
  );
408
+ }
408
409
  chunk.rendered = true;
409
410
  return new ConcatSource(source, ";");
410
411
  }