webpack 5.83.0 → 5.84.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 (137) hide show
  1. package/README.md +2 -2
  2. package/lib/CompatibilityPlugin.js +3 -2
  3. package/lib/Compilation.js +2 -2
  4. package/lib/ContextModule.js +3 -3
  5. package/lib/DefinePlugin.js +11 -2
  6. package/lib/DllEntryPlugin.js +5 -0
  7. package/lib/DllModule.js +1 -1
  8. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  9. package/lib/MainTemplate.js +2 -2
  10. package/lib/PrefetchPlugin.js +4 -0
  11. package/lib/RuntimeTemplate.js +5 -5
  12. package/lib/SelfModuleFactory.js +12 -0
  13. package/lib/SourceMapDevToolPlugin.js +9 -2
  14. package/lib/Template.js +2 -1
  15. package/lib/config/browserslistTargetHandler.js +3 -3
  16. package/lib/config/defaults.js +209 -70
  17. package/lib/config/normalization.js +103 -71
  18. package/lib/config/target.js +37 -10
  19. package/lib/container/FallbackModule.js +1 -1
  20. package/lib/container/RemoteRuntimeModule.js +1 -1
  21. package/lib/css/CssParser.js +168 -73
  22. package/lib/debug/ProfilingPlugin.js +11 -0
  23. package/lib/dependencies/AMDDefineDependency.js +12 -6
  24. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -2
  25. package/lib/dependencies/AMDPlugin.js +7 -0
  26. package/lib/dependencies/AMDRequireArrayDependency.js +5 -0
  27. package/lib/dependencies/AMDRequireContextDependency.js +6 -0
  28. package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
  29. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
  30. package/lib/dependencies/AMDRequireDependency.js +8 -1
  31. package/lib/dependencies/AMDRequireItemDependency.js +6 -0
  32. package/lib/dependencies/CachedConstDependency.js +6 -0
  33. package/lib/dependencies/CommonJsExportRequireDependency.js +11 -0
  34. package/lib/dependencies/CommonJsExportsDependency.js +8 -0
  35. package/lib/dependencies/CommonJsExportsParserPlugin.js +2 -2
  36. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -1
  37. package/lib/dependencies/CommonJsPlugin.js +14 -0
  38. package/lib/dependencies/CommonJsRequireContextDependency.js +8 -0
  39. package/lib/dependencies/CommonJsRequireDependency.js +7 -0
  40. package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
  41. package/lib/dependencies/ConstDependency.js +2 -1
  42. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  43. package/lib/dependencies/CreateScriptUrlDependency.js +2 -1
  44. package/lib/dependencies/CriticalDependencyWarning.js +3 -0
  45. package/lib/dependencies/CssImportDependency.js +2 -1
  46. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -1
  47. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  48. package/lib/dependencies/CssUrlDependency.js +12 -2
  49. package/lib/dependencies/DelegatedSourceDependency.js +3 -0
  50. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  51. package/lib/dependencies/HarmonyAcceptDependency.js +2 -1
  52. package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
  53. package/lib/dependencies/HarmonyDetectionParserPlugin.js +16 -0
  54. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +11 -0
  55. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -0
  56. package/lib/dependencies/HarmonyExportExpressionDependency.js +9 -1
  57. package/lib/dependencies/HarmonyExportHeaderDependency.js +5 -0
  58. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  59. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  60. package/lib/dependencies/HarmonyImportDependency.js +2 -1
  61. package/lib/dependencies/HarmonyImportSideEffectDependency.js +6 -0
  62. package/lib/dependencies/HarmonyImportSpecifierDependency.js +11 -0
  63. package/lib/dependencies/HarmonyModulesPlugin.js +12 -0
  64. package/lib/dependencies/ImportContextDependency.js +6 -0
  65. package/lib/dependencies/ImportDependency.js +2 -1
  66. package/lib/dependencies/ImportEagerDependency.js +2 -1
  67. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +32 -13
  68. package/lib/dependencies/ImportMetaContextPlugin.js +7 -0
  69. package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
  70. package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
  71. package/lib/dependencies/ImportParserPlugin.js +5 -0
  72. package/lib/dependencies/ImportPlugin.js +7 -0
  73. package/lib/dependencies/ImportWeakDependency.js +2 -1
  74. package/lib/dependencies/LocalModule.js +16 -0
  75. package/lib/dependencies/LocalModuleDependency.js +7 -0
  76. package/lib/dependencies/LocalModulesHelpers.js +18 -0
  77. package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
  78. package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
  79. package/lib/dependencies/PrefetchDependency.js +3 -0
  80. package/lib/dependencies/ProvidedDependency.js +2 -1
  81. package/lib/dependencies/PureExpressionDependency.js +2 -1
  82. package/lib/dependencies/RequireContextDependency.js +6 -0
  83. package/lib/dependencies/RequireContextPlugin.js +7 -0
  84. package/lib/dependencies/RequireEnsureDependenciesBlock.js +4 -0
  85. package/lib/dependencies/RequireEnsureDependency.js +8 -2
  86. package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
  87. package/lib/dependencies/RequireEnsurePlugin.js +14 -0
  88. package/lib/dependencies/RequireHeaderDependency.js +5 -1
  89. package/lib/dependencies/RequireIncludeDependency.js +5 -0
  90. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  91. package/lib/dependencies/RequireIncludePlugin.js +14 -0
  92. package/lib/dependencies/RequireResolveContextDependency.js +8 -0
  93. package/lib/dependencies/RequireResolveDependency.js +6 -0
  94. package/lib/dependencies/RequireResolveHeaderDependency.js +4 -0
  95. package/lib/dependencies/SystemPlugin.js +10 -1
  96. package/lib/dependencies/URLDependency.js +3 -2
  97. package/lib/dependencies/URLPlugin.js +7 -5
  98. package/lib/dependencies/UnsupportedDependency.js +5 -0
  99. package/lib/dependencies/WebAssemblyExportImportedDependency.js +6 -0
  100. package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
  101. package/lib/dependencies/WorkerDependency.js +2 -1
  102. package/lib/dependencies/WorkerPlugin.js +5 -2
  103. package/lib/dependencies/getFunctionExpression.js +7 -0
  104. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -1
  105. package/lib/esm/ModuleChunkFormatPlugin.js +2 -2
  106. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +5 -2
  107. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  108. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  109. package/lib/javascript/JavascriptModulesPlugin.js +13 -13
  110. package/lib/javascript/JavascriptParser.js +540 -180
  111. package/lib/javascript/StartupHelpers.js +1 -1
  112. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  113. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
  114. package/lib/optimize/ConcatenatedModule.js +1 -1
  115. package/lib/optimize/InnerGraphPlugin.js +11 -4
  116. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  117. package/lib/runtime/StartupEntrypointRuntimeModule.js +5 -5
  118. package/lib/serialization/ArraySerializer.js +22 -6
  119. package/lib/serialization/BinaryMiddleware.js +21 -0
  120. package/lib/serialization/DateObjectSerializer.js +15 -4
  121. package/lib/serialization/ErrorObjectSerializer.js +20 -8
  122. package/lib/serialization/FileMiddleware.js +17 -0
  123. package/lib/serialization/MapObjectSerializer.js +24 -8
  124. package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
  125. package/lib/serialization/ObjectMiddleware.js +23 -0
  126. package/lib/serialization/PlainObjectSerializer.js +23 -12
  127. package/lib/serialization/RegExpObjectSerializer.js +16 -5
  128. package/lib/serialization/SetObjectSerializer.js +21 -6
  129. package/lib/sharing/ShareRuntimeModule.js +1 -1
  130. package/lib/util/makeSerializable.js +7 -0
  131. package/lib/util/serialization.js +10 -0
  132. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -1
  133. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +5 -1
  134. package/package.json +3 -3
  135. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  136. package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
  137. package/types.d.ts +469 -149
@@ -19,6 +19,8 @@ const walkCssTokens = require("./walkCssTokens");
19
19
 
20
20
  /** @typedef {import("../Parser").ParserState} ParserState */
21
21
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
22
+ /** @typedef {[number, number]} Range */
23
+
22
24
  const CC_LEFT_CURLY = "{".charCodeAt(0);
23
25
  const CC_RIGHT_CURLY = "}".charCodeAt(0);
24
26
  const CC_COLON = ":".charCodeAt(0);
@@ -121,10 +123,9 @@ class LocConverter {
121
123
 
122
124
  const CSS_MODE_TOP_LEVEL = 0;
123
125
  const CSS_MODE_IN_BLOCK = 1;
124
- const CSS_MODE_AT_IMPORT_EXPECT_URL = 2;
125
- const CSS_MODE_AT_IMPORT_EXPECT_LAYER_OR_SUPPORTS_OR_MEDIA = 3;
126
- const CSS_MODE_AT_IMPORT_INVALID = 4;
127
- const CSS_MODE_AT_NAMESPACE_INVALID = 5;
126
+ const CSS_MODE_IN_AT_IMPORT = 2;
127
+ const CSS_MODE_AT_IMPORT_INVALID = 3;
128
+ const CSS_MODE_AT_NAMESPACE_INVALID = 4;
128
129
 
129
130
  class CssParser extends Parser {
130
131
  constructor({ allowModeSwitch = true, defaultMode = "global" } = {}) {
@@ -183,7 +184,7 @@ class CssParser extends Parser {
183
184
  let lastIdentifier = undefined;
184
185
  /** @type [string, number, number][] */
185
186
  let balanced = [];
186
- /** @type {undefined | { start: number, end: number, url?: string, media?: string, supports?: string, layer?: string }} */
187
+ /** @type {undefined | { start: number, url?: string, urlStart?: number, urlEnd?: number, layer?: string, layerStart?: number, layerEnd?: number, supports?: string, supportsStart?: number, supportsEnd?: number, inSupports?:boolean, media?: string }} */
187
188
  let importData = undefined;
188
189
  /** @type {boolean} */
189
190
  let inAnimationProperty = false;
@@ -405,15 +406,32 @@ class CssParser extends Parser {
405
406
  },
406
407
  url: (input, start, end, contentStart, contentEnd) => {
407
408
  let value = normalizeUrl(input.slice(contentStart, contentEnd), false);
409
+
408
410
  switch (scope) {
409
- case CSS_MODE_AT_IMPORT_EXPECT_URL: {
411
+ case CSS_MODE_IN_AT_IMPORT: {
412
+ // Do not parse URLs in `supports(...)`
413
+ if (importData.inSupports) {
414
+ break;
415
+ }
416
+
417
+ if (importData.url) {
418
+ this._emitWarning(
419
+ state,
420
+ `Duplicate of 'url(...)' in '${input.slice(
421
+ importData.start,
422
+ end
423
+ )}'`,
424
+ locConverter,
425
+ start,
426
+ end
427
+ );
428
+
429
+ break;
430
+ }
431
+
410
432
  importData.url = value;
411
- importData.end = end;
412
- scope = CSS_MODE_AT_IMPORT_EXPECT_LAYER_OR_SUPPORTS_OR_MEDIA;
413
- break;
414
- }
415
- // Do not parse URLs in `supports(...)`
416
- case CSS_MODE_AT_IMPORT_EXPECT_LAYER_OR_SUPPORTS_OR_MEDIA: {
433
+ importData.urlStart = start;
434
+ importData.urlEnd = end;
417
435
  break;
418
436
  }
419
437
  // Do not parse URLs in import between rules
@@ -440,23 +458,44 @@ class CssParser extends Parser {
440
458
  },
441
459
  string: (input, start, end) => {
442
460
  switch (scope) {
443
- case CSS_MODE_AT_IMPORT_EXPECT_URL: {
461
+ case CSS_MODE_IN_AT_IMPORT: {
462
+ const insideURLFunction =
463
+ balanced[balanced.length - 1] &&
464
+ balanced[balanced.length - 1][0] === "url";
465
+
466
+ // Do not parse URLs in `supports(...)` and other strings if we already have a URL
467
+ if (
468
+ importData.inSupports ||
469
+ (!insideURLFunction && importData.url)
470
+ ) {
471
+ break;
472
+ }
473
+
474
+ if (insideURLFunction && importData.url) {
475
+ this._emitWarning(
476
+ state,
477
+ `Duplicate of 'url(...)' in '${input.slice(
478
+ importData.start,
479
+ end
480
+ )}'`,
481
+ locConverter,
482
+ start,
483
+ end
484
+ );
485
+
486
+ break;
487
+ }
488
+
444
489
  importData.url = normalizeUrl(
445
490
  input.slice(start + 1, end - 1),
446
491
  true
447
492
  );
448
- importData.end = end;
449
- const insideURLFunction =
450
- balanced[balanced.length - 1] &&
451
- balanced[balanced.length - 1][0] === "url";
452
493
 
453
494
  if (!insideURLFunction) {
454
- scope = CSS_MODE_AT_IMPORT_EXPECT_LAYER_OR_SUPPORTS_OR_MEDIA;
495
+ importData.urlStart = start;
496
+ importData.urlEnd = end;
455
497
  }
456
- break;
457
- }
458
- // Do not parse URLs in `supports(...)`
459
- case CSS_MODE_AT_IMPORT_EXPECT_LAYER_OR_SUPPORTS_OR_MEDIA: {
498
+
460
499
  break;
461
500
  }
462
501
  case CSS_MODE_IN_BLOCK: {
@@ -497,7 +536,7 @@ class CssParser extends Parser {
497
536
  scope = CSS_MODE_AT_NAMESPACE_INVALID;
498
537
  this._emitWarning(
499
538
  state,
500
- "@namespace is not supported in bundled CSS",
539
+ "'@namespace' is not supported in bundled CSS",
501
540
  locConverter,
502
541
  start,
503
542
  end
@@ -508,7 +547,7 @@ class CssParser extends Parser {
508
547
  scope = CSS_MODE_AT_IMPORT_INVALID;
509
548
  this._emitWarning(
510
549
  state,
511
- "Any @import rules must precede all other rules",
550
+ "Any '@import' rules must precede all other rules",
512
551
  locConverter,
513
552
  start,
514
553
  end
@@ -516,8 +555,8 @@ class CssParser extends Parser {
516
555
  return end;
517
556
  }
518
557
 
519
- scope = CSS_MODE_AT_IMPORT_EXPECT_URL;
520
- importData = { start, end };
558
+ scope = CSS_MODE_IN_AT_IMPORT;
559
+ importData = { start };
521
560
  } else if (
522
561
  this.allowModeSwitch &&
523
562
  OPTIONALLY_VENDOR_PREFIXED_KEYFRAMES_AT_RULE.test(name)
@@ -598,54 +637,99 @@ class CssParser extends Parser {
598
637
  },
599
638
  semicolon: (input, start, end) => {
600
639
  switch (scope) {
601
- case CSS_MODE_AT_IMPORT_EXPECT_URL: {
602
- this._emitWarning(
603
- state,
604
- `Expected URL for @import at ${start}`,
605
- locConverter,
606
- start,
607
- end
608
- );
609
- return end;
610
- }
611
- case CSS_MODE_AT_IMPORT_EXPECT_LAYER_OR_SUPPORTS_OR_MEDIA: {
612
- if (!importData.url === undefined) {
640
+ case CSS_MODE_IN_AT_IMPORT: {
641
+ const { start } = importData;
642
+
643
+ if (importData.url === undefined) {
613
644
  this._emitWarning(
614
645
  state,
615
- `Expected URL for @import at ${importData.start}`,
646
+ `Expected URL in '${input.slice(start, end)}'`,
616
647
  locConverter,
617
- importData.start,
618
- importData.end
648
+ start,
649
+ end
619
650
  );
651
+ importData = undefined;
652
+ scope = CSS_MODE_TOP_LEVEL;
653
+ return end;
654
+ }
655
+ if (
656
+ importData.urlStart > importData.layerStart ||
657
+ importData.urlStart > importData.supportsStart
658
+ ) {
659
+ this._emitWarning(
660
+ state,
661
+ `An URL in '${input.slice(
662
+ start,
663
+ end
664
+ )}' should be before 'layer(...)' or 'supports(...)'`,
665
+ locConverter,
666
+ start,
667
+ end
668
+ );
669
+ importData = undefined;
670
+ scope = CSS_MODE_TOP_LEVEL;
620
671
  return end;
621
672
  }
673
+ if (importData.layerStart > importData.supportsStart) {
674
+ this._emitWarning(
675
+ state,
676
+ `The 'layer(...)' in '${input.slice(
677
+ start,
678
+ end
679
+ )}' should be before 'supports(...)'`,
680
+ locConverter,
681
+ start,
682
+ end
683
+ );
684
+ importData = undefined;
685
+ scope = CSS_MODE_TOP_LEVEL;
686
+ return end;
687
+ }
688
+
622
689
  const semicolonPos = end;
623
690
  end = walkCssTokens.eatWhiteLine(input, end + 1);
624
- const { line: sl, column: sc } = locConverter.get(importData.start);
691
+ const { line: sl, column: sc } = locConverter.get(start);
625
692
  const { line: el, column: ec } = locConverter.get(end);
626
- const pos = walkCssTokens.eatWhitespaceAndComments(
627
- input,
628
- importData.end
629
- );
693
+ const lastEnd =
694
+ importData.supportsEnd ||
695
+ importData.layerEnd ||
696
+ importData.urlEnd ||
697
+ start;
698
+ const pos = walkCssTokens.eatWhitespaceAndComments(input, lastEnd);
630
699
  // Prevent to consider comments as a part of media query
631
700
  if (pos !== semicolonPos - 1) {
632
- importData.media = input
633
- .slice(importData.end, semicolonPos - 1)
634
- .trim();
701
+ importData.media = input.slice(lastEnd, semicolonPos - 1).trim();
635
702
  }
636
- const dep = new CssImportDependency(
637
- importData.url.trim(),
638
- [importData.start, end],
639
- importData.layer,
640
- importData.supports,
641
- importData.media && importData.media.length > 0
642
- ? importData.media
643
- : undefined
644
- );
645
- dep.setLoc(sl, sc, el, ec);
646
- module.addDependency(dep);
703
+
704
+ const url = importData.url.trim();
705
+
706
+ if (url.length === 0) {
707
+ const dep = new ConstDependency("", [start, end]);
708
+ module.addPresentationalDependency(dep);
709
+ dep.setLoc(sl, sc, el, ec);
710
+ } else {
711
+ const dep = new CssImportDependency(
712
+ url,
713
+ [start, end],
714
+ importData.layer,
715
+ importData.supports,
716
+ importData.media && importData.media.length > 0
717
+ ? importData.media
718
+ : undefined
719
+ );
720
+ dep.setLoc(sl, sc, el, ec);
721
+ module.addDependency(dep);
722
+ }
723
+
647
724
  importData = undefined;
648
725
  scope = CSS_MODE_TOP_LEVEL;
726
+
727
+ break;
728
+ }
729
+ case CSS_MODE_AT_IMPORT_INVALID:
730
+ case CSS_MODE_AT_NAMESPACE_INVALID: {
731
+ scope = CSS_MODE_TOP_LEVEL;
732
+
649
733
  break;
650
734
  }
651
735
  case CSS_MODE_IN_BLOCK: {
@@ -718,10 +802,11 @@ class CssParser extends Parser {
718
802
  }
719
803
  break;
720
804
  }
721
- case CSS_MODE_AT_IMPORT_EXPECT_LAYER_OR_SUPPORTS_OR_MEDIA: {
805
+ case CSS_MODE_IN_AT_IMPORT: {
722
806
  if (input.slice(start, end).toLowerCase() === "layer") {
723
807
  importData.layer = "";
724
- importData.end = end;
808
+ importData.layerStart = start;
809
+ importData.layerEnd = end;
725
810
  }
726
811
  break;
727
812
  }
@@ -756,6 +841,13 @@ class CssParser extends Parser {
756
841
 
757
842
  balanced.push([name, start, end]);
758
843
 
844
+ if (
845
+ scope === CSS_MODE_IN_AT_IMPORT &&
846
+ name.toLowerCase() === "supports"
847
+ ) {
848
+ importData.inSupports = true;
849
+ }
850
+
759
851
  if (isLocalMode()) {
760
852
  name = name.toLowerCase();
761
853
 
@@ -810,20 +902,23 @@ class CssParser extends Parser {
810
902
  }
811
903
 
812
904
  switch (scope) {
813
- case CSS_MODE_AT_IMPORT_EXPECT_URL: {
814
- if (last && last[0] === "url") {
815
- importData.end = end;
816
- scope = CSS_MODE_AT_IMPORT_EXPECT_LAYER_OR_SUPPORTS_OR_MEDIA;
817
- }
818
- break;
819
- }
820
- case CSS_MODE_AT_IMPORT_EXPECT_LAYER_OR_SUPPORTS_OR_MEDIA: {
821
- if (last && last[0].toLowerCase() === "layer") {
905
+ case CSS_MODE_IN_AT_IMPORT: {
906
+ if (last && last[0] === "url" && !importData.inSupports) {
907
+ importData.urlStart = last[1];
908
+ importData.urlEnd = end;
909
+ } else if (
910
+ last &&
911
+ last[0].toLowerCase() === "layer" &&
912
+ !importData.inSupports
913
+ ) {
822
914
  importData.layer = input.slice(last[2], end - 1).trim();
823
- importData.end = end;
915
+ importData.layerStart = last[1];
916
+ importData.layerEnd = end;
824
917
  } else if (last && last[0].toLowerCase() === "supports") {
825
918
  importData.supports = input.slice(last[2], end - 1).trim();
826
- importData.end = end;
919
+ importData.supportsStart = last[1];
920
+ importData.supportsEnd = end;
921
+ importData.inSupports = false;
827
922
  }
828
923
  break;
829
924
  }
@@ -17,6 +17,7 @@ const createSchemaValidation = require("../util/create-schema-validation");
17
17
  const { dirname, mkdirpSync } = require("../util/fs");
18
18
 
19
19
  /** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
20
+ /** @typedef {import("../Compiler")} Compiler */
20
21
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
21
22
 
22
23
  const validate = createSchemaValidation(
@@ -72,6 +73,11 @@ class Profiler {
72
73
  ]);
73
74
  }
74
75
 
76
+ /**
77
+ * @param {string} method method name
78
+ * @param {object} [params] params
79
+ * @returns {Promise<TODO>} Promise for the result
80
+ */
75
81
  sendCommand(method, params) {
76
82
  if (this.hasSession()) {
77
83
  return new Promise((res, rej) => {
@@ -203,6 +209,11 @@ class ProfilingPlugin {
203
209
  this.outputPath = options.outputPath || "events.json";
204
210
  }
205
211
 
212
+ /**
213
+ * Apply the plugin
214
+ * @param {Compiler} compiler the compiler instance
215
+ * @returns {void}
216
+ */
206
217
  apply(compiler) {
207
218
  const tracer = createTrace(
208
219
  compiler.intermediateFileSystem,
@@ -12,6 +12,7 @@ const NullDependency = require("./NullDependency");
12
12
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13
13
  /** @typedef {import("../Dependency")} Dependency */
14
14
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
15
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
15
16
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
16
17
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
17
18
 
@@ -19,7 +20,7 @@ const NullDependency = require("./NullDependency");
19
20
  const DEFINITIONS = {
20
21
  f: {
21
22
  definition: "var __WEBPACK_AMD_DEFINE_RESULT__;",
22
- content: `!(__WEBPACK_AMD_DEFINE_RESULT__ = (#).call(exports, __webpack_require__, exports, module),
23
+ content: `!(__WEBPACK_AMD_DEFINE_RESULT__ = (#).call(exports, ${RuntimeGlobals.require}, exports, module),
23
24
  __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`,
24
25
  requests: [
25
26
  RuntimeGlobals.require,
@@ -37,7 +38,7 @@ const DEFINITIONS = {
37
38
  "var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;",
38
39
  content: `!(__WEBPACK_AMD_DEFINE_FACTORY__ = (#),
39
40
  __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
40
- (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) :
41
+ (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, ${RuntimeGlobals.require}, exports, module)) :
41
42
  __WEBPACK_AMD_DEFINE_FACTORY__),
42
43
  __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`,
43
44
  requests: [
@@ -69,8 +70,7 @@ const DEFINITIONS = {
69
70
  },
70
71
  lf: {
71
72
  definition: "var XXX, XXXmodule;",
72
- content:
73
- "!(XXXmodule = { id: YYY, exports: {}, loaded: false }, XXX = (#).call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule), XXXmodule.loaded = true, XXX === undefined && (XXX = XXXmodule.exports))",
73
+ content: `!(XXXmodule = { id: YYY, exports: {}, loaded: false }, XXX = (#).call(XXXmodule.exports, ${RuntimeGlobals.require}, XXXmodule.exports, XXXmodule), XXXmodule.loaded = true, XXX === undefined && (XXX = XXXmodule.exports))`,
74
74
  requests: [RuntimeGlobals.require, RuntimeGlobals.module]
75
75
  },
76
76
  lo: {
@@ -80,8 +80,7 @@ const DEFINITIONS = {
80
80
  },
81
81
  lof: {
82
82
  definition: "var XXX, XXXfactory, XXXmodule;",
83
- content:
84
- "!(XXXfactory = (#), (typeof XXXfactory === 'function' ? ((XXXmodule = { id: YYY, exports: {}, loaded: false }), (XXX = XXXfactory.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule)), (XXXmodule.loaded = true), XXX === undefined && (XXX = XXXmodule.exports)) : XXX = XXXfactory))",
83
+ content: `!(XXXfactory = (#), (typeof XXXfactory === 'function' ? ((XXXmodule = { id: YYY, exports: {}, loaded: false }), (XXX = XXXfactory.call(XXXmodule.exports, ${RuntimeGlobals.require}, XXXmodule.exports, XXXmodule)), (XXXmodule.loaded = true), XXX === undefined && (XXX = XXXmodule.exports)) : XXX = XXXfactory))`,
85
84
  requests: [RuntimeGlobals.require, RuntimeGlobals.module]
86
85
  },
87
86
  laf: {
@@ -107,6 +106,13 @@ const DEFINITIONS = {
107
106
  };
108
107
 
109
108
  class AMDDefineDependency extends NullDependency {
109
+ /**
110
+ * @param {Range} range range
111
+ * @param {Range} arrayRange array range
112
+ * @param {Range} functionRange function range
113
+ * @param {Range} objectRange object range
114
+ * @param {boolean} namedModule true, when define is called with a name
115
+ */
110
116
  constructor(range, arrayRange, functionRange, objectRange, namedModule) {
111
117
  super();
112
118
  this.range = range;
@@ -16,6 +16,8 @@ const DynamicExports = require("./DynamicExports");
16
16
  const LocalModuleDependency = require("./LocalModuleDependency");
17
17
  const { addLocalModule, getLocalModule } = require("./LocalModulesHelpers");
18
18
 
19
+ /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
20
+
19
21
  const isBoundFunctionExpression = expr => {
20
22
  if (expr.type !== "CallExpression") return false;
21
23
  if (expr.callee.type !== "MemberExpression") return false;
@@ -43,6 +45,10 @@ class AMDDefineDependencyParserPlugin {
43
45
  this.options = options;
44
46
  }
45
47
 
48
+ /**
49
+ * @param {JavascriptParser} parser the parser
50
+ * @returns {void}
51
+ */
46
52
  apply(parser) {
47
53
  parser.hooks.call
48
54
  .for("define")
@@ -73,7 +79,7 @@ class AMDDefineDependencyParserPlugin {
73
79
  let localModule;
74
80
  if (request === "require") {
75
81
  identifiers[idx] = request;
76
- dep = "__webpack_require__";
82
+ dep = RuntimeGlobals.require;
77
83
  } else if (["exports", "module"].includes(request)) {
78
84
  identifiers[idx] = request;
79
85
  dep = request;
@@ -109,7 +115,7 @@ class AMDDefineDependencyParserPlugin {
109
115
  } else if (param.isString()) {
110
116
  let dep, localModule;
111
117
  if (param.string === "require") {
112
- dep = new ConstDependency("__webpack_require__", param.range, [
118
+ dep = new ConstDependency(RuntimeGlobals.require, param.range, [
113
119
  RuntimeGlobals.require
114
120
  ]);
115
121
  } else if (param.string === "exports") {
@@ -32,8 +32,10 @@ const ConstDependency = require("./ConstDependency");
32
32
  const LocalModuleDependency = require("./LocalModuleDependency");
33
33
  const UnsupportedDependency = require("./UnsupportedDependency");
34
34
 
35
+ /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
35
36
  /** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
36
37
  /** @typedef {import("../Compiler")} Compiler */
38
+ /** @typedef {import("../javascript/JavascriptParser")} Parser */
37
39
 
38
40
  const PLUGIN_NAME = "AMDPlugin";
39
41
 
@@ -125,6 +127,11 @@ class AMDPlugin {
125
127
  );
126
128
  });
127
129
 
130
+ /**
131
+ * @param {Parser} parser parser parser
132
+ * @param {JavascriptParserOptions} parserOptions parserOptions
133
+ * @returns {void}
134
+ */
128
135
  const handler = (parser, parserOptions) => {
129
136
  if (parserOptions.amd !== undefined && !parserOptions.amd) return;
130
137
 
@@ -12,10 +12,15 @@ const NullDependency = require("./NullDependency");
12
12
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13
13
  /** @typedef {import("../Dependency")} Dependency */
14
14
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
15
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
15
16
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
16
17
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
17
18
 
18
19
  class AMDRequireArrayDependency extends NullDependency {
20
+ /**
21
+ * @param {TODO} depsArray deps array
22
+ * @param {Range} range range
23
+ */
19
24
  constructor(depsArray, range) {
20
25
  super();
21
26
 
@@ -8,10 +8,16 @@
8
8
  const makeSerializable = require("../util/makeSerializable");
9
9
  const ContextDependency = require("./ContextDependency");
10
10
 
11
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
11
12
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
12
13
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
13
14
 
14
15
  class AMDRequireContextDependency extends ContextDependency {
16
+ /**
17
+ * @param {TODO} options options
18
+ * @param {Range} range range
19
+ * @param {Range} valueRange value range
20
+ */
15
21
  constructor(options, range, valueRange) {
16
22
  super(options);
17
23
 
@@ -8,7 +8,13 @@
8
8
  const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
10
 
11
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
12
+
11
13
  class AMDRequireDependenciesBlock extends AsyncDependenciesBlock {
14
+ /**
15
+ * @param {DependencyLocation} loc location info
16
+ * @param {string=} request request
17
+ */
12
18
  constructor(loc, request) {
13
19
  super(null, loc, request);
14
20
  }
@@ -19,6 +19,8 @@ const { getLocalModule } = require("./LocalModulesHelpers");
19
19
  const UnsupportedDependency = require("./UnsupportedDependency");
20
20
  const getFunctionExpression = require("./getFunctionExpression");
21
21
 
22
+ /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
23
+
22
24
  class AMDRequireDependenciesBlockParserPlugin {
23
25
  constructor(options) {
24
26
  this.options = options;
@@ -50,6 +52,10 @@ class AMDRequireDependenciesBlockParserPlugin {
50
52
  return bindThis;
51
53
  }
52
54
 
55
+ /**
56
+ * @param {JavascriptParser} parser the parser
57
+ * @returns {void}
58
+ */
53
59
  apply(parser) {
54
60
  parser.hooks.call
55
61
  .for("require")
@@ -73,7 +79,7 @@ class AMDRequireDependenciesBlockParserPlugin {
73
79
  for (const request of param.array) {
74
80
  let dep, localModule;
75
81
  if (request === "require") {
76
- dep = "__webpack_require__";
82
+ dep = RuntimeGlobals.require;
77
83
  } else if (["exports", "module"].includes(request)) {
78
84
  dep = request;
79
85
  } else if ((localModule = getLocalModule(parser.state, request))) {
@@ -108,7 +114,7 @@ class AMDRequireDependenciesBlockParserPlugin {
108
114
  } else if (param.isString()) {
109
115
  let dep, localModule;
110
116
  if (param.string === "require") {
111
- dep = new ConstDependency("__webpack_require__", param.string, [
117
+ dep = new ConstDependency(RuntimeGlobals.require, param.string, [
112
118
  RuntimeGlobals.require
113
119
  ]);
114
120
  } else if (param.string === "module") {
@@ -13,10 +13,17 @@ const NullDependency = require("./NullDependency");
13
13
  /** @typedef {import("../AsyncDependenciesBlock")} AsyncDependenciesBlock */
14
14
  /** @typedef {import("../Dependency")} Dependency */
15
15
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
16
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
16
17
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
17
18
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
18
19
 
19
20
  class AMDRequireDependency extends NullDependency {
21
+ /**
22
+ * @param {Range} outerRange outer range
23
+ * @param {Range} arrayRange array range
24
+ * @param {Range} functionRange function range
25
+ * @param {Range} errorCallbackRange error callback range
26
+ */
20
27
  constructor(outerRange, arrayRange, functionRange, errorCallbackRange) {
21
28
  super();
22
29
 
@@ -111,7 +118,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
111
118
  // has function range but no array range
112
119
  if (dep.functionRange && !dep.arrayRange) {
113
120
  const startBlock = `${promise}.then((`;
114
- const endBlock = `).bind(exports, __webpack_require__, exports, module))['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
121
+ const endBlock = `).bind(exports, ${RuntimeGlobals.require}, exports, module))['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
115
122
  runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
116
123
 
117
124
  source.replace(dep.outerRange[0], dep.functionRange[0] - 1, startBlock);
@@ -9,7 +9,13 @@ const makeSerializable = require("../util/makeSerializable");
9
9
  const ModuleDependency = require("./ModuleDependency");
10
10
  const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
11
11
 
12
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
13
+
12
14
  class AMDRequireItemDependency extends ModuleDependency {
15
+ /**
16
+ * @param {string} request the request string
17
+ * @param {Range} range location in source code
18
+ */
13
19
  constructor(request, range) {
14
20
  super(request);
15
21
 
@@ -18,11 +18,17 @@ const NullDependency = require("./NullDependency");
18
18
  /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
19
19
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
20
20
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
21
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
21
22
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
22
23
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
23
24
  /** @typedef {import("../util/Hash")} Hash */
24
25
 
25
26
  class CachedConstDependency extends NullDependency {
27
+ /**
28
+ * @param {string} expression expression
29
+ * @param {Range} range range
30
+ * @param {string} identifier identifier
31
+ */
26
32
  constructor(expression, range, identifier) {
27
33
  super();
28
34