webpack 5.79.0 → 5.81.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 (115) hide show
  1. package/README.md +3 -0
  2. package/lib/AsyncDependenciesBlock.js +8 -0
  3. package/lib/CodeGenerationResults.js +2 -2
  4. package/lib/Compilation.js +2 -2
  5. package/lib/ContextModule.js +8 -0
  6. package/lib/CssModule.js +137 -0
  7. package/lib/DefinePlugin.js +81 -44
  8. package/lib/DelegatedModule.js +5 -0
  9. package/lib/DependenciesBlock.js +8 -0
  10. package/lib/Dependency.js +8 -0
  11. package/lib/DllModule.js +8 -0
  12. package/lib/ExportsInfo.js +3 -0
  13. package/lib/ExternalModule.js +8 -0
  14. package/lib/FileSystemInfo.js +8 -0
  15. package/lib/LoaderOptionsPlugin.js +12 -2
  16. package/lib/Module.js +8 -0
  17. package/lib/ModuleBuildError.js +9 -0
  18. package/lib/ModuleError.js +9 -0
  19. package/lib/ModuleFilenameHelpers.js +113 -4
  20. package/lib/ModuleParseError.js +9 -0
  21. package/lib/ModuleTypeConstants.js +21 -0
  22. package/lib/ModuleWarning.js +9 -0
  23. package/lib/NormalModule.js +8 -0
  24. package/lib/NormalModuleFactory.js +26 -4
  25. package/lib/RawModule.js +8 -0
  26. package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
  27. package/lib/WebpackError.js +8 -0
  28. package/lib/asset/AssetGenerator.js +11 -3
  29. package/lib/asset/RawDataUrlModule.js +8 -0
  30. package/lib/cache/ResolverCachePlugin.js +3 -0
  31. package/lib/config/normalization.js +1 -0
  32. package/lib/container/ContainerEntryModule.js +5 -0
  33. package/lib/container/ContainerExposedDependency.js +9 -0
  34. package/lib/container/FallbackDependency.js +6 -0
  35. package/lib/container/FallbackModule.js +5 -0
  36. package/lib/container/RemoteModule.js +5 -0
  37. package/lib/css/CssModulesPlugin.js +91 -50
  38. package/lib/css/CssParser.js +226 -72
  39. package/lib/css/walkCssTokens.js +152 -117
  40. package/lib/dependencies/AMDDefineDependency.js +8 -0
  41. package/lib/dependencies/AMDRequireArrayDependency.js +8 -0
  42. package/lib/dependencies/AMDRequireContextDependency.js +9 -0
  43. package/lib/dependencies/AMDRequireDependency.js +8 -0
  44. package/lib/dependencies/CachedConstDependency.js +8 -0
  45. package/lib/dependencies/CommonJsDependencyHelpers.js +9 -0
  46. package/lib/dependencies/CommonJsExportRequireDependency.js +8 -0
  47. package/lib/dependencies/CommonJsExportsDependency.js +8 -0
  48. package/lib/dependencies/CommonJsExportsParserPlugin.js +65 -3
  49. package/lib/dependencies/CommonJsFullRequireDependency.js +8 -0
  50. package/lib/dependencies/CommonJsRequireContextDependency.js +9 -0
  51. package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
  52. package/lib/dependencies/ConstDependency.js +8 -0
  53. package/lib/dependencies/ContextDependency.js +8 -0
  54. package/lib/dependencies/ContextElementDependency.js +8 -0
  55. package/lib/dependencies/CreateScriptUrlDependency.js +8 -0
  56. package/lib/dependencies/CssExportDependency.js +8 -0
  57. package/lib/dependencies/CssImportDependency.js +52 -1
  58. package/lib/dependencies/CssLocalIdentifierDependency.js +8 -0
  59. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +8 -0
  60. package/lib/dependencies/CssUrlDependency.js +38 -18
  61. package/lib/dependencies/DllEntryDependency.js +9 -0
  62. package/lib/dependencies/ExportsInfoDependency.js +5 -0
  63. package/lib/dependencies/HarmonyAcceptDependency.js +8 -0
  64. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +8 -0
  65. package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
  66. package/lib/dependencies/HarmonyExportHeaderDependency.js +8 -0
  67. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +14 -0
  68. package/lib/dependencies/HarmonyExportSpecifierDependency.js +8 -0
  69. package/lib/dependencies/HarmonyImportDependency.js +8 -0
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +8 -0
  71. package/lib/dependencies/ImportContextDependency.js +9 -0
  72. package/lib/dependencies/ImportDependency.js +8 -0
  73. package/lib/dependencies/ImportMetaPlugin.js +56 -26
  74. package/lib/dependencies/ImportParserPlugin.js +17 -1
  75. package/lib/dependencies/JsonExportsDependency.js +8 -0
  76. package/lib/dependencies/LocalModuleDependency.js +8 -0
  77. package/lib/dependencies/ModuleDecoratorDependency.js +8 -0
  78. package/lib/dependencies/ModuleDependency.js +8 -0
  79. package/lib/dependencies/ProvidedDependency.js +8 -0
  80. package/lib/dependencies/PureExpressionDependency.js +8 -0
  81. package/lib/dependencies/RequireEnsureDependency.js +8 -0
  82. package/lib/dependencies/RequireHeaderDependency.js +5 -0
  83. package/lib/dependencies/RequireResolveContextDependency.js +9 -0
  84. package/lib/dependencies/RequireResolveHeaderDependency.js +5 -0
  85. package/lib/dependencies/RuntimeRequirementsDependency.js +8 -0
  86. package/lib/dependencies/StaticExportsDependency.js +8 -0
  87. package/lib/dependencies/URLDependency.js +8 -0
  88. package/lib/dependencies/UnsupportedDependency.js +8 -0
  89. package/lib/dependencies/WebAssemblyExportImportedDependency.js +8 -0
  90. package/lib/dependencies/WebAssemblyImportDependency.js +8 -0
  91. package/lib/dependencies/WorkerDependency.js +8 -0
  92. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  93. package/lib/index.js +1 -0
  94. package/lib/javascript/JavascriptParser.js +14 -4
  95. package/lib/optimize/RealContentHashPlugin.js +6 -0
  96. package/lib/runtime/AutoPublicPathRuntimeModule.js +6 -1
  97. package/lib/schemes/DataUriPlugin.js +12 -3
  98. package/lib/serialization/ObjectMiddleware.js +2 -0
  99. package/lib/sharing/ConsumeSharedModule.js +8 -0
  100. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -3
  101. package/lib/sharing/ProvideSharedDependency.js +6 -0
  102. package/lib/sharing/ProvideSharedModule.js +5 -0
  103. package/lib/sharing/ShareRuntimeModule.js +7 -4
  104. package/lib/stats/DefaultStatsFactoryPlugin.js +98 -25
  105. package/lib/stats/DefaultStatsPresetPlugin.js +9 -0
  106. package/lib/stats/DefaultStatsPrinterPlugin.js +4 -0
  107. package/lib/util/LazySet.js +10 -2
  108. package/lib/util/MapHelpers.js +19 -5
  109. package/lib/util/binarySearchBounds.js +49 -0
  110. package/lib/util/internalSerializables.js +1 -0
  111. package/lib/util/semver.js +1 -1
  112. package/package.json +19 -22
  113. package/schemas/WebpackOptions.check.js +1 -1
  114. package/schemas/WebpackOptions.json +16 -0
  115. package/types.d.ts +108 -39
@@ -7,7 +7,7 @@
7
7
 
8
8
  /**
9
9
  * @typedef {Object} CssTokenCallbacks
10
- * @property {function(string, number): boolean} isSelector
10
+ * @property {function(string, number): boolean=} isSelector
11
11
  * @property {function(string, number, number, number, number): number=} url
12
12
  * @property {function(string, number, number): number=} string
13
13
  * @property {function(string, number, number): number=} leftParenthesis
@@ -36,14 +36,16 @@ const CC_FORM_FEED = "\f".charCodeAt(0);
36
36
  const CC_TAB = "\t".charCodeAt(0);
37
37
  const CC_SPACE = " ".charCodeAt(0);
38
38
 
39
- const CC_SLASH = "/".charCodeAt(0);
40
- const CC_BACK_SLASH = "\\".charCodeAt(0);
39
+ const CC_SOLIDUS = "/".charCodeAt(0);
40
+ const CC_REVERSE_SOLIDUS = "\\".charCodeAt(0);
41
41
  const CC_ASTERISK = "*".charCodeAt(0);
42
42
 
43
43
  const CC_LEFT_PARENTHESIS = "(".charCodeAt(0);
44
44
  const CC_RIGHT_PARENTHESIS = ")".charCodeAt(0);
45
45
  const CC_LEFT_CURLY = "{".charCodeAt(0);
46
46
  const CC_RIGHT_CURLY = "}".charCodeAt(0);
47
+ const CC_LEFT_SQUARE = "[".charCodeAt(0);
48
+ const CC_RIGHT_SQUARE = "]".charCodeAt(0);
47
49
 
48
50
  const CC_QUOTATION_MARK = '"'.charCodeAt(0);
49
51
  const CC_APOSTROPHE = "'".charCodeAt(0);
@@ -100,28 +102,46 @@ const _isWhiteSpace = cc => {
100
102
  );
101
103
  };
102
104
 
105
+ const _isIdentStartCodePoint = cc => {
106
+ return (
107
+ (cc >= CC_LOWER_A && cc <= CC_LOWER_Z) ||
108
+ (cc >= CC_UPPER_A && cc <= CC_UPPER_Z) ||
109
+ cc === CC_LOW_LINE ||
110
+ cc >= 0x80
111
+ );
112
+ };
113
+
103
114
  /** @type {CharHandler} */
104
- const consumeSingleCharToken = (input, pos, callbacks) => {
115
+ const consumeDelimToken = (input, pos, callbacks) => {
105
116
  return pos + 1;
106
117
  };
107
118
 
108
119
  /** @type {CharHandler} */
109
- const consumePotentialComment = (input, pos, callbacks) => {
110
- pos++;
111
- if (pos === input.length) return pos;
112
- let cc = input.charCodeAt(pos);
113
- if (cc !== CC_ASTERISK) return pos;
114
- for (;;) {
115
- pos++;
116
- if (pos === input.length) return pos;
117
- cc = input.charCodeAt(pos);
118
- while (cc === CC_ASTERISK) {
120
+ const consumeComments = (input, pos, callbacks) => {
121
+ // If the next two input code point are U+002F SOLIDUS (/) followed by a U+002A
122
+ // ASTERISK (*), consume them and all following code points up to and including
123
+ // the first U+002A ASTERISK (*) followed by a U+002F SOLIDUS (/), or up to an
124
+ // EOF code point. Return to the start of this step.
125
+ //
126
+ // If the preceding paragraph ended by consuming an EOF code point, this is a parse error.
127
+ // But we are silent on errors.
128
+ if (
129
+ input.charCodeAt(pos) === CC_SOLIDUS &&
130
+ input.charCodeAt(pos + 1) === CC_ASTERISK
131
+ ) {
132
+ pos += 1;
133
+ while (pos < input.length) {
134
+ if (
135
+ input.charCodeAt(pos) === CC_ASTERISK &&
136
+ input.charCodeAt(pos + 1) === CC_SOLIDUS
137
+ ) {
138
+ pos += 2;
139
+ break;
140
+ }
119
141
  pos++;
120
- if (pos === input.length) return pos;
121
- cc = input.charCodeAt(pos);
122
- if (cc === CC_SLASH) return pos + 1;
123
142
  }
124
143
  }
144
+ return pos;
125
145
  };
126
146
 
127
147
  /** @type {function(number): CharHandler} */
@@ -144,7 +164,7 @@ const _consumeString = (input, pos, end) => {
144
164
  // bad string
145
165
  return pos;
146
166
  }
147
- if (cc === CC_BACK_SLASH) {
167
+ if (cc === CC_REVERSE_SOLIDUS) {
148
168
  // we don't need to fully parse the escaped code point
149
169
  // just skip over a potential new line
150
170
  pos++;
@@ -165,6 +185,12 @@ const _isIdentifierStartCode = cc => {
165
185
  );
166
186
  };
167
187
 
188
+ const _isTwoCodePointsAreValidEscape = (first, second) => {
189
+ if (first !== CC_REVERSE_SOLIDUS) return false;
190
+ if (_isNewLine(second)) return false;
191
+ return true;
192
+ };
193
+
168
194
  const _isDigit = cc => {
169
195
  return cc >= CC_0 && cc <= CC_9;
170
196
  };
@@ -175,13 +201,13 @@ const _startsIdentifier = (input, pos) => {
175
201
  if (pos === input.length) return false;
176
202
  const cc = input.charCodeAt(pos + 1);
177
203
  if (cc === CC_HYPHEN_MINUS) return true;
178
- if (cc === CC_BACK_SLASH) {
204
+ if (cc === CC_REVERSE_SOLIDUS) {
179
205
  const cc = input.charCodeAt(pos + 2);
180
206
  return !_isNewLine(cc);
181
207
  }
182
208
  return _isIdentifierStartCode(cc);
183
209
  }
184
- if (cc === CC_BACK_SLASH) {
210
+ if (cc === CC_REVERSE_SOLIDUS) {
185
211
  const cc = input.charCodeAt(pos + 1);
186
212
  return !_isNewLine(cc);
187
213
  }
@@ -208,6 +234,7 @@ const consumeMinus = (input, pos, callbacks) => {
208
234
  pos++;
209
235
  if (pos === input.length) return pos;
210
236
  const cc = input.charCodeAt(pos);
237
+ // If the input stream starts with a number, reconsume the current input code point, consume a numeric token, and return it.
211
238
  if (cc === CC_FULL_STOP || _isDigit(cc)) {
212
239
  return consumeNumericToken(input, pos, callbacks);
213
240
  } else if (cc === CC_HYPHEN_MINUS) {
@@ -222,7 +249,7 @@ const consumeMinus = (input, pos, callbacks) => {
222
249
  return callbacks.identifier(input, start, pos);
223
250
  }
224
251
  }
225
- } else if (cc === CC_BACK_SLASH) {
252
+ } else if (cc === CC_REVERSE_SOLIDUS) {
226
253
  if (pos + 1 === input.length) return pos;
227
254
  const cc = input.charCodeAt(pos + 1);
228
255
  if (_isNewLine(cc)) return pos;
@@ -231,11 +258,7 @@ const consumeMinus = (input, pos, callbacks) => {
231
258
  return callbacks.identifier(input, start, pos);
232
259
  }
233
260
  } else if (_isIdentifierStartCode(cc)) {
234
- pos++;
235
- pos = _consumeIdentifier(input, pos);
236
- if (callbacks.identifier !== undefined) {
237
- return callbacks.identifier(input, start, pos);
238
- }
261
+ pos = consumeOtherIdentifier(input, pos - 1, callbacks);
239
262
  }
240
263
  return pos;
241
264
  };
@@ -289,9 +312,10 @@ const consumeOtherIdentifier = (input, pos, callbacks) => {
289
312
  const consumePotentialUrl = (input, pos, callbacks) => {
290
313
  const start = pos;
291
314
  pos = _consumeIdentifier(input, pos);
315
+ const nextPos = pos + 1;
292
316
  if (
293
317
  pos === start + 3 &&
294
- input.slice(start, pos + 1).toLowerCase() === "url("
318
+ input.slice(start, nextPos).toLowerCase() === "url("
295
319
  ) {
296
320
  pos++;
297
321
  let cc = input.charCodeAt(pos);
@@ -301,26 +325,15 @@ const consumePotentialUrl = (input, pos, callbacks) => {
301
325
  cc = input.charCodeAt(pos);
302
326
  }
303
327
  if (cc === CC_QUOTATION_MARK || cc === CC_APOSTROPHE) {
304
- pos++;
305
- const contentStart = pos;
306
- pos = _consumeString(input, pos, cc);
307
- const contentEnd = pos - 1;
308
- cc = input.charCodeAt(pos);
309
- while (_isWhiteSpace(cc)) {
310
- pos++;
311
- if (pos === input.length) return pos;
312
- cc = input.charCodeAt(pos);
328
+ if (callbacks.function !== undefined) {
329
+ return callbacks.function(input, start, nextPos);
313
330
  }
314
- if (cc !== CC_RIGHT_PARENTHESIS) return pos;
315
- pos++;
316
- if (callbacks.url !== undefined)
317
- return callbacks.url(input, start, pos, contentStart, contentEnd);
318
- return pos;
331
+ return nextPos;
319
332
  } else {
320
333
  const contentStart = pos;
321
334
  let contentEnd;
322
335
  for (;;) {
323
- if (cc === CC_BACK_SLASH) {
336
+ if (cc === CC_REVERSE_SOLIDUS) {
324
337
  pos++;
325
338
  if (pos === input.length) return pos;
326
339
  pos++;
@@ -439,7 +452,7 @@ const consumeComma = (input, pos, callbacks) => {
439
452
  const _consumeIdentifier = (input, pos) => {
440
453
  for (;;) {
441
454
  const cc = input.charCodeAt(pos);
442
- if (cc === CC_BACK_SLASH) {
455
+ if (cc === CC_REVERSE_SOLIDUS) {
443
456
  pos++;
444
457
  if (pos === input.length) return pos;
445
458
  pos++;
@@ -513,7 +526,6 @@ const consumeLessThan = (input, pos, callbacks) => {
513
526
  return pos + 1;
514
527
  };
515
528
 
516
- /** @type {CharHandler} */
517
529
  const consumeAt = (input, pos, callbacks) => {
518
530
  const start = pos;
519
531
  pos++;
@@ -527,65 +539,102 @@ const consumeAt = (input, pos, callbacks) => {
527
539
  return pos;
528
540
  };
529
541
 
542
+ /** @type {CharHandler} */
543
+ const consumeReverseSolidus = (input, pos, callbacks) => {
544
+ const start = pos;
545
+ pos++;
546
+ if (pos === input.length) return pos;
547
+ // If the input stream starts with a valid escape, reconsume the current input code point, consume an ident-like token, and return it.
548
+ if (
549
+ _isTwoCodePointsAreValidEscape(
550
+ input.charCodeAt(start),
551
+ input.charCodeAt(pos)
552
+ )
553
+ ) {
554
+ return consumeOtherIdentifier(input, pos - 1, callbacks);
555
+ }
556
+ // Otherwise, this is a parse error. Return a <delim-token> with its value set to the current input code point.
557
+ return pos;
558
+ };
559
+
530
560
  const CHAR_MAP = Array.from({ length: 0x80 }, (_, cc) => {
531
561
  // https://drafts.csswg.org/css-syntax/#consume-token
532
562
  switch (cc) {
563
+ // whitespace
533
564
  case CC_LINE_FEED:
534
565
  case CC_CARRIAGE_RETURN:
535
566
  case CC_FORM_FEED:
536
567
  case CC_TAB:
537
568
  case CC_SPACE:
538
569
  return consumeSpace;
570
+ // U+0022 QUOTATION MARK (")
539
571
  case CC_QUOTATION_MARK:
540
- case CC_APOSTROPHE:
541
572
  return consumeString(cc);
573
+ // U+0023 NUMBER SIGN (#)
542
574
  case CC_NUMBER_SIGN:
543
575
  return consumeNumberSign;
544
- case CC_SLASH:
545
- return consumePotentialComment;
546
- // case CC_LEFT_SQUARE:
547
- // case CC_RIGHT_SQUARE:
548
- // case CC_COMMA:
549
- // case CC_COLON:
550
- // return consumeSingleCharToken;
551
- case CC_COMMA:
552
- return consumeComma;
553
- case CC_SEMICOLON:
554
- return consumeSemicolon;
576
+ // U+0027 APOSTROPHE (')
577
+ case CC_APOSTROPHE:
578
+ return consumeString(cc);
579
+ // U+0028 LEFT PARENTHESIS (()
555
580
  case CC_LEFT_PARENTHESIS:
556
581
  return consumeLeftParenthesis;
582
+ // U+0029 RIGHT PARENTHESIS ())
557
583
  case CC_RIGHT_PARENTHESIS:
558
584
  return consumeRightParenthesis;
559
- case CC_LEFT_CURLY:
560
- return consumeLeftCurlyBracket;
561
- case CC_RIGHT_CURLY:
562
- return consumeRightCurlyBracket;
563
- case CC_COLON:
564
- return consumePotentialPseudo;
585
+ // U+002B PLUS SIGN (+)
565
586
  case CC_PLUS_SIGN:
566
587
  return consumeNumericToken;
567
- case CC_FULL_STOP:
568
- return consumeDot;
588
+ // U+002C COMMA (,)
589
+ case CC_COMMA:
590
+ return consumeComma;
591
+ // U+002D HYPHEN-MINUS (-)
569
592
  case CC_HYPHEN_MINUS:
570
593
  return consumeMinus;
594
+ // U+002E FULL STOP (.)
595
+ case CC_FULL_STOP:
596
+ return consumeDot;
597
+ // U+003A COLON (:)
598
+ case CC_COLON:
599
+ return consumePotentialPseudo;
600
+ // U+003B SEMICOLON (;)
601
+ case CC_SEMICOLON:
602
+ return consumeSemicolon;
603
+ // U+003C LESS-THAN SIGN (<)
571
604
  case CC_LESS_THAN_SIGN:
572
605
  return consumeLessThan;
606
+ // U+0040 COMMERCIAL AT (@)
573
607
  case CC_AT_SIGN:
574
608
  return consumeAt;
609
+ // U+005B LEFT SQUARE BRACKET ([)
610
+ case CC_LEFT_SQUARE:
611
+ return consumeDelimToken;
612
+ // U+005C REVERSE SOLIDUS (\)
613
+ case CC_REVERSE_SOLIDUS:
614
+ return consumeReverseSolidus;
615
+ // U+005D RIGHT SQUARE BRACKET (])
616
+ case CC_RIGHT_SQUARE:
617
+ return consumeDelimToken;
618
+ // U+007B LEFT CURLY BRACKET ({)
619
+ case CC_LEFT_CURLY:
620
+ return consumeLeftCurlyBracket;
621
+ // U+007D RIGHT CURLY BRACKET (})
622
+ case CC_RIGHT_CURLY:
623
+ return consumeRightCurlyBracket;
624
+ // Optimization
575
625
  case CC_LOWER_U:
576
626
  case CC_UPPER_U:
577
627
  return consumePotentialUrl;
578
- case CC_LOW_LINE:
579
- return consumeOtherIdentifier;
580
628
  default:
629
+ // digit
581
630
  if (_isDigit(cc)) return consumeNumericToken;
582
- if (
583
- (cc >= CC_LOWER_A && cc <= CC_LOWER_Z) ||
584
- (cc >= CC_UPPER_A && cc <= CC_UPPER_Z)
585
- ) {
631
+ // ident-start code point
632
+ if (_isIdentStartCodePoint(cc)) {
586
633
  return consumeOtherIdentifier;
587
634
  }
588
- return consumeSingleCharToken;
635
+ // EOF, but we don't have it
636
+ // anything else
637
+ return consumeDelimToken;
589
638
  }
590
639
  });
591
640
 
@@ -595,9 +644,15 @@ const CHAR_MAP = Array.from({ length: 0x80 }, (_, cc) => {
595
644
  * @returns {void}
596
645
  */
597
646
  module.exports = (input, callbacks) => {
647
+ // This section describes how to consume a token from a stream of code points. It will return a single token of any type.
598
648
  let pos = 0;
599
649
  while (pos < input.length) {
650
+ // Consume comments.
651
+ pos = consumeComments(input, pos, callbacks);
652
+
600
653
  const cc = input.charCodeAt(pos);
654
+
655
+ // Consume the next input code point.
601
656
  if (cc < 0x80) {
602
657
  pos = CHAR_MAP[cc](input, pos, callbacks);
603
658
  } else {
@@ -606,59 +661,39 @@ module.exports = (input, callbacks) => {
606
661
  }
607
662
  };
608
663
 
664
+ /**
665
+ * @param {string} input input
666
+ * @param {number} pos position
667
+ * @returns {number} position after comments
668
+ */
609
669
  module.exports.eatComments = (input, pos) => {
610
- loop: for (;;) {
611
- const cc = input.charCodeAt(pos);
612
- if (cc === CC_SLASH) {
613
- if (pos === input.length) return pos;
614
- let cc = input.charCodeAt(pos + 1);
615
- if (cc !== CC_ASTERISK) return pos;
616
- pos++;
617
- for (;;) {
618
- pos++;
619
- if (pos === input.length) return pos;
620
- cc = input.charCodeAt(pos);
621
- while (cc === CC_ASTERISK) {
622
- pos++;
623
- if (pos === input.length) return pos;
624
- cc = input.charCodeAt(pos);
625
- if (cc === CC_SLASH) {
626
- pos++;
627
- continue loop;
628
- }
629
- }
630
- }
670
+ for (;;) {
671
+ let originalPos = pos;
672
+ pos = consumeComments(input, pos, {});
673
+ if (originalPos === pos) {
674
+ break;
631
675
  }
632
- return pos;
633
676
  }
677
+
678
+ return pos;
634
679
  };
635
680
 
681
+ /**
682
+ * @param {string} input input
683
+ * @param {number} pos position
684
+ * @returns {number} position after whitespace and comments
685
+ */
636
686
  module.exports.eatWhitespaceAndComments = (input, pos) => {
637
- loop: for (;;) {
638
- const cc = input.charCodeAt(pos);
639
- if (cc === CC_SLASH) {
640
- if (pos === input.length) return pos;
641
- let cc = input.charCodeAt(pos + 1);
642
- if (cc !== CC_ASTERISK) return pos;
643
- pos++;
644
- for (;;) {
645
- pos++;
646
- if (pos === input.length) return pos;
647
- cc = input.charCodeAt(pos);
648
- while (cc === CC_ASTERISK) {
649
- pos++;
650
- if (pos === input.length) return pos;
651
- cc = input.charCodeAt(pos);
652
- if (cc === CC_SLASH) {
653
- pos++;
654
- continue loop;
655
- }
656
- }
657
- }
658
- } else if (_isWhiteSpace(cc)) {
687
+ for (;;) {
688
+ let originalPos = pos;
689
+ pos = consumeComments(input, pos, {});
690
+ while (_isWhiteSpace(input.charCodeAt(pos))) {
659
691
  pos++;
660
- continue;
661
692
  }
662
- return pos;
693
+ if (originalPos === pos) {
694
+ break;
695
+ }
663
696
  }
697
+
698
+ return pos;
664
699
  };
@@ -12,6 +12,8 @@ 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("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
16
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
15
17
 
16
18
  /** @type {Record<string, { definition: string, content: string, requests: string[] }>} */
17
19
  const DEFINITIONS = {
@@ -119,6 +121,9 @@ class AMDDefineDependency extends NullDependency {
119
121
  return "amd define";
120
122
  }
121
123
 
124
+ /**
125
+ * @param {ObjectSerializerContext} context context
126
+ */
122
127
  serialize(context) {
123
128
  const { write } = context;
124
129
  write(this.range);
@@ -130,6 +135,9 @@ class AMDDefineDependency extends NullDependency {
130
135
  super.serialize(context);
131
136
  }
132
137
 
138
+ /**
139
+ * @param {ObjectDeserializerContext} context context
140
+ */
133
141
  deserialize(context) {
134
142
  const { read } = context;
135
143
  this.range = read();
@@ -12,6 +12,8 @@ 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("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
16
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
15
17
 
16
18
  class AMDRequireArrayDependency extends NullDependency {
17
19
  constructor(depsArray, range) {
@@ -29,6 +31,9 @@ class AMDRequireArrayDependency extends NullDependency {
29
31
  return "amd";
30
32
  }
31
33
 
34
+ /**
35
+ * @param {ObjectSerializerContext} context context
36
+ */
32
37
  serialize(context) {
33
38
  const { write } = context;
34
39
 
@@ -38,6 +43,9 @@ class AMDRequireArrayDependency extends NullDependency {
38
43
  super.serialize(context);
39
44
  }
40
45
 
46
+ /**
47
+ * @param {ObjectDeserializerContext} context context
48
+ */
41
49
  deserialize(context) {
42
50
  const { read } = context;
43
51
 
@@ -8,6 +8,9 @@
8
8
  const makeSerializable = require("../util/makeSerializable");
9
9
  const ContextDependency = require("./ContextDependency");
10
10
 
11
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
12
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
13
+
11
14
  class AMDRequireContextDependency extends ContextDependency {
12
15
  constructor(options, range, valueRange) {
13
16
  super(options);
@@ -24,6 +27,9 @@ class AMDRequireContextDependency extends ContextDependency {
24
27
  return "amd";
25
28
  }
26
29
 
30
+ /**
31
+ * @param {ObjectSerializerContext} context context
32
+ */
27
33
  serialize(context) {
28
34
  const { write } = context;
29
35
 
@@ -33,6 +39,9 @@ class AMDRequireContextDependency extends ContextDependency {
33
39
  super.serialize(context);
34
40
  }
35
41
 
42
+ /**
43
+ * @param {ObjectDeserializerContext} context context
44
+ */
36
45
  deserialize(context) {
37
46
  const { read } = context;
38
47
 
@@ -13,6 +13,8 @@ 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("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
17
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
16
18
 
17
19
  class AMDRequireDependency extends NullDependency {
18
20
  constructor(outerRange, arrayRange, functionRange, errorCallbackRange) {
@@ -30,6 +32,9 @@ class AMDRequireDependency extends NullDependency {
30
32
  return "amd";
31
33
  }
32
34
 
35
+ /**
36
+ * @param {ObjectSerializerContext} context context
37
+ */
33
38
  serialize(context) {
34
39
  const { write } = context;
35
40
 
@@ -43,6 +48,9 @@ class AMDRequireDependency extends NullDependency {
43
48
  super.serialize(context);
44
49
  }
45
50
 
51
+ /**
52
+ * @param {ObjectDeserializerContext} context context
53
+ */
46
54
  deserialize(context) {
47
55
  const { read } = context;
48
56
 
@@ -18,6 +18,8 @@ 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("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
22
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
21
23
  /** @typedef {import("../util/Hash")} Hash */
22
24
 
23
25
  class CachedConstDependency extends NullDependency {
@@ -42,6 +44,9 @@ class CachedConstDependency extends NullDependency {
42
44
  hash.update(this._hashUpdate);
43
45
  }
44
46
 
47
+ /**
48
+ * @param {ObjectSerializerContext} context context
49
+ */
45
50
  serialize(context) {
46
51
  const { write } = context;
47
52
 
@@ -52,6 +57,9 @@ class CachedConstDependency extends NullDependency {
52
57
  super.serialize(context);
53
58
  }
54
59
 
60
+ /**
61
+ * @param {ObjectDeserializerContext} context context
62
+ */
55
63
  deserialize(context) {
56
64
  const { read } = context;
57
65
 
@@ -7,6 +7,15 @@
7
7
 
8
8
  const RuntimeGlobals = require("../RuntimeGlobals");
9
9
 
10
+ /** @typedef {import("../Module")} Module */
11
+ /** @typedef {"exports" | "module.exports" | "this" | "Object.defineProperty(exports)" | "Object.defineProperty(module.exports)" | "Object.defineProperty(this)"} CommonJSDependencyBaseKeywords */
12
+
13
+ /**
14
+ * @param {CommonJSDependencyBaseKeywords} depBase commonjs dependency base
15
+ * @param {Module} module module
16
+ * @param {Set<string>} runtimeRequirements runtime requirements
17
+ * @returns {[string, string]} type and base
18
+ */
10
19
  exports.handleDependencyBase = (depBase, module, runtimeRequirements) => {
11
20
  let base = undefined;
12
21
  let type;
@@ -22,6 +22,8 @@ const processExportInfo = require("./processExportInfo");
22
22
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
23
23
  /** @typedef {import("../Module")} Module */
24
24
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
25
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
26
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
25
27
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
26
28
 
27
29
  const idsSymbol = Symbol("CommonJsExportRequireDependency.ids");
@@ -270,6 +272,9 @@ class CommonJsExportRequireDependency extends ModuleDependency {
270
272
  return { exports, checked };
271
273
  }
272
274
 
275
+ /**
276
+ * @param {ObjectSerializerContext} context context
277
+ */
273
278
  serialize(context) {
274
279
  const { write } = context;
275
280
  write(this.asiSafe);
@@ -282,6 +287,9 @@ class CommonJsExportRequireDependency extends ModuleDependency {
282
287
  super.serialize(context);
283
288
  }
284
289
 
290
+ /**
291
+ * @param {ObjectDeserializerContext} context context
292
+ */
285
293
  deserialize(context) {
286
294
  const { read } = context;
287
295
  this.asiSafe = read();
@@ -16,6 +16,8 @@ const NullDependency = require("./NullDependency");
16
16
  /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
17
17
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
18
18
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
19
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
20
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
19
21
 
20
22
  const EMPTY_OBJECT = {};
21
23
 
@@ -53,6 +55,9 @@ class CommonJsExportsDependency extends NullDependency {
53
55
  };
54
56
  }
55
57
 
58
+ /**
59
+ * @param {ObjectSerializerContext} context context
60
+ */
56
61
  serialize(context) {
57
62
  const { write } = context;
58
63
  write(this.range);
@@ -62,6 +67,9 @@ class CommonJsExportsDependency extends NullDependency {
62
67
  super.serialize(context);
63
68
  }
64
69
 
70
+ /**
71
+ * @param {ObjectDeserializerContext} context context
72
+ */
65
73
  deserialize(context) {
66
74
  const { read } = context;
67
75
  this.range = read();