webpack 5.105.4 → 5.106.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.
Files changed (123) hide show
  1. package/README.md +3 -6
  2. package/lib/BannerPlugin.js +13 -13
  3. package/lib/Chunk.js +25 -0
  4. package/lib/ChunkGraph.js +8 -4
  5. package/lib/CleanPlugin.js +23 -20
  6. package/lib/CompatibilityPlugin.js +1 -1
  7. package/lib/Compilation.js +34 -11
  8. package/lib/Compiler.js +59 -1
  9. package/lib/CssModule.js +17 -2
  10. package/lib/Dependency.js +1 -1
  11. package/lib/DllPlugin.js +17 -17
  12. package/lib/DllReferencePlugin.js +20 -18
  13. package/lib/DotenvPlugin.js +29 -27
  14. package/lib/ExternalModule.js +39 -6
  15. package/lib/FileSystemInfo.js +3 -1
  16. package/lib/IgnorePlugin.js +12 -11
  17. package/lib/LoaderOptionsPlugin.js +17 -15
  18. package/lib/ManifestPlugin.js +27 -25
  19. package/lib/Module.js +69 -4
  20. package/lib/ModuleGraph.js +3 -0
  21. package/lib/ModuleParseError.js +1 -1
  22. package/lib/ModuleTypeConstants.js +1 -1
  23. package/lib/NormalModule.js +7 -3
  24. package/lib/NormalModuleFactory.js +20 -1
  25. package/lib/ProgressPlugin.js +39 -29
  26. package/lib/RuntimeGlobals.js +6 -0
  27. package/lib/RuntimeTemplate.js +1 -1
  28. package/lib/SourceMapDevToolPlugin.js +13 -11
  29. package/lib/TemplatedPathPlugin.js +4 -3
  30. package/lib/WatchIgnorePlugin.js +15 -13
  31. package/lib/WebpackOptionsApply.js +4 -4
  32. package/lib/asset/AssetModulesPlugin.js +50 -29
  33. package/lib/cli.js +3 -1
  34. package/lib/config/defaults.js +27 -13
  35. package/lib/config/normalization.js +3 -2
  36. package/lib/container/ContainerPlugin.js +46 -42
  37. package/lib/container/ContainerReferencePlugin.js +42 -26
  38. package/lib/container/FallbackModule.js +1 -1
  39. package/lib/container/ModuleFederationPlugin.js +17 -13
  40. package/lib/css/CssGenerator.js +306 -192
  41. package/lib/css/CssInjectStyleRuntimeModule.js +179 -0
  42. package/lib/css/CssLoadingRuntimeModule.js +1 -4
  43. package/lib/css/CssModulesPlugin.js +197 -98
  44. package/lib/css/CssParser.js +231 -134
  45. package/lib/css/walkCssTokens.js +115 -12
  46. package/lib/debug/ProfilingPlugin.js +16 -13
  47. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +20 -15
  48. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -3
  49. package/lib/dependencies/CommonJsExportRequireDependency.js +4 -2
  50. package/lib/dependencies/CommonJsExportsDependency.js +1 -1
  51. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
  52. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
  53. package/lib/dependencies/CommonJsImportsParserPlugin.js +63 -2
  54. package/lib/dependencies/CommonJsRequireContextDependency.js +21 -0
  55. package/lib/dependencies/CommonJsRequireDependency.js +42 -1
  56. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -1
  57. package/lib/dependencies/ContextElementDependency.js +1 -1
  58. package/lib/dependencies/CssIcssExportDependency.js +210 -87
  59. package/lib/dependencies/CssIcssImportDependency.js +13 -70
  60. package/lib/dependencies/CssIcssSymbolDependency.js +19 -30
  61. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +13 -2
  62. package/lib/dependencies/HarmonyExportExpressionDependency.js +28 -2
  63. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -3
  64. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  65. package/lib/dependencies/HarmonyImportDependency.js +21 -8
  66. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +4 -1
  67. package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
  68. package/lib/dependencies/HarmonyImportSpecifierDependency.js +13 -2
  69. package/lib/dependencies/ImportContextDependency.js +1 -1
  70. package/lib/dependencies/ImportDependency.js +16 -2
  71. package/lib/dependencies/ImportMetaPlugin.js +39 -29
  72. package/lib/dependencies/ImportParserPlugin.js +4 -5
  73. package/lib/dependencies/ImportPhase.js +65 -22
  74. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
  75. package/lib/esm/ModuleChunkFormatPlugin.js +1 -4
  76. package/lib/ids/HashedModuleIdsPlugin.js +21 -23
  77. package/lib/ids/OccurrenceChunkIdsPlugin.js +15 -11
  78. package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -11
  79. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -4
  80. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -4
  81. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -2
  82. package/lib/javascript/JavascriptModulesPlugin.js +38 -12
  83. package/lib/javascript/JavascriptParser.js +5 -3
  84. package/lib/json/JsonModulesPlugin.js +28 -21
  85. package/lib/library/AssignLibraryPlugin.js +1 -1
  86. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  87. package/lib/library/ModuleLibraryPlugin.js +35 -13
  88. package/lib/library/SystemLibraryPlugin.js +1 -1
  89. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +22 -0
  90. package/lib/optimize/AggressiveSplittingPlugin.js +18 -31
  91. package/lib/optimize/ConcatenatedModule.js +4 -3
  92. package/lib/optimize/InnerGraphPlugin.js +11 -5
  93. package/lib/optimize/LimitChunkCountPlugin.js +22 -18
  94. package/lib/optimize/MergeDuplicateChunksPlugin.js +15 -12
  95. package/lib/optimize/MinChunkSizePlugin.js +20 -16
  96. package/lib/optimize/RemoveEmptyChunksPlugin.js +0 -1
  97. package/lib/rules/RuleSetCompiler.js +1 -0
  98. package/lib/schemes/HttpUriPlugin.js +20 -11
  99. package/lib/schemes/VirtualUrlPlugin.js +77 -30
  100. package/lib/serialization/FileMiddleware.js +7 -7
  101. package/lib/sharing/ConsumeSharedPlugin.js +32 -25
  102. package/lib/sharing/ProvideSharedPlugin.js +29 -25
  103. package/lib/util/{propertyName.js → property.js} +26 -1
  104. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +148 -0
  105. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +54 -0
  106. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +105 -0
  107. package/lib/wasm-async/AsyncWebAssemblyParser.js +30 -6
  108. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +26 -2
  109. package/lib/web/FetchCompileAsyncWasmPlugin.js +23 -0
  110. package/lib/web/JsonpTemplatePlugin.js +1 -0
  111. package/lib/webpack.js +34 -4
  112. package/package.json +18 -16
  113. package/schemas/WebpackOptions.check.js +1 -1
  114. package/schemas/WebpackOptions.json +82 -22
  115. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  116. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  117. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  118. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +1 -1
  119. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +1 -1
  120. package/schemas/plugins/schemes/VirtualUrlPlugin.json +8 -0
  121. package/types.d.ts +511 -114
  122. package/lib/util/create-schema-validation.js +0 -41
  123. package/lib/util/propertyAccess.js +0 -30
@@ -7,8 +7,8 @@
7
7
 
8
8
  /**
9
9
  * @typedef {object} CssTokenCallbacks
10
- * @property {((input: string, start: number, end: number, innerStart: number, innerEnd: number) => number)=} url
11
10
  * @property {((input: string, start: number, end: number) => number)=} comment
11
+ * @property {((input: string, start: number, end: number) => number)=} whitespace
12
12
  * @property {((input: string, start: number, end: number) => number)=} string
13
13
  * @property {((input: string, start: number, end: number) => number)=} leftCurlyBracket
14
14
  * @property {((input: string, start: number, end: number) => number)=} rightCurlyBracket
@@ -17,13 +17,21 @@
17
17
  * @property {((input: string, start: number, end: number) => number)=} leftSquareBracket
18
18
  * @property {((input: string, start: number, end: number) => number)=} rightSquareBracket
19
19
  * @property {((input: string, start: number, end: number) => number)=} function
20
+ * @property {((input: string, start: number, end: number, innerStart: number, innerEnd: number) => number)=} url
20
21
  * @property {((input: string, start: number, end: number) => number)=} colon
21
22
  * @property {((input: string, start: number, end: number) => number)=} atKeyword
22
23
  * @property {((input: string, start: number, end: number) => number)=} delim
23
24
  * @property {((input: string, start: number, end: number) => number)=} identifier
25
+ * @property {((input: string, start: number, end: number) => number)=} percentage
26
+ * @property {((input: string, start: number, end: number) => number)=} number
27
+ * @property {((input: string, start: number, end: number) => number)=} dimension
24
28
  * @property {((input: string, start: number, end: number, isId: boolean) => number)=} hash
25
29
  * @property {((input: string, start: number, end: number) => number)=} semicolon
26
30
  * @property {((input: string, start: number, end: number) => number)=} comma
31
+ * @property {((input: string, start: number, end: number) => number)=} cdo
32
+ * @property {((input: string, start: number, end: number) => number)=} cdc
33
+ * @property {((input: string, start: number, end: number) => number)=} badStringToken
34
+ * @property {((input: string, start: number, end: number) => number)=} badUrlToken
27
35
  * @property {(() => boolean)=} needTerminate
28
36
  */
29
37
 
@@ -81,13 +89,19 @@ const CC_LESS_THAN_SIGN = "<".charCodeAt(0);
81
89
  const CC_GREATER_THAN_SIGN = ">".charCodeAt(0);
82
90
 
83
91
  /** @type {CharHandler} */
84
- const consumeSpace = (input, pos, _callbacks) => {
92
+ const consumeSpace = (input, pos, callbacks) => {
93
+ const start = pos - 1;
94
+
85
95
  // Consume as much whitespace as possible.
86
96
  while (_isWhiteSpace(input.charCodeAt(pos))) {
87
97
  pos++;
88
98
  }
89
99
 
90
100
  // Return a <whitespace-token>.
101
+ if (callbacks.whitespace !== undefined) {
102
+ return callbacks.whitespace(input, start, pos);
103
+ }
104
+
91
105
  return pos;
92
106
  };
93
107
 
@@ -143,9 +157,14 @@ const isIdentStartCodePoint = (cc) =>
143
157
  cc >= 0x80;
144
158
 
145
159
  /** @type {CharHandler} */
146
- const consumeDelimToken = (input, pos, _callbacks) =>
160
+ const consumeDelimToken = (input, pos, callbacks) => {
147
161
  // Return a <delim-token> with its value set to the current input code point.
148
- pos;
162
+ if (callbacks.delim) {
163
+ pos = callbacks.delim(input, pos - 1, pos);
164
+ }
165
+
166
+ return pos;
167
+ };
149
168
 
150
169
  /** @type {CharHandler} */
151
170
  const consumeComments = (input, pos, callbacks) => {
@@ -286,6 +305,11 @@ const consumeAStringToken = (input, pos, callbacks) => {
286
305
  // Reconsume the current input code point, create a <bad-string-token>, and return it.
287
306
  else if (_isNewline(cc)) {
288
307
  pos--;
308
+
309
+ if (callbacks.badStringToken !== undefined) {
310
+ return callbacks.badStringToken(input, start, pos);
311
+ }
312
+
289
313
  // bad string
290
314
  return pos;
291
315
  }
@@ -445,7 +469,7 @@ const _ifThreeCodePointsWouldStartANumber = (input, pos, f, s, t) => {
445
469
 
446
470
  const first = f || input.charCodeAt(pos - 1);
447
471
  const second = s || input.charCodeAt(pos);
448
- const third = t || input.charCodeAt(pos);
472
+ const third = t || input.charCodeAt(pos + 1);
449
473
 
450
474
  // Look at the first code point:
451
475
 
@@ -523,6 +547,10 @@ const consumeNumberSign = (input, pos, callbacks) => {
523
547
  return pos;
524
548
  }
525
549
 
550
+ if (callbacks.delim !== undefined) {
551
+ return callbacks.delim(input, start, pos);
552
+ }
553
+
526
554
  // Otherwise, return a <delim-token> with its value set to the current input code point.
527
555
  return pos;
528
556
  };
@@ -539,6 +567,10 @@ const consumeHyphenMinus = (input, pos, callbacks) => {
539
567
  input.charCodeAt(pos) === CC_HYPHEN_MINUS &&
540
568
  input.charCodeAt(pos + 1) === CC_GREATER_THAN_SIGN
541
569
  ) {
570
+ if (callbacks.cdc !== undefined) {
571
+ return callbacks.cdc(input, pos - 1, pos + 2);
572
+ }
573
+
542
574
  return pos + 2;
543
575
  }
544
576
  // Otherwise, if the input stream starts with an ident sequence, reconsume the current input code point, consume an ident-like token, and return it.
@@ -547,6 +579,10 @@ const consumeHyphenMinus = (input, pos, callbacks) => {
547
579
  return consumeAnIdentLikeToken(input, pos, callbacks);
548
580
  }
549
581
 
582
+ if (callbacks.delim !== undefined) {
583
+ return callbacks.delim(input, pos - 1, pos);
584
+ }
585
+
550
586
  // Otherwise, return a <delim-token> with its value set to the current input code point.
551
587
  return pos;
552
588
  };
@@ -571,6 +607,8 @@ const consumeFullStop = (input, pos, callbacks) => {
571
607
 
572
608
  /** @type {CharHandler} */
573
609
  const consumePlusSign = (input, pos, callbacks) => {
610
+ const start = pos - 1;
611
+
574
612
  // If the input stream starts with a number, reconsume the current input code point, consume a numeric token, and return it.
575
613
  if (_ifThreeCodePointsWouldStartANumber(input, pos)) {
576
614
  pos--;
@@ -578,6 +616,10 @@ const consumePlusSign = (input, pos, callbacks) => {
578
616
  }
579
617
 
580
618
  // Otherwise, return a <delim-token> with its value set to the current input code point.
619
+ if (callbacks.delim !== undefined) {
620
+ return callbacks.delim(input, start, pos);
621
+ }
622
+
581
623
  return pos;
582
624
  };
583
625
 
@@ -657,6 +699,8 @@ const consumeANumericToken = (input, pos, callbacks) => {
657
699
  // This section describes how to consume a numeric token from a stream of code points.
658
700
  // It returns either a <number-token>, <percentage-token>, or <dimension-token>.
659
701
 
702
+ const start = pos;
703
+
660
704
  // Consume a number and let number be the result.
661
705
  pos = _consumeANumber(input, pos, callbacks);
662
706
 
@@ -679,15 +723,29 @@ const consumeANumericToken = (input, pos, callbacks) => {
679
723
  third
680
724
  )
681
725
  ) {
682
- return _consumeAnIdentSequence(input, pos, callbacks);
726
+ pos = _consumeAnIdentSequence(input, pos, callbacks);
727
+
728
+ if (callbacks.dimension !== undefined) {
729
+ return callbacks.dimension(input, start, pos);
730
+ }
731
+
732
+ return pos;
683
733
  }
684
734
  // Otherwise, if the next input code point is U+0025 PERCENTAGE SIGN (%), consume it.
685
735
  // Create a <percentage-token> with the same value as number, and return it.
686
736
  else if (first === CC_PERCENTAGE) {
737
+ if (callbacks.percentage !== undefined) {
738
+ return callbacks.percentage(input, start, pos + 1);
739
+ }
740
+
687
741
  return pos + 1;
688
742
  }
689
743
 
690
744
  // Otherwise, create a <number-token> with the same value and type flag as number, and return it.
745
+ if (callbacks.number !== undefined) {
746
+ return callbacks.number(input, start, pos);
747
+ }
748
+
691
749
  return pos;
692
750
  };
693
751
 
@@ -697,6 +755,7 @@ const consumeColon = (input, pos, callbacks) => {
697
755
  if (callbacks.colon !== undefined) {
698
756
  return callbacks.colon(input, pos - 1, pos);
699
757
  }
758
+
700
759
  return pos;
701
760
  };
702
761
 
@@ -706,6 +765,7 @@ const consumeLeftParenthesis = (input, pos, callbacks) => {
706
765
  if (callbacks.leftParenthesis !== undefined) {
707
766
  return callbacks.leftParenthesis(input, pos - 1, pos);
708
767
  }
768
+
709
769
  return pos;
710
770
  };
711
771
 
@@ -715,6 +775,7 @@ const consumeRightParenthesis = (input, pos, callbacks) => {
715
775
  if (callbacks.rightParenthesis !== undefined) {
716
776
  return callbacks.rightParenthesis(input, pos - 1, pos);
717
777
  }
778
+
718
779
  return pos;
719
780
  };
720
781
 
@@ -724,6 +785,7 @@ const consumeLeftSquareBracket = (input, pos, callbacks) => {
724
785
  if (callbacks.leftSquareBracket !== undefined) {
725
786
  return callbacks.leftSquareBracket(input, pos - 1, pos);
726
787
  }
788
+
727
789
  return pos;
728
790
  };
729
791
 
@@ -733,6 +795,7 @@ const consumeRightSquareBracket = (input, pos, callbacks) => {
733
795
  if (callbacks.rightSquareBracket !== undefined) {
734
796
  return callbacks.rightSquareBracket(input, pos - 1, pos);
735
797
  }
798
+
736
799
  return pos;
737
800
  };
738
801
 
@@ -742,6 +805,7 @@ const consumeLeftCurlyBracket = (input, pos, callbacks) => {
742
805
  if (callbacks.leftCurlyBracket !== undefined) {
743
806
  return callbacks.leftCurlyBracket(input, pos - 1, pos);
744
807
  }
808
+
745
809
  return pos;
746
810
  };
747
811
 
@@ -751,6 +815,7 @@ const consumeRightCurlyBracket = (input, pos, callbacks) => {
751
815
  if (callbacks.rightCurlyBracket !== undefined) {
752
816
  return callbacks.rightCurlyBracket(input, pos - 1, pos);
753
817
  }
818
+
754
819
  return pos;
755
820
  };
756
821
 
@@ -760,6 +825,7 @@ const consumeSemicolon = (input, pos, callbacks) => {
760
825
  if (callbacks.semicolon !== undefined) {
761
826
  return callbacks.semicolon(input, pos - 1, pos);
762
827
  }
828
+
763
829
  return pos;
764
830
  };
765
831
 
@@ -769,6 +835,7 @@ const consumeComma = (input, pos, callbacks) => {
769
835
  if (callbacks.comma !== undefined) {
770
836
  return callbacks.comma(input, pos - 1, pos);
771
837
  }
838
+
772
839
  return pos;
773
840
  };
774
841
 
@@ -935,7 +1002,13 @@ const consumeAUrlToken = (input, pos, fnStart, callbacks) => {
935
1002
  }
936
1003
 
937
1004
  // Don't handle bad urls
938
- return consumeTheRemnantsOfABadUrl(input, pos);
1005
+ pos = consumeTheRemnantsOfABadUrl(input, pos);
1006
+
1007
+ if (callbacks.badUrlToken !== undefined) {
1008
+ return callbacks.badUrlToken(input, fnStart, pos);
1009
+ }
1010
+
1011
+ return pos;
939
1012
  }
940
1013
  // U+0022 QUOTATION MARK (")
941
1014
  // U+0027 APOSTROPHE (')
@@ -949,7 +1022,13 @@ const consumeAUrlToken = (input, pos, fnStart, callbacks) => {
949
1022
  _isNonPrintableCodePoint(cc)
950
1023
  ) {
951
1024
  // Don't handle bad urls
952
- return consumeTheRemnantsOfABadUrl(input, pos);
1025
+ pos = consumeTheRemnantsOfABadUrl(input, pos);
1026
+
1027
+ if (callbacks.badUrlToken !== undefined) {
1028
+ return callbacks.badUrlToken(input, fnStart, pos);
1029
+ }
1030
+
1031
+ return pos;
953
1032
  }
954
1033
  // // U+005C REVERSE SOLIDUS (\)
955
1034
  // // If the stream starts with a valid escape, consume an escaped code point and append the returned code point to the <url-token>’s value.
@@ -959,7 +1038,13 @@ const consumeAUrlToken = (input, pos, fnStart, callbacks) => {
959
1038
  pos = _consumeAnEscapedCodePoint(input, pos);
960
1039
  } else {
961
1040
  // Don't handle bad urls
962
- return consumeTheRemnantsOfABadUrl(input, pos);
1041
+ pos = consumeTheRemnantsOfABadUrl(input, pos);
1042
+
1043
+ if (callbacks.badUrlToken !== undefined) {
1044
+ return callbacks.badUrlToken(input, fnStart, pos);
1045
+ }
1046
+
1047
+ return pos;
963
1048
  }
964
1049
  }
965
1050
  // anything else
@@ -1033,12 +1118,20 @@ const consumeAnIdentLikeToken = (input, pos, callbacks) => {
1033
1118
  };
1034
1119
 
1035
1120
  /** @type {CharHandler} */
1036
- const consumeLessThan = (input, pos, _callbacks) => {
1121
+ const consumeLessThan = (input, pos, callbacks) => {
1037
1122
  // If the next 3 input code points are U+0021 EXCLAMATION MARK U+002D HYPHEN-MINUS U+002D HYPHEN-MINUS (!--), consume them and return a <CDO-token>.
1038
1123
  if (input.slice(pos, pos + 3) === "!--") {
1124
+ if (callbacks.cdo !== undefined) {
1125
+ return callbacks.cdo(input, pos - 1, pos + 3);
1126
+ }
1127
+
1039
1128
  return pos + 3;
1040
1129
  }
1041
1130
 
1131
+ if (callbacks.delim !== undefined) {
1132
+ return callbacks.delim(input, pos - 1, pos);
1133
+ }
1134
+
1042
1135
  // Otherwise, return a <delim-token> with its value set to the current input code point.
1043
1136
  return pos;
1044
1137
  };
@@ -1067,6 +1160,10 @@ const consumeCommercialAt = (input, pos, callbacks) => {
1067
1160
  }
1068
1161
 
1069
1162
  // Otherwise, return a <delim-token> with its value set to the current input code point.
1163
+ if (callbacks.delim !== undefined) {
1164
+ return callbacks.delim(input, start, pos);
1165
+ }
1166
+
1070
1167
  return pos;
1071
1168
  };
1072
1169
 
@@ -1079,6 +1176,10 @@ const consumeReverseSolidus = (input, pos, callbacks) => {
1079
1176
  }
1080
1177
 
1081
1178
  // Otherwise, this is a parse error. Return a <delim-token> with its value set to the current input code point.
1179
+ if (callbacks.delim !== undefined) {
1180
+ return callbacks.delim(input, pos - 1, pos);
1181
+ }
1182
+
1082
1183
  return pos;
1083
1184
  };
1084
1185
 
@@ -1281,12 +1382,14 @@ const consumeUntil = (input, pos, callbacks, additional, options = {}) => {
1281
1382
  };
1282
1383
  }
1283
1384
 
1385
+ const mergedCallbacks = { ...servicedCallbacks, ...callbacks };
1386
+
1284
1387
  while (pos < input.length) {
1285
1388
  // Consume comments.
1286
1389
  pos = consumeComments(
1287
1390
  input,
1288
1391
  pos,
1289
- needHandle ? { ...servicedCallbacks, ...callbacks } : servicedCallbacks
1392
+ needHandle ? mergedCallbacks : servicedCallbacks
1290
1393
  );
1291
1394
 
1292
1395
  const start = pos;
@@ -1296,7 +1399,7 @@ const consumeUntil = (input, pos, callbacks, additional, options = {}) => {
1296
1399
  pos = consumeAToken(
1297
1400
  input,
1298
1401
  pos,
1299
- needHandle ? { ...servicedCallbacks, ...callbacks } : servicedCallbacks
1402
+ needHandle ? mergedCallbacks : servicedCallbacks
1300
1403
  );
1301
1404
 
1302
1405
  if (needTerminate) {
@@ -11,7 +11,6 @@ const {
11
11
  JSON_MODULE_TYPE,
12
12
  WEBASSEMBLY_MODULES
13
13
  } = require("../ModuleTypeConstants");
14
- const createSchemaValidation = require("../util/create-schema-validation");
15
14
  const { dirname, mkdirpSync } = require("../util/fs");
16
15
 
17
16
  /** @typedef {import("inspector").Session} Session */
@@ -43,15 +42,6 @@ const { dirname, mkdirpSync } = require("../util/fs");
43
42
  * @typedef {import("tapable").HookInterceptor<T, R>} HookInterceptor
44
43
  */
45
44
 
46
- const validate = createSchemaValidation(
47
- require("../../schemas/plugins/debug/ProfilingPlugin.check"),
48
- () => require("../../schemas/plugins/debug/ProfilingPlugin.json"),
49
- {
50
- name: "Profiling Plugin",
51
- baseDataPath: "options"
52
- }
53
- );
54
-
55
45
  /** @typedef {{ Session: typeof import("inspector").Session }} Inspector */
56
46
 
57
47
  /** @type {Inspector | undefined} */
@@ -242,8 +232,8 @@ class ProfilingPlugin {
242
232
  * @param {ProfilingPluginOptions=} options options object
243
233
  */
244
234
  constructor(options = {}) {
245
- validate(options);
246
- this.outputPath = options.outputPath || "events.json";
235
+ /** @type {ProfilingPluginOptions} */
236
+ this.options = options;
247
237
  }
248
238
 
249
239
  /**
@@ -252,10 +242,23 @@ class ProfilingPlugin {
252
242
  * @returns {void}
253
243
  */
254
244
  apply(compiler) {
245
+ compiler.hooks.validate.tap(PLUGIN_NAME, () => {
246
+ compiler.validate(
247
+ () => require("../../schemas/plugins/debug/ProfilingPlugin.json"),
248
+ this.options,
249
+ {
250
+ name: "Profiling Plugin",
251
+ baseDataPath: "options"
252
+ },
253
+ (options) =>
254
+ require("../../schemas/plugins/debug/ProfilingPlugin.check")(options)
255
+ );
256
+ });
257
+
255
258
  const tracer = createTrace(
256
259
  /** @type {IntermediateFileSystem} */
257
260
  (compiler.intermediateFileSystem),
258
- this.outputPath
261
+ this.options.outputPath || "events.json"
259
262
  );
260
263
  tracer.profiler.startProfiling();
261
264
 
@@ -394,21 +394,25 @@ class AMDDefineDependencyParserPlugin {
394
394
  let inTry;
395
395
  if (fn && isUnboundFunctionExpression(fn)) {
396
396
  inTry = parser.scope.inTry;
397
- parser.inScope(/** @type {Identifier[]} */ (fnParams), () => {
398
- for (const [name, varInfo] of fnRenames) {
399
- parser.setVariable(name, varInfo);
400
- }
401
- parser.scope.inTry = /** @type {boolean} */ (inTry);
402
- if (fn.body.type === "BlockStatement") {
403
- parser.detectMode(fn.body.body);
404
- const prev = parser.prevStatement;
405
- parser.preWalkStatement(fn.body);
406
- parser.prevStatement = prev;
407
- parser.walkStatement(fn.body);
408
- } else {
409
- parser.walkExpression(fn.body);
397
+ parser.inFunctionScope(
398
+ true,
399
+ /** @type {Identifier[]} */ (fnParams),
400
+ () => {
401
+ for (const [name, varInfo] of fnRenames) {
402
+ parser.setVariable(name, varInfo);
403
+ }
404
+ parser.scope.inTry = /** @type {boolean} */ (inTry);
405
+ if (fn.body.type === "BlockStatement") {
406
+ parser.detectMode(fn.body.body);
407
+ const prev = parser.prevStatement;
408
+ parser.preWalkStatement(fn.body);
409
+ parser.prevStatement = prev;
410
+ parser.walkStatement(fn.body);
411
+ } else {
412
+ parser.walkExpression(fn.body);
413
+ }
410
414
  }
411
- });
415
+ );
412
416
  } else if (fn && isBoundFunctionExpression(fn)) {
413
417
  inTry = parser.scope.inTry;
414
418
 
@@ -416,7 +420,8 @@ class AMDDefineDependencyParserPlugin {
416
420
  /** @type {FunctionExpression} */
417
421
  (/** @type {MemberExpression} */ (fn.callee).object);
418
422
 
419
- parser.inScope(
423
+ parser.inFunctionScope(
424
+ true,
420
425
  /** @type {Identifier[]} */
421
426
  (object.params).filter(
422
427
  (i) => !["require", "module", "exports"].includes(i.name)
@@ -51,7 +51,8 @@ class AMDRequireDependenciesBlockParserPlugin {
51
51
  let bindThis = true;
52
52
  const fnData = getFunctionExpression(expression);
53
53
  if (fnData) {
54
- parser.inScope(
54
+ parser.inFunctionScope(
55
+ true,
55
56
  fnData.fn.params.filter(
56
57
  (i) =>
57
58
  !["require", "module", "exports"].includes(
@@ -305,7 +306,7 @@ class AMDRequireDependenciesBlockParserPlugin {
305
306
  }
306
307
 
307
308
  if (expr.arguments.length === 1) {
308
- parser.inScope([], () => {
309
+ parser.inFunctionScope(true, [], () => {
309
310
  result = this.processArray(
310
311
  parser,
311
312
  expr,
@@ -324,7 +325,7 @@ class AMDRequireDependenciesBlockParserPlugin {
324
325
 
325
326
  if (expr.arguments.length === 2 || expr.arguments.length === 3) {
326
327
  try {
327
- parser.inScope([], () => {
328
+ parser.inFunctionScope(true, [], () => {
328
329
  result = this.processArray(
329
330
  parser,
330
331
  expr,
@@ -10,7 +10,7 @@ const { UsageState } = require("../ExportsInfo");
10
10
  const Template = require("../Template");
11
11
  const { equals } = require("../util/ArrayHelpers");
12
12
  const makeSerializable = require("../util/makeSerializable");
13
- const propertyAccess = require("../util/propertyAccess");
13
+ const { propertyAccess } = require("../util/property");
14
14
  const { handleDependencyBase } = require("./CommonJsDependencyHelpers");
15
15
  const ModuleDependency = require("./ModuleDependency");
16
16
  const processExportInfo = require("./processExportInfo");
@@ -32,7 +32,9 @@ const processExportInfo = require("./processExportInfo");
32
32
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
33
33
  /** @typedef {import("./CommonJsDependencyHelpers").CommonJSDependencyBaseKeywords} CommonJSDependencyBaseKeywords */
34
34
 
35
- const idsSymbol = Symbol("CommonJsExportRequireDependency.ids");
35
+ const idsSymbol = /** @type {symbol} */ (
36
+ Symbol("CommonJsExportRequireDependency.ids")
37
+ );
36
38
 
37
39
  const EMPTY_OBJECT = {};
38
40
 
@@ -7,7 +7,7 @@
7
7
 
8
8
  const InitFragment = require("../InitFragment");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
- const propertyAccess = require("../util/propertyAccess");
10
+ const { propertyAccess } = require("../util/property");
11
11
  const { handleDependencyBase } = require("./CommonJsDependencyHelpers");
12
12
  const NullDependency = require("./NullDependency");
13
13
 
@@ -8,7 +8,7 @@
8
8
  const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const formatLocation = require("../formatLocation");
10
10
  const { evaluateToString } = require("../javascript/JavascriptParserHelpers");
11
- const propertyAccess = require("../util/propertyAccess");
11
+ const { propertyAccess } = require("../util/property");
12
12
  const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");
13
13
  const CommonJsExportsDependency = require("./CommonJsExportsDependency");
14
14
  const CommonJsSelfReferenceDependency = require("./CommonJsSelfReferenceDependency");
@@ -9,7 +9,7 @@ const Template = require("../Template");
9
9
  const { equals } = require("../util/ArrayHelpers");
10
10
  const { getTrimmedIdsAndRange } = require("../util/chainedImports");
11
11
  const makeSerializable = require("../util/makeSerializable");
12
- const propertyAccess = require("../util/propertyAccess");
12
+ const { propertyAccess } = require("../util/property");
13
13
  const ModuleDependency = require("./ModuleDependency");
14
14
 
15
15
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
@@ -14,6 +14,7 @@ const {
14
14
  expressionIsUnsupported,
15
15
  toConstantDependency
16
16
  } = require("../javascript/JavascriptParserHelpers");
17
+ const traverseDestructuringAssignmentProperties = require("../util/traverseDestructuringAssignmentProperties");
17
18
  const CommonJsFullRequireDependency = require("./CommonJsFullRequireDependency");
18
19
  const CommonJsRequireContextDependency = require("./CommonJsRequireContextDependency");
19
20
  const CommonJsRequireDependency = require("./CommonJsRequireDependency");
@@ -31,6 +32,7 @@ const RequireResolveHeaderDependency = require("./RequireResolveHeaderDependency
31
32
  /** @typedef {import("estree").NewExpression} NewExpression */
32
33
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
33
34
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
35
+ /** @typedef {import("../Dependency").RawReferencedExports} RawReferencedExports */
34
36
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
35
37
  /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
36
38
  /** @typedef {import("../javascript/JavascriptParser").ImportSource} ImportSource */
@@ -47,6 +49,48 @@ const RequireResolveHeaderDependency = require("./RequireResolveHeaderDependency
47
49
 
48
50
  const PLUGIN_NAME = "CommonJsImportsParserPlugin";
49
51
 
52
+ /**
53
+ * @param {Expression} expression expression
54
+ * @returns {boolean} true, when expression is `require(...)` or `module.require(...)`
55
+ */
56
+ const isRequireCallExpression = (expression) => {
57
+ if (expression.type !== "CallExpression") return false;
58
+ const { callee } = expression;
59
+ if (callee.type === "Identifier") {
60
+ return callee.name === "require";
61
+ }
62
+ if (callee.type === "MemberExpression" && !callee.computed) {
63
+ const object = callee.object;
64
+ const property = callee.property;
65
+ return (
66
+ object.type === "Identifier" &&
67
+ object.name === "module" &&
68
+ property.type === "Identifier" &&
69
+ property.name === "require"
70
+ );
71
+ }
72
+ return false;
73
+ };
74
+
75
+ /**
76
+ * @param {JavascriptParser} parser parser
77
+ * @param {CallExpression | NewExpression} expr expression
78
+ * @returns {RawReferencedExports | null} referenced exports from destructuring
79
+ */
80
+ const getRequireReferencedExportsFromDestructuring = (parser, expr) => {
81
+ const referencedPropertiesInDestructuring =
82
+ parser.destructuringAssignmentPropertiesFor(expr);
83
+ if (!referencedPropertiesInDestructuring) return null;
84
+
85
+ /** @type {RawReferencedExports} */
86
+ const referencedExports = [];
87
+ traverseDestructuringAssignmentProperties(
88
+ referencedPropertiesInDestructuring,
89
+ (stack) => referencedExports.push(stack.map((p) => p.id))
90
+ );
91
+ return referencedExports;
92
+ };
93
+
50
94
  /**
51
95
  * @param {JavascriptParser} parser parser
52
96
  * @returns {(expr: Expression) => boolean} handler
@@ -101,10 +145,15 @@ const createRequireCallHandler = (parser, options, getContext) => {
101
145
  */
102
146
  const processRequireItem = (expr, param) => {
103
147
  if (param.isString()) {
148
+ const referencedExports = getRequireReferencedExportsFromDestructuring(
149
+ parser,
150
+ expr
151
+ );
104
152
  const dep = new CommonJsRequireDependency(
105
153
  /** @type {string} */ (param.string),
106
154
  /** @type {Range} */ (param.range),
107
- getContext()
155
+ getContext(),
156
+ referencedExports
108
157
  );
109
158
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
110
159
  dep.optional = Boolean(parser.scope.inTry);
@@ -118,6 +167,10 @@ const createRequireCallHandler = (parser, options, getContext) => {
118
167
  * @returns {boolean | void} true when handled
119
168
  */
120
169
  const processRequireContext = (expr, param) => {
170
+ const referencedExports = getRequireReferencedExportsFromDestructuring(
171
+ parser,
172
+ expr
173
+ );
121
174
  const dep = ContextDependencyHelpers.create(
122
175
  CommonJsRequireContextDependency,
123
176
  /** @type {Range} */ (expr.range),
@@ -125,7 +178,8 @@ const createRequireCallHandler = (parser, options, getContext) => {
125
178
  expr,
126
179
  options,
127
180
  {
128
- category: "commonjs"
181
+ category: "commonjs",
182
+ referencedExports
129
183
  },
130
184
  parser,
131
185
  undefined,
@@ -353,6 +407,13 @@ class CommonJsImportsParserPlugin {
353
407
  */
354
408
  apply(parser) {
355
409
  const options = this.options;
410
+ parser.hooks.collectDestructuringAssignmentProperties.tap(
411
+ PLUGIN_NAME,
412
+ (expr) => {
413
+ if (isRequireCallExpression(expr)) return true;
414
+ }
415
+ );
416
+
356
417
  const getContext = () => {
357
418
  if (parser.currentTagData) {
358
419
  const { context } =