webpack 5.90.3 → 5.91.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (174) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +5 -1
  3. package/lib/APIPlugin.js +8 -4
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +7 -1
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/ChunkGraph.js +32 -18
  9. package/lib/ChunkGroup.js +14 -14
  10. package/lib/CleanPlugin.js +7 -5
  11. package/lib/Compilation.js +262 -93
  12. package/lib/Compiler.js +199 -83
  13. package/lib/ConditionalInitFragment.js +4 -5
  14. package/lib/ContextModule.js +2 -0
  15. package/lib/ContextModuleFactory.js +4 -2
  16. package/lib/ContextReplacementPlugin.js +3 -2
  17. package/lib/DefinePlugin.js +4 -2
  18. package/lib/Dependency.js +4 -2
  19. package/lib/DependencyTemplate.js +7 -2
  20. package/lib/DllModule.js +1 -0
  21. package/lib/DllReferencePlugin.js +6 -2
  22. package/lib/EntryOptionPlugin.js +4 -1
  23. package/lib/EntryPlugin.js +6 -1
  24. package/lib/Entrypoint.js +1 -1
  25. package/lib/ExportsInfo.js +1 -4
  26. package/lib/ExternalModule.js +118 -24
  27. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  28. package/lib/FileSystemInfo.js +1 -1
  29. package/lib/Generator.js +2 -1
  30. package/lib/HookWebpackError.js +2 -2
  31. package/lib/InitFragment.js +5 -3
  32. package/lib/LibManifestPlugin.js +15 -7
  33. package/lib/Module.js +30 -2
  34. package/lib/ModuleFilenameHelpers.js +1 -1
  35. package/lib/ModuleGraph.js +56 -27
  36. package/lib/ModuleGraphConnection.js +2 -1
  37. package/lib/MultiCompiler.js +26 -8
  38. package/lib/NodeStuffPlugin.js +14 -3
  39. package/lib/NormalModule.js +3 -1
  40. package/lib/NormalModuleFactory.js +1 -1
  41. package/lib/NormalModuleReplacementPlugin.js +5 -1
  42. package/lib/ProvidePlugin.js +3 -1
  43. package/lib/RawModule.js +2 -1
  44. package/lib/ResolverFactory.js +3 -1
  45. package/lib/RuntimeModule.js +4 -4
  46. package/lib/RuntimePlugin.js +1 -0
  47. package/lib/RuntimeTemplate.js +102 -34
  48. package/lib/SourceMapDevToolPlugin.js +4 -1
  49. package/lib/Stats.js +10 -3
  50. package/lib/TemplatedPathPlugin.js +32 -6
  51. package/lib/Watching.js +67 -60
  52. package/lib/WebpackError.js +6 -6
  53. package/lib/WebpackOptionsApply.js +18 -5
  54. package/lib/asset/RawDataUrlModule.js +3 -1
  55. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  56. package/lib/buildChunkGraph.js +117 -64
  57. package/lib/cache/IdleFileCachePlugin.js +8 -3
  58. package/lib/cache/MemoryCachePlugin.js +1 -1
  59. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  60. package/lib/cache/PackFileCacheStrategy.js +49 -16
  61. package/lib/cache/ResolverCachePlugin.js +14 -6
  62. package/lib/cache/getLazyHashedEtag.js +1 -1
  63. package/lib/config/defaults.js +24 -1
  64. package/lib/config/normalization.js +3 -1
  65. package/lib/container/ContainerEntryDependency.js +2 -1
  66. package/lib/container/ContainerEntryModule.js +3 -1
  67. package/lib/container/ContainerPlugin.js +14 -10
  68. package/lib/container/FallbackModule.js +1 -1
  69. package/lib/container/RemoteRuntimeModule.js +12 -3
  70. package/lib/css/CssExportsGenerator.js +34 -17
  71. package/lib/css/CssGenerator.js +20 -2
  72. package/lib/css/CssLoadingRuntimeModule.js +212 -96
  73. package/lib/css/CssModulesPlugin.js +47 -13
  74. package/lib/debug/ProfilingPlugin.js +27 -2
  75. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  76. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  77. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  78. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  79. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  80. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  81. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  82. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  83. package/lib/dependencies/ContextElementDependency.js +8 -1
  84. package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
  85. package/lib/dependencies/CssUrlDependency.js +5 -3
  86. package/lib/dependencies/ExportsInfoDependency.js +4 -3
  87. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  88. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  89. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  90. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  91. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  92. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  93. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  94. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
  95. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  96. package/lib/dependencies/HarmonyImportSpecifierDependency.js +6 -5
  97. package/lib/dependencies/ImportDependency.js +9 -2
  98. package/lib/dependencies/ImportEagerDependency.js +4 -2
  99. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  100. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  101. package/lib/dependencies/ImportParserPlugin.js +12 -4
  102. package/lib/dependencies/ImportWeakDependency.js +4 -2
  103. package/lib/dependencies/LoaderDependency.js +2 -1
  104. package/lib/dependencies/LoaderImportDependency.js +2 -1
  105. package/lib/dependencies/ModuleDependency.js +4 -5
  106. package/lib/dependencies/PureExpressionDependency.js +4 -1
  107. package/lib/dependencies/RequireContextPlugin.js +1 -1
  108. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  109. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  110. package/lib/dependencies/URLDependency.js +7 -4
  111. package/lib/dependencies/WorkerPlugin.js +2 -1
  112. package/lib/dependencies/getFunctionExpression.js +3 -1
  113. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
  114. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  115. package/lib/javascript/ChunkHelpers.js +2 -2
  116. package/lib/javascript/JavascriptParser.js +169 -57
  117. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  118. package/lib/javascript/StartupHelpers.js +22 -5
  119. package/lib/logging/Logger.js +27 -2
  120. package/lib/logging/createConsoleLogger.js +11 -7
  121. package/lib/node/NodeEnvironmentPlugin.js +13 -7
  122. package/lib/node/NodeWatchFileSystem.js +37 -26
  123. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  124. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  125. package/lib/node/nodeConsole.js +24 -1
  126. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  127. package/lib/optimize/ConcatenatedModule.js +138 -54
  128. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  129. package/lib/optimize/InnerGraph.js +7 -2
  130. package/lib/optimize/InnerGraphPlugin.js +36 -13
  131. package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
  132. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  133. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  134. package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
  135. package/lib/optimize/SplitChunksPlugin.js +2 -2
  136. package/lib/performance/SizeLimitsPlugin.js +11 -0
  137. package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
  138. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  139. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  140. package/lib/serialization/FileMiddleware.js +1 -0
  141. package/lib/serialization/ObjectMiddleware.js +2 -0
  142. package/lib/serialization/Serializer.js +19 -0
  143. package/lib/sharing/ConsumeSharedModule.js +1 -1
  144. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  145. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  146. package/lib/sharing/ProvideSharedPlugin.js +12 -5
  147. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  148. package/lib/sharing/utils.js +13 -6
  149. package/lib/util/StackedCacheMap.js +26 -0
  150. package/lib/util/WeakTupleMap.js +57 -13
  151. package/lib/util/cleverMerge.js +24 -11
  152. package/lib/util/comparators.js +34 -14
  153. package/lib/util/conventions.js +129 -0
  154. package/lib/util/fs.js +379 -65
  155. package/lib/util/hash/BatchedHash.js +3 -0
  156. package/lib/util/hash/xxhash64.js +2 -2
  157. package/lib/util/runtime.js +1 -1
  158. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  159. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
  160. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
  161. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  162. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
  163. package/lib/webpack.js +7 -3
  164. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  165. package/package.json +25 -26
  166. package/schemas/WebpackOptions.check.js +1 -1
  167. package/schemas/WebpackOptions.json +69 -8
  168. package/schemas/plugins/BannerPlugin.check.js +1 -1
  169. package/schemas/plugins/BannerPlugin.json +5 -1
  170. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  171. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  173. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  174. package/types.d.ts +1668 -613
@@ -5,6 +5,21 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /**
9
+ * @template {any[]} T
10
+ * @template V
11
+ * @typedef {Map<object, WeakTupleMap<T, V>>} M
12
+ */
13
+ /**
14
+ * @template {any[]} T
15
+ * @template V
16
+ * @typedef {WeakMap<object, WeakTupleMap<T, V>>} W
17
+ */
18
+
19
+ /**
20
+ * @param {any} thing thing
21
+ * @returns {boolean} true if is weak
22
+ */
8
23
  const isWeakKey = thing => typeof thing === "object" && thing !== null;
9
24
 
10
25
  /**
@@ -15,11 +30,20 @@ class WeakTupleMap {
15
30
  constructor() {
16
31
  /** @private */
17
32
  this.f = 0;
18
- /** @private @type {any} */
33
+ /**
34
+ * @private
35
+ * @type {any}
36
+ **/
19
37
  this.v = undefined;
20
- /** @private @type {Map<object, WeakTupleMap<T, V>> | undefined} */
38
+ /**
39
+ * @private
40
+ * @type {M<T, V> | undefined}
41
+ **/
21
42
  this.m = undefined;
22
- /** @private @type {WeakMap<object, WeakTupleMap<T, V>> | undefined} */
43
+ /**
44
+ * @private
45
+ * @type {W<T, V> | undefined}
46
+ **/
23
47
  this.w = undefined;
24
48
  }
25
49
 
@@ -41,7 +65,7 @@ class WeakTupleMap {
41
65
  * @returns {boolean} true, if the tuple is in the Set
42
66
  */
43
67
  has(...args) {
44
- /** @type {WeakTupleMap<T, V>} */
68
+ /** @type {WeakTupleMap<T, V> | undefined} */
45
69
  let node = this;
46
70
  for (let i = 0; i < args.length; i++) {
47
71
  node = node._peek(args[i]);
@@ -52,10 +76,10 @@ class WeakTupleMap {
52
76
 
53
77
  /**
54
78
  * @param {T} args tuple
55
- * @returns {V} the value
79
+ * @returns {V | undefined} the value
56
80
  */
57
81
  get(...args) {
58
- /** @type {WeakTupleMap<T, V>} */
82
+ /** @type {WeakTupleMap<T, V> | undefined} */
59
83
  let node = this;
60
84
  for (let i = 0; i < args.length; i++) {
61
85
  node = node._peek(args[i]);
@@ -86,7 +110,7 @@ class WeakTupleMap {
86
110
  * @returns {void}
87
111
  */
88
112
  delete(...args) {
89
- /** @type {WeakTupleMap<T, V>} */
113
+ /** @type {WeakTupleMap<T, V> | undefined} */
90
114
  let node = this;
91
115
  for (let i = 0; i < args.length; i++) {
92
116
  node = node._peek(args[i]);
@@ -113,6 +137,10 @@ class WeakTupleMap {
113
137
  return (this.f & 1) === 1;
114
138
  }
115
139
 
140
+ /**
141
+ * @param {any} v value
142
+ * @private
143
+ */
116
144
  _setValue(v) {
117
145
  this.f |= 1;
118
146
  this.v = v;
@@ -123,16 +151,26 @@ class WeakTupleMap {
123
151
  this.v = undefined;
124
152
  }
125
153
 
154
+ /**
155
+ * @param {any} thing thing
156
+ * @returns {WeakTupleMap<T, V> | undefined} thing
157
+ * @private
158
+ */
126
159
  _peek(thing) {
127
160
  if (isWeakKey(thing)) {
128
161
  if ((this.f & 4) !== 4) return undefined;
129
- return this.w.get(thing);
162
+ return /** @type {W<T, V>} */ (this.w).get(thing);
130
163
  } else {
131
164
  if ((this.f & 2) !== 2) return undefined;
132
- return this.m.get(thing);
165
+ return /** @type {M<T, V>} */ (this.m).get(thing);
133
166
  }
134
167
  }
135
168
 
169
+ /**
170
+ * @private
171
+ * @param {any} thing thing
172
+ * @returns {WeakTupleMap<T, V>} value
173
+ */
136
174
  _get(thing) {
137
175
  if (isWeakKey(thing)) {
138
176
  if ((this.f & 4) !== 4) {
@@ -142,12 +180,15 @@ class WeakTupleMap {
142
180
  (this.w = newMap).set(thing, newNode);
143
181
  return newNode;
144
182
  }
145
- const entry = this.w.get(thing);
183
+ const entry =
184
+ /** @type {W<T, V>} */
185
+ (this.w).get(thing);
146
186
  if (entry !== undefined) {
147
187
  return entry;
148
188
  }
149
189
  const newNode = new WeakTupleMap();
150
- this.w.set(thing, newNode);
190
+ /** @type {W<T, V>} */
191
+ (this.w).set(thing, newNode);
151
192
  return newNode;
152
193
  } else {
153
194
  if ((this.f & 2) !== 2) {
@@ -157,12 +198,15 @@ class WeakTupleMap {
157
198
  (this.m = newMap).set(thing, newNode);
158
199
  return newNode;
159
200
  }
160
- const entry = this.m.get(thing);
201
+ const entry =
202
+ /** @type {M<T, V>} */
203
+ (this.m).get(thing);
161
204
  if (entry !== undefined) {
162
205
  return entry;
163
206
  }
164
207
  const newNode = new WeakTupleMap();
165
- this.m.set(thing, newNode);
208
+ /** @type {M<T, V>} */
209
+ (this.m).set(thing, newNode);
166
210
  return newNode;
167
211
  }
168
212
  }
@@ -38,11 +38,11 @@ const cachedCleverMerge = (first, second) => {
38
38
  innerCache = new WeakMap();
39
39
  mergeCache.set(first, innerCache);
40
40
  }
41
- const prevMerge = innerCache.get(second);
41
+ const prevMerge = /** @type {T & O} */ (innerCache.get(second));
42
42
  if (prevMerge !== undefined) return prevMerge;
43
43
  const newMerge = _cleverMerge(first, second, true);
44
44
  innerCache.set(second, newMerge);
45
- return newMerge;
45
+ return /** @type {T & O} */ (newMerge);
46
46
  };
47
47
 
48
48
  /**
@@ -69,7 +69,7 @@ const cachedSetProperty = (obj, property, value) => {
69
69
 
70
70
  let result = mapByValue.get(value);
71
71
 
72
- if (result) return result;
72
+ if (result) return /** @type {T} */ (result);
73
73
 
74
74
  result = {
75
75
  ...obj,
@@ -77,7 +77,7 @@ const cachedSetProperty = (obj, property, value) => {
77
77
  };
78
78
  mapByValue.set(value, result);
79
79
 
80
- return result;
80
+ return /** @type {T} */ (result);
81
81
  };
82
82
 
83
83
  /**
@@ -257,7 +257,7 @@ const cleverMerge = (first, second) => {
257
257
  if (typeof second !== "object" || second === null) return second;
258
258
  if (typeof first !== "object" || first === null) return first;
259
259
 
260
- return _cleverMerge(first, second, false);
260
+ return /** @type {T & O} */ (_cleverMerge(first, second, false));
261
261
  };
262
262
 
263
263
  /**
@@ -498,27 +498,40 @@ const mergeSingleValue = (a, b, internalCaching) => {
498
498
  };
499
499
 
500
500
  /**
501
- * @template T
501
+ * @template {object} T
502
502
  * @param {T} obj the object
503
+ * @param {(keyof T)[]=} keysToKeepOriginalValue keys to keep original value
503
504
  * @returns {T} the object without operations like "..." or DELETE
504
505
  */
505
- const removeOperations = obj => {
506
+ const removeOperations = (obj, keysToKeepOriginalValue = []) => {
506
507
  const newObj = /** @type {T} */ ({});
507
508
  for (const key of Object.keys(obj)) {
508
- const value = obj[key];
509
+ const value = obj[/** @type {keyof T} */ (key)];
509
510
  const type = getValueType(value);
511
+ if (
512
+ type === VALUE_TYPE_OBJECT &&
513
+ keysToKeepOriginalValue.includes(/** @type {keyof T} */ (key))
514
+ ) {
515
+ newObj[/** @type {keyof T} */ (key)] = value;
516
+ continue;
517
+ }
510
518
  switch (type) {
511
519
  case VALUE_TYPE_UNDEFINED:
512
520
  case VALUE_TYPE_DELETE:
513
521
  break;
514
522
  case VALUE_TYPE_OBJECT:
515
- newObj[key] = removeOperations(value);
523
+ newObj[key] = removeOperations(
524
+ /** @type {TODO} */ (value),
525
+ keysToKeepOriginalValue
526
+ );
516
527
  break;
517
528
  case VALUE_TYPE_ARRAY_EXTEND:
518
- newObj[key] = value.filter(i => i !== "...");
529
+ newObj[key] =
530
+ /** @type {any[]} */
531
+ (value).filter(i => i !== "...");
519
532
  break;
520
533
  default:
521
- newObj[key] = value;
534
+ newObj[/** @type {keyof T} */ (key)] = value;
522
535
  break;
523
536
  }
524
537
  }
@@ -8,6 +8,7 @@
8
8
  const { compareRuntime } = require("./runtime");
9
9
 
10
10
  /** @typedef {import("../Chunk")} Chunk */
11
+ /** @typedef {import("../Chunk").ChunkId} ChunkId */
11
12
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
12
13
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
13
14
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
@@ -46,7 +47,10 @@ const createCachedParameterizedComparator = fn => {
46
47
  * @returns {-1|0|1} compare result
47
48
  */
48
49
  exports.compareChunksById = (a, b) => {
49
- return compareIds(a.id, b.id);
50
+ return compareIds(
51
+ /** @type {ChunkId} */ (a.id),
52
+ /** @type {ChunkId} */ (b.id)
53
+ );
50
54
  };
51
55
 
52
56
  /**
@@ -166,8 +170,8 @@ exports.compareStringsNumeric = compareStringsNumeric;
166
170
  */
167
171
  const compareModulesByPostOrderIndexOrIdentifier = (moduleGraph, a, b) => {
168
172
  const cmp = compareNumbers(
169
- moduleGraph.getPostOrderIndex(a),
170
- moduleGraph.getPostOrderIndex(b)
173
+ /** @type {number} */ (moduleGraph.getPostOrderIndex(a)),
174
+ /** @type {number} */ (moduleGraph.getPostOrderIndex(b))
171
175
  );
172
176
  if (cmp !== 0) return cmp;
173
177
  return compareIds(a.identifier(), b.identifier());
@@ -186,8 +190,8 @@ exports.compareModulesByPostOrderIndexOrIdentifier =
186
190
  */
187
191
  const compareModulesByPreOrderIndexOrIdentifier = (moduleGraph, a, b) => {
188
192
  const cmp = compareNumbers(
189
- moduleGraph.getPreOrderIndex(a),
190
- moduleGraph.getPreOrderIndex(b)
193
+ /** @type {number} */ (moduleGraph.getPreOrderIndex(a)),
194
+ /** @type {number} */ (moduleGraph.getPreOrderIndex(b))
191
195
  );
192
196
  if (cmp !== 0) return cmp;
193
197
  return compareIds(a.identifier(), b.identifier());
@@ -261,7 +265,9 @@ exports.compareStrings = compareStrings;
261
265
  * @returns {-1|0|1} compare result
262
266
  */
263
267
  const compareChunkGroupsByIndex = (a, b) => {
264
- return a.index < b.index ? -1 : 1;
268
+ return /** @type {number} */ (a.index) < /** @type {number} */ (b.index)
269
+ ? -1
270
+ : 1;
265
271
  };
266
272
 
267
273
  exports.compareChunkGroupsByIndex = compareChunkGroupsByIndex;
@@ -273,7 +279,7 @@ exports.compareChunkGroupsByIndex = compareChunkGroupsByIndex;
273
279
  */
274
280
  class TwoKeyWeakMap {
275
281
  constructor() {
276
- /** @private @type {WeakMap<any, WeakMap<any, T>>} */
282
+ /** @private @type {WeakMap<any, WeakMap<any, T | undefined>>} */
277
283
  this._map = new WeakMap();
278
284
  }
279
285
 
@@ -340,7 +346,10 @@ const concatComparators = (c1, c2, ...cRest) => {
340
346
  };
341
347
  exports.concatComparators = concatComparators;
342
348
 
343
- /** @template A, B @typedef {(input: A) => B} Selector */
349
+ /**
350
+ * @template A, B
351
+ * @typedef {(input: A) => B | undefined | null} Selector
352
+ */
344
353
 
345
354
  /** @type {TwoKeyWeakMap<Selector<any, any>, Comparator<any>, Comparator<any>>}} */
346
355
  const compareSelectCache = new TwoKeyWeakMap();
@@ -431,7 +440,11 @@ exports.keepOriginalOrder = iterable => {
431
440
  for (const item of iterable) {
432
441
  map.set(item, i++);
433
442
  }
434
- return (a, b) => compareNumbers(map.get(a), map.get(b));
443
+ return (a, b) =>
444
+ compareNumbers(
445
+ /** @type {number} */ (map.get(a)),
446
+ /** @type {number} */ (map.get(b))
447
+ );
435
448
  };
436
449
 
437
450
  /**
@@ -442,7 +455,10 @@ exports.compareChunksNatural = chunkGraph => {
442
455
  const cmpFn = exports.compareModulesById(chunkGraph);
443
456
  const cmpIterableFn = compareIterables(cmpFn);
444
457
  return concatComparators(
445
- compareSelect(chunk => chunk.name, compareIds),
458
+ compareSelect(
459
+ chunk => /** @type {string|number} */ (chunk.name),
460
+ compareIds
461
+ ),
446
462
  compareSelect(chunk => chunk.runtime, compareRuntime),
447
463
  compareSelect(
448
464
  /**
@@ -475,8 +491,10 @@ exports.compareLocations = (a, b) => {
475
491
  const bp = b.start;
476
492
  if (ap.line < bp.line) return -1;
477
493
  if (ap.line > bp.line) return 1;
478
- if (ap.column < bp.column) return -1;
479
- if (ap.column > bp.column) return 1;
494
+ if (/** @type {number} */ (ap.column) < /** @type {number} */ (bp.column))
495
+ return -1;
496
+ if (/** @type {number} */ (ap.column) > /** @type {number} */ (bp.column))
497
+ return 1;
480
498
  } else return -1;
481
499
  } else if ("start" in b) return 1;
482
500
  if ("name" in a) {
@@ -487,8 +505,10 @@ exports.compareLocations = (a, b) => {
487
505
  } else if ("name" in b) return 1;
488
506
  if ("index" in a) {
489
507
  if ("index" in b) {
490
- if (a.index < b.index) return -1;
491
- if (a.index > b.index) return 1;
508
+ if (/** @type {number} */ (a.index) < /** @type {number} */ (b.index))
509
+ return -1;
510
+ if (/** @type {number} */ (a.index) > /** @type {number} */ (b.index))
511
+ return 1;
492
512
  } else return -1;
493
513
  } else if ("index" in b) return 1;
494
514
  return 0;
@@ -0,0 +1,129 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Gengkun He @ahabhgk
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
9
+
10
+ /**
11
+ * @param {string} input input
12
+ * @param {CssGeneratorExportsConvention} convention convention
13
+ * @returns {Set<string>} results
14
+ */
15
+ exports.cssExportConvention = (input, convention) => {
16
+ const set = new Set();
17
+ if (typeof convention === "function") {
18
+ set.add(convention(input));
19
+ } else {
20
+ switch (convention) {
21
+ case "camel-case": {
22
+ set.add(input);
23
+ set.add(exports.camelCase(input));
24
+ break;
25
+ }
26
+ case "camel-case-only": {
27
+ set.add(exports.camelCase(input));
28
+ break;
29
+ }
30
+ case "dashes": {
31
+ set.add(input);
32
+ set.add(exports.dashesCamelCase(input));
33
+ break;
34
+ }
35
+ case "dashes-only": {
36
+ set.add(exports.dashesCamelCase(input));
37
+ break;
38
+ }
39
+ case "as-is": {
40
+ set.add(input);
41
+ break;
42
+ }
43
+ }
44
+ }
45
+ return set;
46
+ };
47
+
48
+ // Copy from css-loader
49
+ /**
50
+ * @param {string} input input
51
+ * @returns {string} result
52
+ */
53
+ exports.dashesCamelCase = input => {
54
+ return input.replace(/-+(\w)/g, (match, firstLetter) =>
55
+ firstLetter.toUpperCase()
56
+ );
57
+ };
58
+
59
+ // Copy from css-loader
60
+ /**
61
+ * @param {string} input input
62
+ * @returns {string} result
63
+ */
64
+ exports.camelCase = input => {
65
+ let result = input.trim();
66
+
67
+ if (result.length === 0) {
68
+ return "";
69
+ }
70
+
71
+ if (result.length === 1) {
72
+ return result.toLowerCase();
73
+ }
74
+
75
+ const hasUpperCase = result !== result.toLowerCase();
76
+
77
+ if (hasUpperCase) {
78
+ result = preserveCamelCase(result);
79
+ }
80
+
81
+ return result
82
+ .replace(/^[_.\- ]+/, "")
83
+ .toLowerCase()
84
+ .replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toUpperCase())
85
+ .replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toUpperCase());
86
+ };
87
+
88
+ // Copy from css-loader
89
+ /**
90
+ * @param {string} string string
91
+ * @returns {string} result
92
+ */
93
+ const preserveCamelCase = string => {
94
+ let result = string;
95
+ let isLastCharLower = false;
96
+ let isLastCharUpper = false;
97
+ let isLastLastCharUpper = false;
98
+
99
+ for (let i = 0; i < result.length; i++) {
100
+ const character = result[i];
101
+
102
+ if (isLastCharLower && /[\p{Lu}]/u.test(character)) {
103
+ result = `${result.slice(0, i)}-${result.slice(i)}`;
104
+ isLastCharLower = false;
105
+ isLastLastCharUpper = isLastCharUpper;
106
+ isLastCharUpper = true;
107
+ i += 1;
108
+ } else if (
109
+ isLastCharUpper &&
110
+ isLastLastCharUpper &&
111
+ /[\p{Ll}]/u.test(character)
112
+ ) {
113
+ result = `${result.slice(0, i - 1)}-${result.slice(i - 1)}`;
114
+ isLastLastCharUpper = isLastCharUpper;
115
+ isLastCharUpper = false;
116
+ isLastCharLower = true;
117
+ } else {
118
+ isLastCharLower =
119
+ character.toLowerCase() === character &&
120
+ character.toUpperCase() !== character;
121
+ isLastLastCharUpper = isLastCharUpper;
122
+ isLastCharUpper =
123
+ character.toUpperCase() === character &&
124
+ character.toLowerCase() !== character;
125
+ }
126
+ }
127
+
128
+ return result;
129
+ };