webpack 5.77.0 → 5.79.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 (82) hide show
  1. package/bin/webpack.js +0 -0
  2. package/lib/APIPlugin.js +25 -18
  3. package/lib/CompatibilityPlugin.js +80 -62
  4. package/lib/Compiler.js +7 -4
  5. package/lib/ConstPlugin.js +22 -15
  6. package/lib/ContextModule.js +3 -2
  7. package/lib/DefinePlugin.js +62 -42
  8. package/lib/DelegatedModule.js +2 -1
  9. package/lib/DllModule.js +2 -1
  10. package/lib/ErrorHelpers.js +61 -22
  11. package/lib/ExportsInfoApiPlugin.js +16 -9
  12. package/lib/ExternalModule.js +2 -1
  13. package/lib/FlagAllModulesAsUsedPlugin.js +22 -27
  14. package/lib/FlagDependencyExportsPlugin.js +336 -348
  15. package/lib/FlagDependencyUsagePlugin.js +6 -8
  16. package/lib/FlagEntryExportAsUsedPlugin.js +22 -23
  17. package/lib/HotModuleReplacementPlugin.js +50 -45
  18. package/lib/JavascriptMetaInfoPlugin.js +16 -9
  19. package/lib/LibManifestPlugin.js +2 -1
  20. package/lib/ModuleTypeConstants.js +50 -0
  21. package/lib/NodeStuffPlugin.js +35 -31
  22. package/lib/NormalModule.js +2 -1
  23. package/lib/NormalModuleFactory.js +7 -1
  24. package/lib/NormalModuleReplacementPlugin.js +1 -1
  25. package/lib/ProvidePlugin.js +17 -10
  26. package/lib/RawModule.js +2 -1
  27. package/lib/RequireJsStuffPlugin.js +15 -15
  28. package/lib/UseStrictPlugin.js +15 -8
  29. package/lib/WebpackIsIncludedPlugin.js +16 -9
  30. package/lib/config/defaults.js +16 -8
  31. package/lib/config/normalization.js +4 -0
  32. package/lib/container/ContainerEntryModule.js +2 -1
  33. package/lib/css/CssLoadingRuntimeModule.js +1 -1
  34. package/lib/css/CssParser.js +28 -8
  35. package/lib/css/walkCssTokens.js +6 -1
  36. package/lib/debug/ProfilingPlugin.js +20 -12
  37. package/lib/dependencies/AMDPlugin.js +26 -20
  38. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -4
  39. package/lib/dependencies/CommonJsPlugin.js +29 -25
  40. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  41. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +4 -0
  42. package/lib/dependencies/HarmonyImportSpecifierDependency.js +28 -3
  43. package/lib/dependencies/HarmonyModulesPlugin.js +11 -5
  44. package/lib/dependencies/ImportMetaContextPlugin.js +11 -5
  45. package/lib/dependencies/ImportMetaPlugin.js +26 -20
  46. package/lib/dependencies/ImportPlugin.js +14 -7
  47. package/lib/dependencies/RequireContextPlugin.js +12 -6
  48. package/lib/dependencies/RequireEnsurePlugin.js +13 -7
  49. package/lib/dependencies/RequireIncludePlugin.js +11 -5
  50. package/lib/dependencies/SystemPlugin.js +21 -15
  51. package/lib/dependencies/URLPlugin.js +15 -9
  52. package/lib/dependencies/WorkerPlugin.js +14 -8
  53. package/lib/index.js +5 -0
  54. package/lib/javascript/JavascriptModulesPlugin.js +157 -164
  55. package/lib/javascript/JavascriptParser.js +88 -0
  56. package/lib/json/JsonModulesPlugin.js +13 -5
  57. package/lib/library/AmdLibraryPlugin.js +22 -6
  58. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  59. package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
  60. package/lib/optimize/ConcatenatedModule.js +2 -1
  61. package/lib/optimize/InnerGraphPlugin.js +47 -46
  62. package/lib/optimize/SideEffectsFlagPlugin.js +43 -43
  63. package/lib/sharing/ConsumeSharedPlugin.js +4 -0
  64. package/lib/stats/DefaultStatsPrinterPlugin.js +14 -0
  65. package/lib/util/hash/md4.js +2 -2
  66. package/lib/util/hash/xxhash64.js +1 -1
  67. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +9 -6
  68. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +42 -43
  69. package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -1
  70. package/lib/web/FetchCompileWasmPlugin.js +40 -40
  71. package/lib/webpack.js +1 -1
  72. package/package.json +41 -36
  73. package/schemas/WebpackOptions.check.js +1 -1
  74. package/schemas/WebpackOptions.json +18 -0
  75. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  76. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  77. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  78. package/schemas/plugins/container/ContainerPlugin.json +8 -0
  79. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  80. package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
  81. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  82. package/types.d.ts +152 -122
@@ -18,6 +18,11 @@ const Compilation = require("../Compilation");
18
18
  const { tryRunOrWebpackError } = require("../HookWebpackError");
19
19
  const HotUpdateChunk = require("../HotUpdateChunk");
20
20
  const InitFragment = require("../InitFragment");
21
+ const {
22
+ JAVASCRIPT_MODULE_TYPE_AUTO,
23
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC,
24
+ JAVASCRIPT_MODULE_TYPE_ESM
25
+ } = require("../ModuleTypeConstants");
21
26
  const RuntimeGlobals = require("../RuntimeGlobals");
22
27
  const Template = require("../Template");
23
28
  const { last, someInIterable } = require("../util/IterableHelpers");
@@ -133,6 +138,8 @@ const printGeneratedCodeForStack = (module, code) => {
133
138
  /** @type {WeakMap<Compilation, CompilationHooks>} */
134
139
  const compilationHooksMap = new WeakMap();
135
140
 
141
+ const PLUGIN_NAME = "JavascriptModulesPlugin";
142
+
136
143
  class JavascriptModulesPlugin {
137
144
  /**
138
145
  * @param {Compilation} compilation the compilation
@@ -196,154 +203,147 @@ class JavascriptModulesPlugin {
196
203
  */
197
204
  apply(compiler) {
198
205
  compiler.hooks.compilation.tap(
199
- "JavascriptModulesPlugin",
206
+ PLUGIN_NAME,
200
207
  (compilation, { normalModuleFactory }) => {
201
208
  const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
202
209
  normalModuleFactory.hooks.createParser
203
- .for("javascript/auto")
204
- .tap("JavascriptModulesPlugin", options => {
210
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
211
+ .tap(PLUGIN_NAME, options => {
205
212
  return new JavascriptParser("auto");
206
213
  });
207
214
  normalModuleFactory.hooks.createParser
208
- .for("javascript/dynamic")
209
- .tap("JavascriptModulesPlugin", options => {
215
+ .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
216
+ .tap(PLUGIN_NAME, options => {
210
217
  return new JavascriptParser("script");
211
218
  });
212
219
  normalModuleFactory.hooks.createParser
213
- .for("javascript/esm")
214
- .tap("JavascriptModulesPlugin", options => {
220
+ .for(JAVASCRIPT_MODULE_TYPE_ESM)
221
+ .tap(PLUGIN_NAME, options => {
215
222
  return new JavascriptParser("module");
216
223
  });
217
224
  normalModuleFactory.hooks.createGenerator
218
- .for("javascript/auto")
219
- .tap("JavascriptModulesPlugin", () => {
225
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
226
+ .tap(PLUGIN_NAME, () => {
220
227
  return new JavascriptGenerator();
221
228
  });
222
229
  normalModuleFactory.hooks.createGenerator
223
- .for("javascript/dynamic")
224
- .tap("JavascriptModulesPlugin", () => {
230
+ .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
231
+ .tap(PLUGIN_NAME, () => {
225
232
  return new JavascriptGenerator();
226
233
  });
227
234
  normalModuleFactory.hooks.createGenerator
228
- .for("javascript/esm")
229
- .tap("JavascriptModulesPlugin", () => {
235
+ .for(JAVASCRIPT_MODULE_TYPE_ESM)
236
+ .tap(PLUGIN_NAME, () => {
230
237
  return new JavascriptGenerator();
231
238
  });
232
- compilation.hooks.renderManifest.tap(
233
- "JavascriptModulesPlugin",
234
- (result, options) => {
235
- const {
236
- hash,
237
- chunk,
238
- chunkGraph,
239
- moduleGraph,
240
- runtimeTemplate,
241
- dependencyTemplates,
242
- outputOptions,
243
- codeGenerationResults
244
- } = options;
239
+ compilation.hooks.renderManifest.tap(PLUGIN_NAME, (result, options) => {
240
+ const {
241
+ hash,
242
+ chunk,
243
+ chunkGraph,
244
+ moduleGraph,
245
+ runtimeTemplate,
246
+ dependencyTemplates,
247
+ outputOptions,
248
+ codeGenerationResults
249
+ } = options;
245
250
 
246
- const hotUpdateChunk =
247
- chunk instanceof HotUpdateChunk ? chunk : null;
251
+ const hotUpdateChunk = chunk instanceof HotUpdateChunk ? chunk : null;
248
252
 
249
- let render;
250
- const filenameTemplate =
251
- JavascriptModulesPlugin.getChunkFilenameTemplate(
252
- chunk,
253
- outputOptions
253
+ let render;
254
+ const filenameTemplate =
255
+ JavascriptModulesPlugin.getChunkFilenameTemplate(
256
+ chunk,
257
+ outputOptions
258
+ );
259
+ if (hotUpdateChunk) {
260
+ render = () =>
261
+ this.renderChunk(
262
+ {
263
+ chunk,
264
+ dependencyTemplates,
265
+ runtimeTemplate,
266
+ moduleGraph,
267
+ chunkGraph,
268
+ codeGenerationResults,
269
+ strictMode: runtimeTemplate.isModule()
270
+ },
271
+ hooks
254
272
  );
255
- if (hotUpdateChunk) {
256
- render = () =>
257
- this.renderChunk(
258
- {
259
- chunk,
260
- dependencyTemplates,
261
- runtimeTemplate,
262
- moduleGraph,
263
- chunkGraph,
264
- codeGenerationResults,
265
- strictMode: runtimeTemplate.isModule()
266
- },
267
- hooks
268
- );
269
- } else if (chunk.hasRuntime()) {
270
- render = () =>
271
- this.renderMain(
272
- {
273
- hash,
274
- chunk,
275
- dependencyTemplates,
276
- runtimeTemplate,
277
- moduleGraph,
278
- chunkGraph,
279
- codeGenerationResults,
280
- strictMode: runtimeTemplate.isModule()
281
- },
282
- hooks,
283
- compilation
284
- );
285
- } else {
286
- if (!chunkHasJs(chunk, chunkGraph)) {
287
- return result;
288
- }
289
-
290
- render = () =>
291
- this.renderChunk(
292
- {
293
- chunk,
294
- dependencyTemplates,
295
- runtimeTemplate,
296
- moduleGraph,
297
- chunkGraph,
298
- codeGenerationResults,
299
- strictMode: runtimeTemplate.isModule()
300
- },
301
- hooks
302
- );
273
+ } else if (chunk.hasRuntime()) {
274
+ render = () =>
275
+ this.renderMain(
276
+ {
277
+ hash,
278
+ chunk,
279
+ dependencyTemplates,
280
+ runtimeTemplate,
281
+ moduleGraph,
282
+ chunkGraph,
283
+ codeGenerationResults,
284
+ strictMode: runtimeTemplate.isModule()
285
+ },
286
+ hooks,
287
+ compilation
288
+ );
289
+ } else {
290
+ if (!chunkHasJs(chunk, chunkGraph)) {
291
+ return result;
303
292
  }
304
293
 
305
- result.push({
306
- render,
307
- filenameTemplate,
308
- pathOptions: {
309
- hash,
310
- runtime: chunk.runtime,
311
- chunk,
312
- contentHashType: "javascript"
313
- },
314
- info: {
315
- javascriptModule: compilation.runtimeTemplate.isModule()
316
- },
317
- identifier: hotUpdateChunk
318
- ? `hotupdatechunk${chunk.id}`
319
- : `chunk${chunk.id}`,
320
- hash: chunk.contentHash.javascript
321
- });
322
-
323
- return result;
324
- }
325
- );
326
- compilation.hooks.chunkHash.tap(
327
- "JavascriptModulesPlugin",
328
- (chunk, hash, context) => {
329
- hooks.chunkHash.call(chunk, hash, context);
330
- if (chunk.hasRuntime()) {
331
- this.updateHashWithBootstrap(
332
- hash,
294
+ render = () =>
295
+ this.renderChunk(
333
296
  {
334
- hash: "0000",
335
297
  chunk,
336
- codeGenerationResults: context.codeGenerationResults,
337
- chunkGraph: context.chunkGraph,
338
- moduleGraph: context.moduleGraph,
339
- runtimeTemplate: context.runtimeTemplate
298
+ dependencyTemplates,
299
+ runtimeTemplate,
300
+ moduleGraph,
301
+ chunkGraph,
302
+ codeGenerationResults,
303
+ strictMode: runtimeTemplate.isModule()
340
304
  },
341
305
  hooks
342
306
  );
343
- }
344
307
  }
345
- );
346
- compilation.hooks.contentHash.tap("JavascriptModulesPlugin", chunk => {
308
+
309
+ result.push({
310
+ render,
311
+ filenameTemplate,
312
+ pathOptions: {
313
+ hash,
314
+ runtime: chunk.runtime,
315
+ chunk,
316
+ contentHashType: "javascript"
317
+ },
318
+ info: {
319
+ javascriptModule: compilation.runtimeTemplate.isModule()
320
+ },
321
+ identifier: hotUpdateChunk
322
+ ? `hotupdatechunk${chunk.id}`
323
+ : `chunk${chunk.id}`,
324
+ hash: chunk.contentHash.javascript
325
+ });
326
+
327
+ return result;
328
+ });
329
+ compilation.hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash, context) => {
330
+ hooks.chunkHash.call(chunk, hash, context);
331
+ if (chunk.hasRuntime()) {
332
+ this.updateHashWithBootstrap(
333
+ hash,
334
+ {
335
+ hash: "0000",
336
+ chunk,
337
+ codeGenerationResults: context.codeGenerationResults,
338
+ chunkGraph: context.chunkGraph,
339
+ moduleGraph: context.moduleGraph,
340
+ runtimeTemplate: context.runtimeTemplate
341
+ },
342
+ hooks
343
+ );
344
+ }
345
+ });
346
+ compilation.hooks.contentHash.tap(PLUGIN_NAME, chunk => {
347
347
  const {
348
348
  chunkGraph,
349
349
  codeGenerationResults,
@@ -410,7 +410,7 @@ class JavascriptModulesPlugin {
410
410
  );
411
411
  });
412
412
  compilation.hooks.additionalTreeRuntimeRequirements.tap(
413
- "JavascriptModulesPlugin",
413
+ PLUGIN_NAME,
414
414
  (chunk, set, { chunkGraph }) => {
415
415
  if (
416
416
  !set.has(RuntimeGlobals.startupNoDefault) &&
@@ -421,58 +421,51 @@ class JavascriptModulesPlugin {
421
421
  }
422
422
  }
423
423
  );
424
- compilation.hooks.executeModule.tap(
425
- "JavascriptModulesPlugin",
426
- (options, context) => {
427
- const source =
428
- options.codeGenerationResult.sources.get("javascript");
429
- if (source === undefined) return;
430
- const { module, moduleObject } = options;
431
- const code = source.source();
424
+ compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => {
425
+ const source = options.codeGenerationResult.sources.get("javascript");
426
+ if (source === undefined) return;
427
+ const { module, moduleObject } = options;
428
+ const code = source.source();
432
429
 
433
- const fn = vm.runInThisContext(
434
- `(function(${module.moduleArgument}, ${module.exportsArgument}, __webpack_require__) {\n${code}\n/**/})`,
435
- {
436
- filename: module.identifier(),
437
- lineOffset: -1
438
- }
439
- );
440
- try {
441
- fn.call(
442
- moduleObject.exports,
443
- moduleObject,
444
- moduleObject.exports,
445
- context.__webpack_require__
446
- );
447
- } catch (e) {
448
- e.stack += printGeneratedCodeForStack(options.module, code);
449
- throw e;
430
+ const fn = vm.runInThisContext(
431
+ `(function(${module.moduleArgument}, ${module.exportsArgument}, __webpack_require__) {\n${code}\n/**/})`,
432
+ {
433
+ filename: module.identifier(),
434
+ lineOffset: -1
450
435
  }
436
+ );
437
+ try {
438
+ fn.call(
439
+ moduleObject.exports,
440
+ moduleObject,
441
+ moduleObject.exports,
442
+ context.__webpack_require__
443
+ );
444
+ } catch (e) {
445
+ e.stack += printGeneratedCodeForStack(options.module, code);
446
+ throw e;
451
447
  }
452
- );
453
- compilation.hooks.executeModule.tap(
454
- "JavascriptModulesPlugin",
455
- (options, context) => {
456
- const source = options.codeGenerationResult.sources.get("runtime");
457
- if (source === undefined) return;
458
- let code = source.source();
459
- if (typeof code !== "string") code = code.toString();
448
+ });
449
+ compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => {
450
+ const source = options.codeGenerationResult.sources.get("runtime");
451
+ if (source === undefined) return;
452
+ let code = source.source();
453
+ if (typeof code !== "string") code = code.toString();
460
454
 
461
- const fn = vm.runInThisContext(
462
- `(function(__webpack_require__) {\n${code}\n/**/})`,
463
- {
464
- filename: options.module.identifier(),
465
- lineOffset: -1
466
- }
467
- );
468
- try {
469
- fn.call(null, context.__webpack_require__);
470
- } catch (e) {
471
- e.stack += printGeneratedCodeForStack(options.module, code);
472
- throw e;
455
+ const fn = vm.runInThisContext(
456
+ `(function(__webpack_require__) {\n${code}\n/**/})`,
457
+ {
458
+ filename: options.module.identifier(),
459
+ lineOffset: -1
473
460
  }
461
+ );
462
+ try {
463
+ fn.call(null, context.__webpack_require__);
464
+ } catch (e) {
465
+ e.stack += printGeneratedCodeForStack(options.module, code);
466
+ throw e;
474
467
  }
475
- );
468
+ });
476
469
  }
477
470
  );
478
471
  }
@@ -331,6 +331,8 @@ class JavascriptParser extends Parser {
331
331
  /** @type {(StatementNode|ExpressionNode)[]} */
332
332
  this.statementPath = undefined;
333
333
  this.prevStatement = undefined;
334
+ /** @type {WeakMap<ExpressionNode, Set<string>>} */
335
+ this.destructuringAssignmentProperties = undefined;
334
336
  this.currentTagData = undefined;
335
337
  this._initializeEvaluating();
336
338
  }
@@ -1411,6 +1413,15 @@ class JavascriptParser extends Parser {
1411
1413
  });
1412
1414
  }
1413
1415
 
1416
+ /**
1417
+ * @param {ExpressionNode} node node
1418
+ * @returns {Set<string>|undefined} destructured identifiers
1419
+ */
1420
+ destructuringAssignmentPropertiesFor(node) {
1421
+ if (!this.destructuringAssignmentProperties) return undefined;
1422
+ return this.destructuringAssignmentProperties.get(node);
1423
+ }
1424
+
1414
1425
  getRenameIdentifier(expr) {
1415
1426
  const result = this.evaluateExpression(expr);
1416
1427
  if (result.isIdentifier()) {
@@ -1557,6 +1568,8 @@ class JavascriptParser extends Parser {
1557
1568
  case "ClassDeclaration":
1558
1569
  this.blockPreWalkClassDeclaration(statement);
1559
1570
  break;
1571
+ case "ExpressionStatement":
1572
+ this.blockPreWalkExpressionStatement(statement);
1560
1573
  }
1561
1574
  this.prevStatement = this.statementPath.pop();
1562
1575
  }
@@ -1890,6 +1903,37 @@ class JavascriptParser extends Parser {
1890
1903
  this.scope.topLevelScope = wasTopLevel;
1891
1904
  }
1892
1905
 
1906
+ blockPreWalkExpressionStatement(statement) {
1907
+ const expression = statement.expression;
1908
+ switch (expression.type) {
1909
+ case "AssignmentExpression":
1910
+ this.preWalkAssignmentExpression(expression);
1911
+ }
1912
+ }
1913
+
1914
+ preWalkAssignmentExpression(expression) {
1915
+ if (
1916
+ expression.left.type !== "ObjectPattern" ||
1917
+ !this.destructuringAssignmentProperties
1918
+ )
1919
+ return;
1920
+ const keys = this._preWalkObjectPattern(expression.left);
1921
+ if (!keys) return;
1922
+
1923
+ // check multiple assignments
1924
+ if (this.destructuringAssignmentProperties.has(expression)) {
1925
+ const set = this.destructuringAssignmentProperties.get(expression);
1926
+ this.destructuringAssignmentProperties.delete(expression);
1927
+ for (const id of set) keys.add(id);
1928
+ }
1929
+
1930
+ this.destructuringAssignmentProperties.set(expression.right, keys);
1931
+
1932
+ if (expression.right.type === "AssignmentExpression") {
1933
+ this.preWalkAssignmentExpression(expression.right);
1934
+ }
1935
+ }
1936
+
1893
1937
  blockPreWalkImportDeclaration(statement) {
1894
1938
  const source = statement.source.value;
1895
1939
  this.hooks.import.call(statement, source);
@@ -2087,6 +2131,7 @@ class JavascriptParser extends Parser {
2087
2131
  for (const declarator of statement.declarations) {
2088
2132
  switch (declarator.type) {
2089
2133
  case "VariableDeclarator": {
2134
+ this.preWalkVariableDeclarator(declarator);
2090
2135
  if (!this.hooks.preDeclarator.call(declarator, statement)) {
2091
2136
  this.enterPattern(declarator.id, (name, decl) => {
2092
2137
  let hook = hookMap.get(name);
@@ -2104,6 +2149,47 @@ class JavascriptParser extends Parser {
2104
2149
  }
2105
2150
  }
2106
2151
 
2152
+ _preWalkObjectPattern(objectPattern) {
2153
+ const ids = new Set();
2154
+ const properties = objectPattern.properties;
2155
+ for (let i = 0; i < properties.length; i++) {
2156
+ const property = properties[i];
2157
+ if (property.type !== "Property") return;
2158
+ const key = property.key;
2159
+ if (key.type === "Identifier") {
2160
+ ids.add(key.name);
2161
+ } else {
2162
+ const id = this.evaluateExpression(key);
2163
+ const str = id.asString();
2164
+ if (str) {
2165
+ ids.add(str);
2166
+ } else {
2167
+ // could not evaluate key
2168
+ return;
2169
+ }
2170
+ }
2171
+ }
2172
+
2173
+ return ids;
2174
+ }
2175
+
2176
+ preWalkVariableDeclarator(declarator) {
2177
+ if (
2178
+ !declarator.init ||
2179
+ declarator.id.type !== "ObjectPattern" ||
2180
+ !this.destructuringAssignmentProperties
2181
+ )
2182
+ return;
2183
+ const keys = this._preWalkObjectPattern(declarator.id);
2184
+
2185
+ if (!keys) return;
2186
+ this.destructuringAssignmentProperties.set(declarator.init, keys);
2187
+
2188
+ if (declarator.init.type === "AssignmentExpression") {
2189
+ this.preWalkAssignmentExpression(declarator.init);
2190
+ }
2191
+ }
2192
+
2107
2193
  walkVariableDeclaration(statement) {
2108
2194
  for (const declarator of statement.declarations) {
2109
2195
  switch (declarator.type) {
@@ -3367,12 +3453,14 @@ class JavascriptParser extends Parser {
3367
3453
  this.statementPath = [];
3368
3454
  this.prevStatement = undefined;
3369
3455
  if (this.hooks.program.call(ast, comments) === undefined) {
3456
+ this.destructuringAssignmentProperties = new WeakMap();
3370
3457
  this.detectMode(ast.body);
3371
3458
  this.preWalkStatements(ast.body);
3372
3459
  this.prevStatement = undefined;
3373
3460
  this.blockPreWalkStatements(ast.body);
3374
3461
  this.prevStatement = undefined;
3375
3462
  this.walkStatements(ast.body);
3463
+ this.destructuringAssignmentProperties = undefined;
3376
3464
  }
3377
3465
  this.hooks.finish.call(ast, comments);
3378
3466
  this.scope = oldScope;
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { JSON_MODULE_TYPE } = require("../ModuleTypeConstants");
8
9
  const createSchemaValidation = require("../util/create-schema-validation");
9
10
  const JsonGenerator = require("./JsonGenerator");
10
11
  const JsonParser = require("./JsonParser");
@@ -20,26 +21,33 @@ const validate = createSchemaValidation(
20
21
  }
21
22
  );
22
23
 
24
+ const PLUGIN_NAME = "JsonModulesPlugin";
25
+
26
+ /**
27
+ * The JsonModulesPlugin is the entrypoint plugin for the json modules feature.
28
+ * It adds the json module type to the compiler and registers the json parser and generator.
29
+ */
23
30
  class JsonModulesPlugin {
24
31
  /**
25
32
  * Apply the plugin
26
33
  * @param {Compiler} compiler the compiler instance
27
34
  * @returns {void}
35
+ *
28
36
  */
29
37
  apply(compiler) {
30
38
  compiler.hooks.compilation.tap(
31
- "JsonModulesPlugin",
39
+ PLUGIN_NAME,
32
40
  (compilation, { normalModuleFactory }) => {
33
41
  normalModuleFactory.hooks.createParser
34
- .for("json")
35
- .tap("JsonModulesPlugin", parserOptions => {
42
+ .for(JSON_MODULE_TYPE)
43
+ .tap(PLUGIN_NAME, parserOptions => {
36
44
  validate(parserOptions);
37
45
 
38
46
  return new JsonParser(parserOptions);
39
47
  });
40
48
  normalModuleFactory.hooks.createGenerator
41
- .for("json")
42
- .tap("JsonModulesPlugin", () => {
49
+ .for(JSON_MODULE_TYPE)
50
+ .tap(PLUGIN_NAME, () => {
43
51
  return new JsonGenerator();
44
52
  });
45
53
  }
@@ -29,6 +29,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
29
29
  /**
30
30
  * @typedef {Object} AmdLibraryPluginParsed
31
31
  * @property {string} name
32
+ * @property {string} amdContainer
32
33
  */
33
34
 
34
35
  /**
@@ -52,7 +53,7 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
52
53
  * @returns {T | false} preprocess as needed by overriding
53
54
  */
54
55
  parseOptions(library) {
55
- const { name } = library;
56
+ const { name, amdContainer } = library;
56
57
  if (this.requireAsWrapper) {
57
58
  if (name) {
58
59
  throw new Error(
@@ -67,7 +68,8 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
67
68
  }
68
69
  }
69
70
  return {
70
- name: /** @type {string=} */ (name)
71
+ name: /** @type {string=} */ (name),
72
+ amdContainer: /** @type {string=} */ (amdContainer)
71
73
  };
72
74
  }
73
75
 
@@ -111,9 +113,14 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
111
113
  (iife || !chunk.hasRuntime() ? " return " : "\n");
112
114
  const fnEnd = iife ? ";\n}" : "\n}";
113
115
 
116
+ let amdContainerPrefix = "";
117
+ if (options.amdContainer) {
118
+ amdContainerPrefix = `${options.amdContainer}.`;
119
+ }
120
+
114
121
  if (this.requireAsWrapper) {
115
122
  return new ConcatSource(
116
- `require(${externalsDepsArray}, ${fnStart}`,
123
+ `${amdContainerPrefix}require(${externalsDepsArray}, ${fnStart}`,
117
124
  source,
118
125
  `${fnEnd});`
119
126
  );
@@ -123,18 +130,24 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
123
130
  });
124
131
 
125
132
  return new ConcatSource(
126
- `define(${JSON.stringify(name)}, ${externalsDepsArray}, ${fnStart}`,
133
+ `${amdContainerPrefix}define(${JSON.stringify(
134
+ name
135
+ )}, ${externalsDepsArray}, ${fnStart}`,
127
136
  source,
128
137
  `${fnEnd});`
129
138
  );
130
139
  } else if (externalsArguments) {
131
140
  return new ConcatSource(
132
- `define(${externalsDepsArray}, ${fnStart}`,
141
+ `${amdContainerPrefix}define(${externalsDepsArray}, ${fnStart}`,
133
142
  source,
134
143
  `${fnEnd});`
135
144
  );
136
145
  } else {
137
- return new ConcatSource(`define(${fnStart}`, source, `${fnEnd});`);
146
+ return new ConcatSource(
147
+ `${amdContainerPrefix}define(${fnStart}`,
148
+ source,
149
+ `${fnEnd});`
150
+ );
138
151
  }
139
152
  }
140
153
 
@@ -155,6 +168,9 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
155
168
  chunk
156
169
  });
157
170
  hash.update(name);
171
+ } else if (options.amdContainer) {
172
+ hash.update("amdContainer");
173
+ hash.update(options.amdContainer);
158
174
  }
159
175
  }
160
176
  }
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { WEBASSEMBLY_MODULE_TYPE_ASYNC } = require("../ModuleTypeConstants");
8
9
  const RuntimeGlobals = require("../RuntimeGlobals");
9
10
  const Template = require("../Template");
10
11
  const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRuntimeModule");
@@ -85,7 +86,7 @@ class ReadFileCompileAsyncWasmPlugin {
85
86
  if (
86
87
  !chunkGraph.hasModuleInGraph(
87
88
  chunk,
88
- m => m.type === "webassembly/async"
89
+ m => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC
89
90
  )
90
91
  ) {
91
92
  return;
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { WEBASSEMBLY_MODULE_TYPE_SYNC } = require("../ModuleTypeConstants");
8
9
  const RuntimeGlobals = require("../RuntimeGlobals");
9
10
  const Template = require("../Template");
10
11
  const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRuntimeModule");
@@ -69,7 +70,7 @@ class ReadFileCompileWasmPlugin {
69
70
  if (
70
71
  !chunkGraph.hasModuleInGraph(
71
72
  chunk,
72
- m => m.type === "webassembly/sync"
73
+ m => m.type === WEBASSEMBLY_MODULE_TYPE_SYNC
73
74
  )
74
75
  ) {
75
76
  return;