webpack 5.87.0 → 5.88.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 (144) hide show
  1. package/lib/APIPlugin.js +1 -1
  2. package/lib/AsyncDependenciesBlock.js +3 -3
  3. package/lib/ChunkGraph.js +4 -4
  4. package/lib/ChunkGroup.js +9 -3
  5. package/lib/CompatibilityPlugin.js +50 -30
  6. package/lib/Compilation.js +2 -1
  7. package/lib/ContextModule.js +4 -1
  8. package/lib/ContextReplacementPlugin.js +13 -0
  9. package/lib/DelegatedModule.js +15 -3
  10. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  11. package/lib/Dependency.js +11 -5
  12. package/lib/DllEntryPlugin.js +11 -1
  13. package/lib/DllReferencePlugin.js +13 -1
  14. package/lib/Entrypoint.js +1 -1
  15. package/lib/ErrorHelpers.js +1 -0
  16. package/lib/EvalSourceMapDevToolPlugin.js +4 -0
  17. package/lib/ExportsInfo.js +17 -3
  18. package/lib/ExportsInfoApiPlugin.js +14 -5
  19. package/lib/ExternalModule.js +5 -0
  20. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  21. package/lib/FlagDependencyUsagePlugin.js +3 -1
  22. package/lib/HotModuleReplacementPlugin.js +8 -0
  23. package/lib/InitFragment.js +28 -5
  24. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  25. package/lib/LibManifestPlugin.js +20 -4
  26. package/lib/Module.js +7 -2
  27. package/lib/ModuleProfile.js +1 -0
  28. package/lib/ModuleRestoreError.js +2 -0
  29. package/lib/NodeStuffPlugin.js +32 -6
  30. package/lib/ProvidePlugin.js +13 -4
  31. package/lib/RawModule.js +3 -1
  32. package/lib/RequireJsStuffPlugin.js +7 -0
  33. package/lib/RuntimeModule.js +3 -3
  34. package/lib/RuntimePlugin.js +4 -2
  35. package/lib/RuntimeTemplate.js +2 -2
  36. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  37. package/lib/SourceMapDevToolPlugin.js +7 -2
  38. package/lib/UseStrictPlugin.js +10 -3
  39. package/lib/WebpackIsIncludedPlugin.js +6 -4
  40. package/lib/asset/AssetGenerator.js +2 -1
  41. package/lib/asset/AssetParser.js +11 -6
  42. package/lib/asset/AssetSourceParser.js +8 -3
  43. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  44. package/lib/cache/IdleFileCachePlugin.js +2 -1
  45. package/lib/cache/PackFileCacheStrategy.js +35 -14
  46. package/lib/config/browserslistTargetHandler.js +7 -7
  47. package/lib/config/defaults.js +12 -24
  48. package/lib/container/RemoteRuntimeModule.js +1 -1
  49. package/lib/css/CssLoadingRuntimeModule.js +30 -13
  50. package/lib/css/CssParser.js +11 -1
  51. package/lib/dependencies/AMDDefineDependency.js +34 -4
  52. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  53. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  54. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  55. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  56. package/lib/dependencies/CommonJsPlugin.js +13 -8
  57. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  58. package/lib/dependencies/ContextDependency.js +7 -2
  59. package/lib/dependencies/CssImportDependency.js +1 -1
  60. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  61. package/lib/dependencies/CssUrlDependency.js +3 -3
  62. package/lib/dependencies/DllEntryDependency.js +5 -0
  63. package/lib/dependencies/DynamicExports.js +10 -6
  64. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  65. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  66. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  67. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  68. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  69. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  70. package/lib/dependencies/HarmonyExports.js +9 -5
  71. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +32 -17
  72. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +19 -9
  74. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  75. package/lib/dependencies/ImportDependency.js +5 -3
  76. package/lib/dependencies/ImportEagerDependency.js +5 -3
  77. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  78. package/lib/dependencies/ImportParserPlugin.js +38 -25
  79. package/lib/dependencies/ImportWeakDependency.js +5 -3
  80. package/lib/dependencies/ModuleDependency.js +1 -1
  81. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  82. package/lib/dependencies/ProvidedDependency.js +4 -1
  83. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  84. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  85. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  86. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  87. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  88. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  89. package/lib/dependencies/SystemPlugin.js +17 -5
  90. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  91. package/lib/dependencies/URLDependency.js +2 -2
  92. package/lib/dependencies/URLPlugin.js +9 -4
  93. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  94. package/lib/dependencies/WorkerPlugin.js +59 -22
  95. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  96. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  97. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  98. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  99. package/lib/javascript/JavascriptParser.js +17 -5
  100. package/lib/logging/runtime.js +1 -1
  101. package/lib/logging/truncateArgs.js +4 -0
  102. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  103. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  104. package/lib/optimize/InnerGraph.js +1 -1
  105. package/lib/optimize/InnerGraphPlugin.js +2 -1
  106. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -1
  107. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -1
  108. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
  109. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
  110. package/lib/runtime/AsyncModuleRuntimeModule.js +4 -4
  111. package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -1
  112. package/lib/runtime/BaseUriRuntimeModule.js +1 -1
  113. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  114. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
  115. package/lib/runtime/CompatRuntimeModule.js +1 -1
  116. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  117. package/lib/runtime/CreateScriptRuntimeModule.js +1 -1
  118. package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -1
  119. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
  120. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -1
  121. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -1
  122. package/lib/runtime/GetFullHashRuntimeModule.js +1 -1
  123. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
  124. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  125. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  126. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
  127. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  128. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
  129. package/lib/runtime/NonceRuntimeModule.js +1 -1
  130. package/lib/runtime/OnChunksLoadedRuntimeModule.js +1 -1
  131. package/lib/runtime/PublicPathRuntimeModule.js +1 -1
  132. package/lib/runtime/RelativeUrlRuntimeModule.js +1 -1
  133. package/lib/runtime/RuntimeIdRuntimeModule.js +1 -1
  134. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  135. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -1
  136. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  137. package/lib/sharing/ConsumeSharedRuntimeModule.js +1 -1
  138. package/lib/sharing/ShareRuntimeModule.js +1 -1
  139. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
  140. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
  141. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  142. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  143. package/package.json +2 -1
  144. package/types.d.ts +86 -38
@@ -7,6 +7,8 @@
7
7
 
8
8
  const Parser = require("../Parser");
9
9
 
10
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
11
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
10
12
  /** @typedef {import("../Parser").ParserState} ParserState */
11
13
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
12
14
 
@@ -21,9 +23,12 @@ class AssetSourceParser extends Parser {
21
23
  throw new Error("AssetSourceParser doesn't accept preparsed AST");
22
24
  }
23
25
  const { module } = state;
24
- module.buildInfo.strict = true;
25
- module.buildMeta.exportsType = "default";
26
- state.module.buildMeta.defaultObject = false;
26
+ /** @type {BuildInfo} */
27
+ (module.buildInfo).strict = true;
28
+ /** @type {BuildMeta} */
29
+ (module.buildMeta).exportsType = "default";
30
+ /** @type {BuildMeta} */
31
+ (state.module.buildMeta).defaultObject = false;
27
32
 
28
33
  return state;
29
34
  }
@@ -29,6 +29,10 @@ class AwaitDependenciesInitFragment extends InitFragment {
29
29
  this.promises = promises;
30
30
  }
31
31
 
32
+ /**
33
+ * @param {AwaitDependenciesInitFragment} other other AwaitDependenciesInitFragment
34
+ * @returns {AwaitDependenciesInitFragment} AwaitDependenciesInitFragment
35
+ */
32
36
  merge(other) {
33
37
  const promises = new Set(other.promises);
34
38
  for (const p of this.promises) {
@@ -50,7 +50,7 @@ class IdleFileCachePlugin {
50
50
  let timeSpendInStore = 0;
51
51
  let avgTimeSpendInStore = 0;
52
52
 
53
- /** @type {Map<string | typeof BUILD_DEPENDENCIES_KEY, () => Promise>} */
53
+ /** @type {Map<string | typeof BUILD_DEPENDENCIES_KEY, () => Promise<void>>} */
54
54
  const pendingIdleTasks = new Map();
55
55
 
56
56
  compiler.cache.hooks.store.tap(
@@ -171,6 +171,7 @@ class IdleFileCachePlugin {
171
171
  isInitialStore = false;
172
172
  }
173
173
  };
174
+ /** @type {ReturnType<typeof setTimeout> | undefined} */
174
175
  let idleTimer = undefined;
175
176
  compiler.cache.hooks.beginIdle.tap(
176
177
  { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
@@ -22,6 +22,8 @@ const {
22
22
  /** @typedef {import("../Compiler")} Compiler */
23
23
  /** @typedef {import("../FileSystemInfo").Snapshot} Snapshot */
24
24
  /** @typedef {import("../logging/Logger").Logger} Logger */
25
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
26
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
25
27
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
26
28
 
27
29
  class PackContainer {
@@ -58,6 +60,9 @@ class PackContainer {
58
60
  writeLazy(this.data);
59
61
  }
60
62
 
63
+ /**
64
+ * @param {ObjectDeserializerContext} context context
65
+ */
61
66
  deserialize({ read }) {
62
67
  this.version = read();
63
68
  this.buildSnapshot = read();
@@ -99,7 +104,7 @@ class Pack {
99
104
  constructor(logger, maxAge) {
100
105
  /** @type {Map<string, PackItemInfo>} */
101
106
  this.itemInfo = new Map();
102
- /** @type {string[]} */
107
+ /** @type {(string | undefined)[]} */
103
108
  this.requests = [];
104
109
  this.requestsTimeout = undefined;
105
110
  /** @type {Map<string, PackItemInfo>} */
@@ -111,6 +116,9 @@ class Pack {
111
116
  this.maxAge = maxAge;
112
117
  }
113
118
 
119
+ /**
120
+ * @param {string} identifier identifier
121
+ */
114
122
  _addRequest(identifier) {
115
123
  this.requests.push(identifier);
116
124
  if (this.requestsTimeout === undefined) {
@@ -149,7 +157,7 @@ class Pack {
149
157
  if (!this.content[loc]) {
150
158
  return undefined;
151
159
  }
152
- return this.content[loc].get(identifier);
160
+ return /** @type {PackContent} */ (this.content[loc]).get(identifier);
153
161
  }
154
162
  }
155
163
 
@@ -175,7 +183,7 @@ class Pack {
175
183
  if (loc >= 0) {
176
184
  this._addRequest(identifier);
177
185
  this.freshContent.set(identifier, info);
178
- const content = this.content[loc];
186
+ const content = /** @type {PackContent} */ (this.content[loc]);
179
187
  content.delete(identifier);
180
188
  if (content.items.size === 0) {
181
189
  this.content[loc] = undefined;
@@ -351,11 +359,12 @@ class Pack {
351
359
  mergedIndices = smallUnusedContents;
352
360
  } else return;
353
361
 
362
+ /** @type {PackContent[] } */
354
363
  const mergedContent = [];
355
364
 
356
365
  // 3. Remove old content entries
357
366
  for (const i of mergedIndices) {
358
- mergedContent.push(this.content[i]);
367
+ mergedContent.push(/** @type {PackContent} */ (this.content[i]));
359
368
  this.content[i] = undefined;
360
369
  }
361
370
 
@@ -364,7 +373,7 @@ class Pack {
364
373
  const mergedItems = new Set();
365
374
  /** @type {Set<string>} */
366
375
  const mergedUsedItems = new Set();
367
- /** @type {(function(Map<string, any>): Promise)[]} */
376
+ /** @type {(function(Map<string, any>): Promise<void>)[]} */
368
377
  const addToMergedMap = [];
369
378
  for (const content of mergedContent) {
370
379
  for (const identifier of content.items) {
@@ -498,17 +507,20 @@ class Pack {
498
507
  * Only runs for one content to avoid large invalidation.
499
508
  */
500
509
  _gcOldestContent() {
501
- /** @type {PackItemInfo} */
510
+ /** @type {PackItemInfo | undefined} */
502
511
  let oldest = undefined;
503
512
  for (const info of this.itemInfo.values()) {
504
513
  if (oldest === undefined || info.lastAccess < oldest.lastAccess) {
505
514
  oldest = info;
506
515
  }
507
516
  }
508
- if (Date.now() - oldest.lastAccess > this.maxAge) {
509
- const loc = oldest.location;
517
+ if (
518
+ Date.now() - /** @type {PackItemInfo} */ (oldest).lastAccess >
519
+ this.maxAge
520
+ ) {
521
+ const loc = /** @type {PackItemInfo} */ (oldest).location;
510
522
  if (loc < 0) return;
511
- const content = this.content[loc];
523
+ const content = /** @type {PackContent} */ (this.content[loc]);
512
524
  const items = new Set(content.items);
513
525
  const usedItems = new Set(content.used);
514
526
  this._gcAndUpdateLocation(items, usedItems, loc);
@@ -771,6 +783,7 @@ class PackContent {
771
783
 
772
784
  // We are in state B
773
785
  const { lazyName } = this;
786
+ /** @type {string | undefined} */
774
787
  let timeMessage;
775
788
  if (lazyName) {
776
789
  // only log once
@@ -811,7 +824,7 @@ class PackContent {
811
824
 
812
825
  /**
813
826
  * @param {string} reason explanation why unpack is necessary
814
- * @returns {void | Promise} maybe a promise if lazy
827
+ * @returns {void | Promise<void>} maybe a promise if lazy
815
828
  */
816
829
  unpack(reason) {
817
830
  if (this.content) return;
@@ -819,6 +832,7 @@ class PackContent {
819
832
  // Move from state B to C
820
833
  if (this.lazy) {
821
834
  const { lazyName } = this;
835
+ /** @type {string | undefined} */
822
836
  let timeMessage;
823
837
  if (lazyName) {
824
838
  // only log once
@@ -862,6 +876,9 @@ class PackContent {
862
876
  return size;
863
877
  }
864
878
 
879
+ /**
880
+ * @param {string} identifier identifier
881
+ */
865
882
  delete(identifier) {
866
883
  this.items.delete(identifier);
867
884
  this.used.delete(identifier);
@@ -906,6 +923,7 @@ class PackContent {
906
923
  }
907
924
  // State B2
908
925
  const { lazyName } = this;
926
+ /** @type {string | undefined} */
909
927
  let timeMessage;
910
928
  if (lazyName) {
911
929
  // only log once
@@ -1028,17 +1046,20 @@ class PackFileCacheStrategy {
1028
1046
  this.buildDependencies = new Set();
1029
1047
  /** @type {LazySet<string>} */
1030
1048
  this.newBuildDependencies = new LazySet();
1031
- /** @type {Snapshot} */
1049
+ /** @type {Snapshot | undefined} */
1032
1050
  this.resolveBuildDependenciesSnapshot = undefined;
1033
- /** @type {Map<string, string | false>} */
1051
+ /** @type {Map<string, string | false> | undefined} */
1034
1052
  this.resolveResults = undefined;
1035
- /** @type {Snapshot} */
1053
+ /** @type {Snapshot | undefined} */
1036
1054
  this.buildSnapshot = undefined;
1037
- /** @type {Promise<Pack>} */
1055
+ /** @type {Promise<Pack> | undefined} */
1038
1056
  this.packPromise = this._openPack();
1039
1057
  this.storePromise = Promise.resolve();
1040
1058
  }
1041
1059
 
1060
+ /**
1061
+ * @returns {Promise<Pack>} pack
1062
+ */
1042
1063
  _getPack() {
1043
1064
  if (this.packPromise === undefined) {
1044
1065
  this.packPromise = this.storePromise.then(() => this._openPack());
@@ -120,7 +120,7 @@ const resolve = browsers => {
120
120
  and_qq: [10, 4],
121
121
  // baidu: Not supported
122
122
  // and_uc: Not supported
123
- // kaios: Not supported
123
+ kaios: [3, 0],
124
124
  node: [12, 17]
125
125
  });
126
126
 
@@ -187,7 +187,7 @@ const resolve = browsers => {
187
187
  // and_qq: Unknown support
188
188
  // baidu: Unknown support
189
189
  // and_uc: Unknown support
190
- // kaios: Unknown support
190
+ kaios: [3, 0],
191
191
  node: [0, 12]
192
192
  }),
193
193
  destructuring: rawChecker({
@@ -206,7 +206,7 @@ const resolve = browsers => {
206
206
  // and_qq: Unknown support
207
207
  // baidu: Unknown support
208
208
  // and_uc: Unknown support
209
- // kaios: Unknown support
209
+ kaios: [2, 5],
210
210
  node: [6, 0]
211
211
  }),
212
212
  bigIntLiteral: rawChecker({
@@ -225,7 +225,7 @@ const resolve = browsers => {
225
225
  // and_qq: Not supported
226
226
  // baidu: Not supported
227
227
  // and_uc: Not supported
228
- // kaios: Not supported
228
+ kaios: [3, 0],
229
229
  node: [10, 4]
230
230
  }),
231
231
  // Support syntax `import` and `export` and no limitations and bugs on Node.js
@@ -246,7 +246,7 @@ const resolve = browsers => {
246
246
  and_qq: [10, 4],
247
247
  // baidu: Not supported
248
248
  // and_uc: Not supported
249
- // kaios: Not supported
249
+ kaios: [3, 0],
250
250
  node: [12, 17]
251
251
  }),
252
252
  dynamicImport: es6DynamicImport,
@@ -269,7 +269,7 @@ const resolve = browsers => {
269
269
  // and_qq: Unknown support
270
270
  // baidu: Unknown support
271
271
  // and_uc: Unknown support
272
- // kaios: Unknown support
272
+ kaios: [3, 0],
273
273
  node: 12
274
274
  }),
275
275
  optionalChaining: rawChecker({
@@ -288,7 +288,7 @@ const resolve = browsers => {
288
288
  // and_qq: Not supported
289
289
  // baidu: Not supported
290
290
  // and_uc: Not supported
291
- // kaios: Not supported
291
+ kaios: [3, 0],
292
292
  node: 14
293
293
  }),
294
294
  templateLiteral: rawChecker({
@@ -15,7 +15,9 @@ const {
15
15
  JAVASCRIPT_MODULE_TYPE_DYNAMIC,
16
16
  WEBASSEMBLY_MODULE_TYPE_SYNC,
17
17
  ASSET_MODULE_TYPE,
18
- CSS_MODULE_TYPE
18
+ CSS_MODULE_TYPE_AUTO,
19
+ CSS_MODULE_TYPE,
20
+ CSS_MODULE_TYPE_MODULE
19
21
  } = require("../ModuleTypeConstants");
20
22
  const Template = require("../Template");
21
23
  const { cleverMerge } = require("../util/cleverMerge");
@@ -708,38 +710,24 @@ const applyModuleDefaults = (
708
710
  });
709
711
  }
710
712
  if (css) {
711
- const cssRule = {
712
- type: CSS_MODULE_TYPE,
713
- resolve: {
714
- fullySpecified: true,
715
- preferRelative: true
716
- }
717
- };
718
- const cssModulesRule = {
719
- type: "css/module",
720
- resolve: {
721
- fullySpecified: true
722
- }
713
+ const resolve = {
714
+ fullySpecified: true,
715
+ preferRelative: true
723
716
  };
724
717
  rules.push({
725
718
  test: /\.css$/i,
726
- oneOf: [
727
- {
728
- test: /\.module\.css$/i,
729
- ...cssModulesRule
730
- },
731
- {
732
- ...cssRule
733
- }
734
- ]
719
+ type: CSS_MODULE_TYPE_AUTO,
720
+ resolve
735
721
  });
736
722
  rules.push({
737
723
  mimetype: "text/css+module",
738
- ...cssModulesRule
724
+ type: CSS_MODULE_TYPE_MODULE,
725
+ resolve
739
726
  });
740
727
  rules.push({
741
728
  mimetype: "text/css",
742
- ...cssRule
729
+ type: CSS_MODULE_TYPE,
730
+ resolve
743
731
  });
744
732
  }
745
733
  rules.push(
@@ -18,7 +18,7 @@ class RemoteRuntimeModule extends RuntimeModule {
18
18
  }
19
19
 
20
20
  /**
21
- * @returns {string} runtime code
21
+ * @returns {string | null} runtime code
22
22
  */
23
23
  generate() {
24
24
  const { compilation, chunkGraph } = this;
@@ -56,7 +56,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
56
56
  }
57
57
 
58
58
  /**
59
- * @returns {string} runtime code
59
+ * @returns {string | null} runtime code
60
60
  */
61
61
  generate() {
62
62
  const { compilation, chunk, _runtimeRequirements } = this;
@@ -135,6 +135,14 @@ class CssLoadingRuntimeModule extends RuntimeModule {
135
135
 
136
136
  /** @type {(str: string) => number} */
137
137
  const cc = str => str.charCodeAt(0);
138
+ const name = uniqueName
139
+ ? runtimeTemplate.concatenation(
140
+ "--webpack-",
141
+ { expr: "uniqueName" },
142
+ "-",
143
+ { expr: "chunkId" }
144
+ )
145
+ : runtimeTemplate.concatenation("--webpack-", { expr: "chunkId" });
138
146
 
139
147
  return Template.asString([
140
148
  "// object to store loaded and loading chunks",
@@ -157,18 +165,27 @@ class CssLoadingRuntimeModule extends RuntimeModule {
157
165
  [
158
166
  `var data, token = "", token2, exports = {}, exportsWithId = [], exportsWithDashes = [], ${
159
167
  withHmr ? "moduleIds = [], " : ""
160
- }i = 0, cc = 1;`,
161
- "try { if(!link) link = loadStylesheet(chunkId); data = link.sheet.cssRules; data = data[data.length - 1].style; } catch(e) { data = getComputedStyle(document.head); }",
162
- `data = data.getPropertyValue(${
163
- uniqueName
164
- ? runtimeTemplate.concatenation(
165
- "--webpack-",
166
- { expr: "uniqueName" },
167
- "-",
168
- { expr: "chunkId" }
169
- )
170
- : runtimeTemplate.concatenation("--webpack-", { expr: "chunkId" })
171
- });`,
168
+ }name = ${name}, i = 0, cc = 1;`,
169
+ "try {",
170
+ Template.indent([
171
+ "if(!link) link = loadStylesheet(chunkId);",
172
+ // `link.sheet.rules` for legacy browsers
173
+ "var cssRules = link.sheet.cssRules || link.sheet.rules;",
174
+ "var j = cssRules.length - 1;",
175
+ "while(j > -1 && !data) {",
176
+ Template.indent([
177
+ "var style = cssRules[j--].style;",
178
+ "if(!style) continue;",
179
+ `data = style.getPropertyValue(name);`
180
+ ]),
181
+ "}"
182
+ ]),
183
+ "}catch(e){}",
184
+ "if(!data) {",
185
+ Template.indent([
186
+ "data = getComputedStyle(document.head).getPropertyValue(name);"
187
+ ]),
188
+ "}",
172
189
  "if(!data) return [];",
173
190
  "for(; cc; i++) {",
174
191
  Template.indent([
@@ -39,7 +39,7 @@ const IMAGE_SET_FUNCTION = /^(-\w+-)?image-set$/i;
39
39
  const OPTIONALLY_VENDOR_PREFIXED_KEYFRAMES_AT_RULE = /^@(-\w+-)?keyframes$/;
40
40
  const OPTIONALLY_VENDOR_PREFIXED_ANIMATION_PROPERTY =
41
41
  /^(-\w+-)?animation(-name)?$/i;
42
- const IS_MODULES = /\.module(s)?\.\w+$/i;
42
+ const IS_MODULES = /\.module(s)?\.[^.]+$/i;
43
43
 
44
44
  /**
45
45
  * @param {string} str url string
@@ -172,12 +172,18 @@ class CssParser extends Parser {
172
172
  }
173
173
 
174
174
  const module = state.module;
175
+
176
+ /** @type {string | undefined} */
177
+ let oldDefaultMode;
178
+
175
179
  if (
176
180
  module.type === CSS_MODULE_TYPE_AUTO &&
177
181
  IS_MODULES.test(
178
182
  parseResource(module.matchResource || module.resource).path
179
183
  )
180
184
  ) {
185
+ oldDefaultMode = this.defaultMode;
186
+
181
187
  this.defaultMode = "local";
182
188
  }
183
189
 
@@ -1013,6 +1019,10 @@ class CssParser extends Parser {
1013
1019
  }
1014
1020
  });
1015
1021
 
1022
+ if (oldDefaultMode) {
1023
+ this.defaultMode = oldDefaultMode;
1024
+ }
1025
+
1016
1026
  module.buildInfo.strict = true;
1017
1027
  module.buildMeta.exportsType = "namespace";
1018
1028
  module.addDependency(new StaticExportsDependency([], true));
@@ -180,6 +180,10 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
180
180
  this.replace(dep, source, definition, content);
181
181
  }
182
182
 
183
+ /**
184
+ * @param {AMDDefineDependency} dependency dependency
185
+ * @returns {string} variable name
186
+ */
183
187
  localModuleVar(dependency) {
184
188
  return (
185
189
  dependency.localModule &&
@@ -188,6 +192,10 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
188
192
  );
189
193
  }
190
194
 
195
+ /**
196
+ * @param {AMDDefineDependency} dependency dependency
197
+ * @returns {string} branch
198
+ */
191
199
  branch(dependency) {
192
200
  const localModuleVar = this.localModuleVar(dependency) ? "l" : "";
193
201
  const arrayRange = dependency.arrayRange ? "a" : "";
@@ -196,6 +204,12 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
196
204
  return localModuleVar + arrayRange + objectRange + functionRange;
197
205
  }
198
206
 
207
+ /**
208
+ * @param {AMDDefineDependency} dependency dependency
209
+ * @param {ReplaceSource} source source
210
+ * @param {string} definition definition
211
+ * @param {string} text text
212
+ */
199
213
  replace(dependency, source, definition, text) {
200
214
  const localModuleVar = this.localModuleVar(dependency);
201
215
  if (localModuleVar) {
@@ -216,18 +230,34 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
216
230
 
217
231
  let current = dependency.range[0];
218
232
  if (dependency.arrayRange) {
219
- source.replace(current, dependency.arrayRange[0] - 1, texts.shift());
233
+ source.replace(
234
+ current,
235
+ dependency.arrayRange[0] - 1,
236
+ /** @type {string} */ (texts.shift())
237
+ );
220
238
  current = dependency.arrayRange[1];
221
239
  }
222
240
 
223
241
  if (dependency.objectRange) {
224
- source.replace(current, dependency.objectRange[0] - 1, texts.shift());
242
+ source.replace(
243
+ current,
244
+ dependency.objectRange[0] - 1,
245
+ /** @type {string} */ (texts.shift())
246
+ );
225
247
  current = dependency.objectRange[1];
226
248
  } else if (dependency.functionRange) {
227
- source.replace(current, dependency.functionRange[0] - 1, texts.shift());
249
+ source.replace(
250
+ current,
251
+ dependency.functionRange[0] - 1,
252
+ /** @type {string} */ (texts.shift())
253
+ );
228
254
  current = dependency.functionRange[1];
229
255
  }
230
- source.replace(current, dependency.range[1] - 1, texts.shift());
256
+ source.replace(
257
+ current,
258
+ dependency.range[1] - 1,
259
+ /** @type {string} */ (texts.shift())
260
+ );
231
261
  if (texts.length > 0) throw new Error("Implementation error");
232
262
  }
233
263
  };
@@ -16,8 +16,13 @@ const DynamicExports = require("./DynamicExports");
16
16
  const LocalModuleDependency = require("./LocalModuleDependency");
17
17
  const { addLocalModule, getLocalModule } = require("./LocalModulesHelpers");
18
18
 
19
+ /** @typedef {import("estree").CallExpression} CallExpression */
19
20
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
20
21
 
22
+ /**
23
+ * @param {CallExpression} expr expression
24
+ * @returns {boolean} true if it's a bound function expression
25
+ */
21
26
  const isBoundFunctionExpression = expr => {
22
27
  if (expr.type !== "CallExpression") return false;
23
28
  if (expr.callee.type !== "MemberExpression") return false;
@@ -14,7 +14,7 @@ class AMDDefineRuntimeModule extends RuntimeModule {
14
14
  }
15
15
 
16
16
  /**
17
- * @returns {string} runtime code
17
+ * @returns {string | null} runtime code
18
18
  */
19
19
  generate() {
20
20
  return Template.asString([
@@ -35,7 +35,7 @@ class AMDOptionsRuntimeModule extends RuntimeModule {
35
35
  }
36
36
 
37
37
  /**
38
- * @returns {string} runtime code
38
+ * @returns {string | null} runtime code
39
39
  */
40
40
  generate() {
41
41
  return Template.asString([
@@ -21,6 +21,7 @@ const ModuleDecoratorDependency = require("./ModuleDecoratorDependency");
21
21
  /** @typedef {import("estree").Expression} Expression */
22
22
  /** @typedef {import("estree").Super} Super */
23
23
 
24
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
24
25
  /** @typedef {import("../NormalModule")} NormalModule */
25
26
  /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
26
27
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
@@ -43,7 +44,7 @@ const ModuleDecoratorDependency = require("./ModuleDecoratorDependency");
43
44
  * ```
44
45
  *
45
46
  * @param {TODO} expr expression
46
- * @returns {Expression} returns the value of property descriptor
47
+ * @returns {Expression | undefined} returns the value of property descriptor
47
48
  */
48
49
  const getValueOfPropertyDescription = expr => {
49
50
  if (expr.type !== "ObjectExpression") return;
@@ -127,6 +128,9 @@ const parseRequireCall = (parser, expr) => {
127
128
  };
128
129
 
129
130
  class CommonJsExportsParserPlugin {
131
+ /**
132
+ * @param {ModuleGraph} moduleGraph module graph
133
+ */
130
134
  constructor(moduleGraph) {
131
135
  this.moduleGraph = moduleGraph;
132
136
  }
@@ -143,7 +147,7 @@ class CommonJsExportsParserPlugin {
143
147
  /**
144
148
  * @param {boolean} topLevel true, when the export is on top level
145
149
  * @param {string[]} members members of the export
146
- * @param {Expression} valueExpr expression for the value
150
+ * @param {Expression | undefined} valueExpr expression for the value
147
151
  * @returns {void}
148
152
  */
149
153
  const checkNamespace = (topLevel, members, valueExpr) => {
@@ -156,10 +160,16 @@ class CommonJsExportsParserPlugin {
156
160
  }
157
161
  }
158
162
  };
163
+ /**
164
+ * @param {string=} reason reason
165
+ */
159
166
  const bailout = reason => {
160
167
  DynamicExports.bailout(parser.state);
161
168
  if (reason) bailoutHint(reason);
162
169
  };
170
+ /**
171
+ * @param {string} reason reason
172
+ */
163
173
  const bailoutHint = reason => {
164
174
  this.moduleGraph
165
175
  .getOptimizationBailout(parser.state.module)
@@ -292,8 +302,8 @@ class CommonJsExportsParserPlugin {
292
302
  * @param {Expression | Super} expr expression
293
303
  * @param {CommonJSDependencyBaseKeywords} base commonjs base keywords
294
304
  * @param {string[]} members members of the export
295
- * @param {CallExpression} call call expression
296
- * @returns {boolean} true, when the expression was handled
305
+ * @param {CallExpression=} call call expression
306
+ * @returns {boolean | void} true, when the expression was handled
297
307
  */
298
308
  const handleAccessExport = (expr, base, members, call = undefined) => {
299
309
  if (HarmonyExports.isEnabled(parser.state)) return;