@rspack/core 2.1.0-beta.0 → 2.1.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 (33) hide show
  1. package/compiled/http-proxy-middleware/package.json +1 -1
  2. package/compiled/watchpack/index.js +474 -235
  3. package/compiled/watchpack/package.json +1 -1
  4. package/compiled/watchpack/types/DirectoryWatcher.d.ts +2 -0
  5. package/compiled/watchpack/types/index.d.ts +121 -113
  6. package/compiled/watchpack/types/util/globToRegExp.d.ts +2 -0
  7. package/compiled/watchpack/types/watchpack.d.ts +1 -1
  8. package/compiled/webpack-sources/index.js +953 -351
  9. package/compiled/webpack-sources/package.json +1 -1
  10. package/compiled/webpack-sources/types.d.ts +40 -1
  11. package/dist/Module.d.ts +0 -1
  12. package/dist/NativeWatchFileSystem.d.ts +29 -0
  13. package/dist/RuntimeGlobals.d.ts +0 -1
  14. package/dist/builtin-loader/swc/types.d.ts +1 -59
  15. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +1 -1
  16. package/dist/builtin-plugin/html-plugin/options.d.ts +1 -1
  17. package/dist/config/normalization.d.ts +2 -2
  18. package/dist/config/types.d.ts +15 -14
  19. package/dist/index.js +116 -67
  20. package/dist/lib/HookWebpackError.d.ts +0 -1
  21. package/dist/lib/cache/getLazyHashedEtag.d.ts +1 -1
  22. package/dist/lib/cache/mergeEtags.d.ts +0 -1
  23. package/dist/node/NodeWatchFileSystem.d.ts +13 -1
  24. package/dist/rslib-runtime-worker.js +22 -0
  25. package/dist/rspack.d.ts +0 -1
  26. package/dist/sharing/IndependentSharedPlugin.d.ts +0 -1
  27. package/dist/stats/statsFactoryUtils.d.ts +0 -6
  28. package/dist/util/comparators.d.ts +1 -1
  29. package/dist/util/fake.d.ts +0 -3
  30. package/dist/util/fs.d.ts +9 -8
  31. package/dist/worker.js +1 -1
  32. package/package.json +7 -7
  33. /package/dist/{612.js → rslib-runtime-index.js} +0 -0
@@ -2,7 +2,7 @@
2
2
  /******/ "use strict";
3
3
  /******/ var __webpack_modules__ = ({
4
4
 
5
- /***/ 61:
5
+ /***/ 969:
6
6
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
7
7
 
8
8
  /*
@@ -12,14 +12,15 @@
12
12
 
13
13
 
14
14
 
15
- const Source = __nccwpck_require__(331);
16
- const streamAndGetSourceAndMap = __nccwpck_require__(439);
17
- const streamChunksOfRawSource = __nccwpck_require__(300);
18
- const streamChunksOfSourceMap = __nccwpck_require__(814);
15
+ const Source = __nccwpck_require__(143);
16
+ const streamAndGetSourceAndMap = __nccwpck_require__(579);
17
+ const streamChunksOfRawSource = __nccwpck_require__(824);
18
+ const streamChunksOfSourceMap = __nccwpck_require__(938);
19
19
  const {
20
20
  isDualStringBufferCachingEnabled,
21
- } = __nccwpck_require__(806);
21
+ } = __nccwpck_require__(386);
22
22
 
23
+ /** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */
23
24
  /** @typedef {import("./Source").HashLike} HashLike */
24
25
  /** @typedef {import("./Source").MapOptions} MapOptions */
25
26
  /** @typedef {import("./Source").RawSourceMap} RawSourceMap */
@@ -85,6 +86,34 @@ const bufferedMapToMap = (bufferedMap) => {
85
86
  /** @typedef {{ map?: null | RawSourceMap, bufferedMap?: null | BufferedMap }} BufferEntry */
86
87
  /** @typedef {Map<string, BufferEntry>} BufferedMaps */
87
88
 
89
+ const CACHE_KEY_EMPTY = "{}";
90
+ const CACHE_KEY_COLUMNS_FALSE = '{"columns":false}';
91
+ const CACHE_KEY_COLUMNS_TRUE = '{"columns":true}';
92
+
93
+ /**
94
+ * Fast-path replacement for `JSON.stringify(options)` when used as a cache
95
+ * key. MapOptions / streamChunks Options are both small boolean-only shapes
96
+ * and the overwhelmingly common shapes (`undefined`, `{}`, `{columns}`) can
97
+ * be keyed without calling `JSON.stringify`, which dominates short-circuit
98
+ * cache lookups. Falls back to `JSON.stringify` for any other shape so keys
99
+ * remain compatible with previously cached `BufferedMaps` entries.
100
+ * @param {undefined | MapOptions | Options} options options
101
+ * @returns {string} cache key
102
+ */
103
+ const getCacheKey = (options) => {
104
+ if (!options) return CACHE_KEY_EMPTY;
105
+ const { columns } = options;
106
+ if (
107
+ /** @type {Options} */ (options).source === undefined &&
108
+ /** @type {Options} */ (options).finalSource === undefined &&
109
+ /** @type {MapOptions} */ (options).module === undefined
110
+ ) {
111
+ if (columns === undefined) return CACHE_KEY_EMPTY;
112
+ return columns ? CACHE_KEY_COLUMNS_TRUE : CACHE_KEY_COLUMNS_FALSE;
113
+ }
114
+ return JSON.stringify(options);
115
+ };
116
+
88
117
  /**
89
118
  * @typedef {object} CachedData
90
119
  * @property {boolean=} source source
@@ -106,36 +135,48 @@ class CachedSource extends Source {
106
135
  * @type {Source | (() => Source)}
107
136
  */
108
137
  this._source = source;
109
- /**
110
- * @private
111
- * @type {boolean | undefined}
112
- */
113
- this._cachedSourceType = cachedData ? cachedData.source : undefined;
114
138
  /**
115
139
  * @private
116
140
  * @type {undefined | string}
117
141
  */
118
142
  this._cachedSource = undefined;
119
- /**
120
- * @private
121
- * @type {Buffer | undefined}
122
- */
123
- this._cachedBuffer = cachedData ? cachedData.buffer : undefined;
124
- /**
125
- * @private
126
- * @type {number | undefined}
127
- */
128
- this._cachedSize = cachedData ? cachedData.size : undefined;
129
- /**
130
- * @private
131
- * @type {BufferedMaps}
132
- */
133
- this._cachedMaps = cachedData ? cachedData.maps : new Map();
134
- /**
135
- * @private
136
- * @type {(string | Buffer)[] | undefined}
137
- */
138
- this._cachedHashUpdate = cachedData ? cachedData.hash : undefined;
143
+ // Split on `cachedData` once instead of re-evaluating the ternary for
144
+ // every field. Under the interpreter (and CodSpeed's simulation) each
145
+ // ternary is a separate branch; consolidating cuts the per-instance
146
+ // branch count roughly in half.
147
+ if (cachedData) {
148
+ /**
149
+ * @private
150
+ * @type {boolean | undefined}
151
+ */
152
+ this._cachedSourceType = cachedData.source;
153
+ /**
154
+ * @private
155
+ * @type {Buffer | undefined}
156
+ */
157
+ this._cachedBuffer = cachedData.buffer;
158
+ /**
159
+ * @private
160
+ * @type {number | undefined}
161
+ */
162
+ this._cachedSize = cachedData.size;
163
+ /**
164
+ * @private
165
+ * @type {BufferedMaps}
166
+ */
167
+ this._cachedMaps = cachedData.maps;
168
+ /**
169
+ * @private
170
+ * @type {(string | Buffer)[] | undefined}
171
+ */
172
+ this._cachedHashUpdate = cachedData.hash;
173
+ } else {
174
+ this._cachedSourceType = undefined;
175
+ this._cachedBuffer = undefined;
176
+ this._cachedSize = undefined;
177
+ this._cachedMaps = new Map();
178
+ this._cachedHashUpdate = undefined;
179
+ }
139
180
  }
140
181
 
141
182
  /**
@@ -157,13 +198,14 @@ class CachedSource extends Source {
157
198
  });
158
199
  }
159
200
  return {
160
- // We don't want to cache strings
161
- // So if we have a caches sources
162
- // create a buffer from it and only store
163
- // if it was a Buffer or string
164
- buffer: this._cachedSource
165
- ? this.buffer()
166
- : /** @type {Buffer} */ (this._cachedBuffer),
201
+ // `CachedData.buffer` is required (it is the on-disk
202
+ // serialization format consumed by the
203
+ // `new CachedSource(source, cachedData)` constructor).
204
+ // `_cachedBuffer` is populated by `buffer()` calls but a
205
+ // caller may invoke `getCachedData()` after `clearCache()`
206
+ // has dropped it; `this.buffer()` rehydrates via the
207
+ // wrapped source so the contract holds in every state.
208
+ buffer: this.buffer(),
167
209
  source:
168
210
  this._cachedSourceType !== undefined
169
211
  ? this._cachedSourceType
@@ -191,8 +233,21 @@ class CachedSource extends Source {
191
233
  * @returns {SourceValue} source
192
234
  */
193
235
  source() {
194
- const source = this._getCachedSource();
195
- if (source !== undefined) return source;
236
+ // Fully inlined _getCachedSource: both warm- and cold-cache paths skip
237
+ // the prototype method lookup / stack frame the interpreter would
238
+ // otherwise pay on every call.
239
+ if (this._cachedSource !== undefined) return this._cachedSource;
240
+ const cachedBuffer = this._cachedBuffer;
241
+ const cachedSourceType = this._cachedSourceType;
242
+ if (cachedBuffer !== undefined && cachedSourceType !== undefined) {
243
+ const value = cachedSourceType
244
+ ? cachedBuffer.toString("utf8")
245
+ : cachedBuffer;
246
+ if (isDualStringBufferCachingEnabled()) {
247
+ this._cachedSource = /** @type {string} */ (value);
248
+ }
249
+ return /** @type {string} */ (value);
250
+ }
196
251
  return (this._cachedSource =
197
252
  /** @type {string} */
198
253
  (this.original().source()));
@@ -235,6 +290,9 @@ class CachedSource extends Source {
235
290
  */
236
291
  buffer() {
237
292
  if (this._cachedBuffer !== undefined) return this._cachedBuffer;
293
+ if (this._cachedBuffers !== undefined) {
294
+ return (this._cachedBuffer = Buffer.concat(this._cachedBuffers));
295
+ }
238
296
  if (this._cachedSource !== undefined) {
239
297
  const value = Buffer.isBuffer(this._cachedSource)
240
298
  ? this._cachedSource
@@ -258,6 +316,21 @@ class CachedSource extends Source {
258
316
  return value;
259
317
  }
260
318
 
319
+ /**
320
+ * @returns {Buffer[]} buffers
321
+ */
322
+ buffers() {
323
+ if (this._cachedBuffers !== undefined) return this._cachedBuffers;
324
+ if (this._cachedBuffer !== undefined) {
325
+ return (this._cachedBuffers = [this._cachedBuffer]);
326
+ }
327
+ const original = this.original();
328
+ if (typeof original.buffers === "function") {
329
+ return (this._cachedBuffers = original.buffers());
330
+ }
331
+ return (this._cachedBuffers = [this.buffer()]);
332
+ }
333
+
261
334
  /**
262
335
  * @returns {number} size
263
336
  */
@@ -278,7 +351,7 @@ class CachedSource extends Source {
278
351
  * @returns {SourceAndMap} source and map
279
352
  */
280
353
  sourceAndMap(options) {
281
- const key = options ? JSON.stringify(options) : "{}";
354
+ const key = getCacheKey(options);
282
355
  const cacheEntry = this._cachedMaps.get(key);
283
356
  // Look for a cached map
284
357
  if (cacheEntry !== undefined) {
@@ -316,7 +389,7 @@ class CachedSource extends Source {
316
389
  * @returns {GeneratedSourceInfo} generated source info
317
390
  */
318
391
  streamChunks(options, onChunk, onSource, onName) {
319
- const key = options ? JSON.stringify(options) : "{}";
392
+ const key = getCacheKey(options);
320
393
  if (
321
394
  this._cachedMaps.has(key) &&
322
395
  (this._cachedBuffer !== undefined || this._cachedSource !== undefined)
@@ -363,7 +436,7 @@ class CachedSource extends Source {
363
436
  * @returns {RawSourceMap | null} map
364
437
  */
365
438
  map(options) {
366
- const key = options ? JSON.stringify(options) : "{}";
439
+ const key = getCacheKey(options);
367
440
  const cacheEntry = this._cachedMaps.get(key);
368
441
  if (cacheEntry !== undefined) {
369
442
  return this._getMapFromCacheEntry(cacheEntry);
@@ -376,6 +449,45 @@ class CachedSource extends Source {
376
449
  return map;
377
450
  }
378
451
 
452
+ /**
453
+ * Release cached data held by this source. clearCache is a memory
454
+ * hint: it never affects correctness or output, only how expensive
455
+ * the next read is. Subclasses override; the base is a no-op so
456
+ * every Source supports the call. Composite sources always recurse
457
+ * into wrapped sources. When the same child is reachable via several
458
+ * parents (e.g. modules shared across webpack chunks), pass a shared
459
+ * `visited` WeakSet so each subtree is walked at most once.
460
+ * Not safe to call concurrently with source/map/sourceAndMap/
461
+ * streamChunks/updateHash on the same instance.
462
+ * @param {ClearCacheOptions=} options selectors
463
+ * @param {WeakSet<Source>=} visited de-duplication set shared across calls
464
+ * @returns {void}
465
+ */
466
+ clearCache(options, visited) {
467
+ if (visited !== undefined && visited.has(this)) return;
468
+ const clearSource = !options || options.source !== false;
469
+ const clearMaps = !options || options.maps !== false;
470
+ if (clearSource) {
471
+ this._cachedSource = undefined;
472
+ this._cachedSourceType = undefined;
473
+ this._cachedBuffer = undefined;
474
+ this._cachedBuffers = undefined;
475
+ }
476
+ if (clearMaps) {
477
+ // Reusing the Map avoids per-call allocation churn when builds
478
+ // call clearCache thousands of times.
479
+ this._cachedMaps.clear();
480
+ }
481
+ if (typeof this._source !== "function") {
482
+ let v = visited;
483
+ if (v === undefined) v = new WeakSet();
484
+ v.add(this);
485
+ this._source.clearCache(options, v);
486
+ } else if (visited !== undefined) {
487
+ visited.add(this);
488
+ }
489
+ }
490
+
379
491
  /**
380
492
  * @param {HashLike} hash hash
381
493
  * @returns {void}
@@ -428,7 +540,7 @@ module.exports = CachedSource;
428
540
 
429
541
  /***/ }),
430
542
 
431
- /***/ 961:
543
+ /***/ 589:
432
544
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
433
545
 
434
546
  /*
@@ -438,8 +550,9 @@ module.exports = CachedSource;
438
550
 
439
551
 
440
552
 
441
- const Source = __nccwpck_require__(331);
553
+ const Source = __nccwpck_require__(143);
442
554
 
555
+ /** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */
443
556
  /** @typedef {import("./Source").HashLike} HashLike */
444
557
  /** @typedef {import("./Source").MapOptions} MapOptions */
445
558
  /** @typedef {import("./Source").RawSourceMap} RawSourceMap */
@@ -450,10 +563,12 @@ const Source = __nccwpck_require__(331);
450
563
  * @typedef {object} SourceLike
451
564
  * @property {() => SourceValue} source source
452
565
  * @property {(() => Buffer)=} buffer buffer
566
+ * @property {(() => Buffer[])=} buffers buffers
453
567
  * @property {(() => number)=} size size
454
568
  * @property {((options?: MapOptions) => RawSourceMap | null)=} map map
455
569
  * @property {((options?: MapOptions) => SourceAndMap)=} sourceAndMap source and map
456
570
  * @property {((hash: HashLike) => void)=} updateHash hash updater
571
+ * @property {((options?: ClearCacheOptions, visited?: WeakSet<Source>) => void)=} clearCache clear cache
457
572
  */
458
573
 
459
574
  class CompatSource extends Source {
@@ -486,6 +601,9 @@ class CompatSource extends Source {
486
601
  return this._sourceLike.source();
487
602
  }
488
603
 
604
+ /**
605
+ * @returns {Buffer} buffer
606
+ */
489
607
  buffer() {
490
608
  if (typeof this._sourceLike.buffer === "function") {
491
609
  return this._sourceLike.buffer();
@@ -493,6 +611,19 @@ class CompatSource extends Source {
493
611
  return super.buffer();
494
612
  }
495
613
 
614
+ /**
615
+ * @returns {Buffer[]} buffers
616
+ */
617
+ buffers() {
618
+ if (typeof this._sourceLike.buffers === "function") {
619
+ return this._sourceLike.buffers();
620
+ }
621
+ return super.buffers();
622
+ }
623
+
624
+ /**
625
+ * @returns {number} size
626
+ */
496
627
  size() {
497
628
  if (typeof this._sourceLike.size === "function") {
498
629
  return this._sourceLike.size();
@@ -522,6 +653,29 @@ class CompatSource extends Source {
522
653
  return super.sourceAndMap(options);
523
654
  }
524
655
 
656
+ /**
657
+ * Release cached data held by this source. clearCache is a memory
658
+ * hint: it never affects correctness or output, only how expensive
659
+ * the next read is. Subclasses override; the base is a no-op so
660
+ * every Source supports the call. Composite sources always recurse
661
+ * into wrapped sources. When the same child is reachable via several
662
+ * parents (e.g. modules shared across webpack chunks), pass a shared
663
+ * `visited` WeakSet so each subtree is walked at most once.
664
+ * Not safe to call concurrently with source/map/sourceAndMap/
665
+ * streamChunks/updateHash on the same instance.
666
+ * @param {ClearCacheOptions=} options selectors
667
+ * @param {WeakSet<Source>=} visited de-duplication set shared across calls
668
+ * @returns {void}
669
+ */
670
+ clearCache(options, visited) {
671
+ if (visited !== undefined && visited.has(this)) return;
672
+ if (visited !== undefined) visited.add(this);
673
+ const sourceLike = this._sourceLike;
674
+ if (typeof sourceLike.clearCache === "function") {
675
+ sourceLike.clearCache(options, visited);
676
+ }
677
+ }
678
+
525
679
  /**
526
680
  * @param {HashLike} hash hash
527
681
  * @returns {void}
@@ -544,7 +698,7 @@ module.exports = CompatSource;
544
698
 
545
699
  /***/ }),
546
700
 
547
- /***/ 523:
701
+ /***/ 415:
548
702
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
549
703
 
550
704
  /*
@@ -554,12 +708,13 @@ module.exports = CompatSource;
554
708
 
555
709
 
556
710
 
557
- const RawSource = __nccwpck_require__(855);
558
- const Source = __nccwpck_require__(331);
559
- const { getMap, getSourceAndMap } = __nccwpck_require__(568);
560
- const streamChunks = __nccwpck_require__(786);
711
+ const RawSource = __nccwpck_require__(371);
712
+ const Source = __nccwpck_require__(143);
713
+ const { getMap, getSourceAndMap } = __nccwpck_require__(468);
714
+ const streamChunks = __nccwpck_require__(750);
561
715
 
562
716
  /** @typedef {import("./CompatSource").SourceLike} SourceLike */
717
+ /** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */
563
718
  /** @typedef {import("./Source").HashLike} HashLike */
564
719
  /** @typedef {import("./Source").MapOptions} MapOptions */
565
720
  /** @typedef {import("./Source").RawSourceMap} RawSourceMap */
@@ -587,10 +742,15 @@ class ConcatSource extends Source {
587
742
  */
588
743
  this._children = [];
589
744
 
590
- for (const item of args) {
745
+ // Indexed loops avoid the iterator-protocol overhead `for...of`
746
+ // pays per element. Hot during webpack's emit when many
747
+ // ConcatSources are constructed/flattened.
748
+ for (let i = 0, l = args.length; i < l; i++) {
749
+ const item = args[i];
591
750
  if (item instanceof ConcatSource) {
592
- for (const child of item._children) {
593
- this._children.push(child);
751
+ const children = item._children;
752
+ for (let j = 0, jl = children.length; j < jl; j++) {
753
+ this._children.push(children[j]);
594
754
  }
595
755
  } else {
596
756
  this._children.push(item);
@@ -618,8 +778,9 @@ class ConcatSource extends Source {
618
778
  */
619
779
  add(item) {
620
780
  if (item instanceof ConcatSource) {
621
- for (const child of item._children) {
622
- this._children.push(child);
781
+ const children = item._children;
782
+ for (let i = 0, l = children.length; i < l; i++) {
783
+ this._children.push(children[i]);
623
784
  }
624
785
  } else {
625
786
  this._children.push(item);
@@ -632,17 +793,38 @@ class ConcatSource extends Source {
632
793
  * @returns {void}
633
794
  */
634
795
  addAllSkipOptimizing(items) {
635
- for (const item of items) {
636
- this._children.push(item);
796
+ for (let i = 0, l = items.length; i < l; i++) {
797
+ this._children.push(items[i]);
637
798
  }
638
799
  }
639
800
 
801
+ /**
802
+ * @returns {Buffer} buffer
803
+ */
640
804
  buffer() {
805
+ return Buffer.concat(this.buffers());
806
+ }
807
+
808
+ /**
809
+ * @returns {Buffer[]} buffers
810
+ */
811
+ buffers() {
641
812
  if (!this._isOptimized) this._optimize();
813
+ const children = /** @type {SourceLike[]} */ (this._children);
814
+ const childCount = children.length;
642
815
  /** @type {Buffer[]} */
643
816
  const buffers = [];
644
- for (const child of /** @type {SourceLike[]} */ (this._children)) {
645
- if (typeof child.buffer === "function") {
817
+ // Indexed loop + manual splat avoids the iterator allocation per
818
+ // child and the inner for-of allocation per child.buffers() call.
819
+ // Hot path during webpack's emit on deeply-nested ConcatSources.
820
+ for (let ci = 0; ci < childCount; ci++) {
821
+ const child = children[ci];
822
+ if (typeof child.buffers === "function") {
823
+ const childBuffers = child.buffers();
824
+ for (let bi = 0, blen = childBuffers.length; bi < blen; bi++) {
825
+ buffers.push(childBuffers[bi]);
826
+ }
827
+ } else if (typeof child.buffer === "function") {
646
828
  buffers.push(child.buffer());
647
829
  } else {
648
830
  const bufferOrString = child.source();
@@ -654,7 +836,7 @@ class ConcatSource extends Source {
654
836
  }
655
837
  }
656
838
  }
657
- return Buffer.concat(buffers);
839
+ return buffers;
658
840
  }
659
841
 
660
842
  /**
@@ -662,18 +844,25 @@ class ConcatSource extends Source {
662
844
  */
663
845
  source() {
664
846
  if (!this._isOptimized) this._optimize();
847
+ const children = /** @type {Source[]} */ (this._children);
848
+ const childCount = children.length;
665
849
  let source = "";
666
- for (const child of this._children) {
667
- source += /** @type {Source} */ (child).source();
850
+ for (let ci = 0; ci < childCount; ci++) {
851
+ source += children[ci].source();
668
852
  }
669
853
  return source;
670
854
  }
671
855
 
856
+ /**
857
+ * @returns {number} size
858
+ */
672
859
  size() {
673
860
  if (!this._isOptimized) this._optimize();
861
+ const children = /** @type {Source[]} */ (this._children);
862
+ const childCount = children.length;
674
863
  let size = 0;
675
- for (const child of this._children) {
676
- size += /** @type {Source} */ (child).size();
864
+ for (let ci = 0; ci < childCount; ci++) {
865
+ size += children[ci].size();
677
866
  }
678
867
  return size;
679
868
  }
@@ -718,7 +907,10 @@ class ConcatSource extends Source {
718
907
  const finalSource = Boolean(options && options.finalSource);
719
908
  let code = "";
720
909
  let needToCloseMapping = false;
721
- for (const item of /** @type {Source[]} */ (this._children)) {
910
+ const children = /** @type {Source[]} */ (this._children);
911
+ const childCount = children.length;
912
+ for (let ci = 0; ci < childCount; ci++) {
913
+ const item = children[ci];
722
914
  /** @type {number[]} */
723
915
  const sourceIndexMapping = [];
724
916
  /** @type {number[]} */
@@ -760,11 +952,6 @@ class ConcatSource extends Source {
760
952
  sourceIndex < 0 || sourceIndex >= sourceIndexMapping.length
761
953
  ? -1
762
954
  : sourceIndexMapping[sourceIndex];
763
- const resultNameIndex =
764
- nameIndex < 0 || nameIndex >= nameIndexMapping.length
765
- ? -1
766
- : nameIndexMapping[nameIndex];
767
- lastMappingLine = resultSourceIndex < 0 ? 0 : generatedLine;
768
955
  let _chunk;
769
956
  // When using finalSource, we process the entire source code at once at the end, rather than chunk by chunk
770
957
  if (finalSource) {
@@ -773,8 +960,17 @@ class ConcatSource extends Source {
773
960
  _chunk = chunk;
774
961
  }
775
962
  if (resultSourceIndex < 0) {
963
+ lastMappingLine = 0;
776
964
  onChunk(_chunk, line, column, -1, -1, -1, -1);
777
965
  } else {
966
+ // Only compute the remapped name index when the chunk
967
+ // actually carries a source mapping; otherwise it is
968
+ // unused.
969
+ const resultNameIndex =
970
+ nameIndex < 0 || nameIndex >= nameIndexMapping.length
971
+ ? -1
972
+ : nameIndexMapping[nameIndex];
973
+ lastMappingLine = generatedLine;
778
974
  onChunk(
779
975
  _chunk,
780
976
  line,
@@ -836,16 +1032,46 @@ class ConcatSource extends Source {
836
1032
  };
837
1033
  }
838
1034
 
1035
+ /**
1036
+ * Release cached data held by this source. clearCache is a memory
1037
+ * hint: it never affects correctness or output, only how expensive
1038
+ * the next read is. Subclasses override; the base is a no-op so
1039
+ * every Source supports the call. Composite sources always recurse
1040
+ * into wrapped sources. When the same child is reachable via several
1041
+ * parents (e.g. modules shared across webpack chunks), pass a shared
1042
+ * `visited` WeakSet so each subtree is walked at most once.
1043
+ * Not safe to call concurrently with source/map/sourceAndMap/
1044
+ * streamChunks/updateHash on the same instance.
1045
+ * @param {ClearCacheOptions=} options selectors
1046
+ * @param {WeakSet<Source>=} visited de-duplication set shared across calls
1047
+ * @returns {void}
1048
+ */
1049
+ clearCache(options, visited) {
1050
+ if (visited !== undefined && visited.has(this)) return;
1051
+ const children = this._children;
1052
+ const { length } = children;
1053
+ let v = visited;
1054
+ if (v === undefined && length > 0) v = new WeakSet();
1055
+ if (v !== undefined) v.add(this);
1056
+ for (let i = 0; i < length; i++) {
1057
+ const child = children[i];
1058
+ if (typeof child !== "string" && typeof child.clearCache === "function") {
1059
+ child.clearCache(options, v);
1060
+ }
1061
+ }
1062
+ }
1063
+
839
1064
  /**
840
1065
  * @param {HashLike} hash hash
841
1066
  * @returns {void}
842
1067
  */
843
1068
  updateHash(hash) {
844
1069
  if (!this._isOptimized) this._optimize();
1070
+ const children = /** @type {Source[]} */ (this._children);
1071
+ const childCount = children.length;
845
1072
  hash.update("ConcatSource");
846
- for (const item of this._children) {
847
- /** @type {Source} */
848
- (item).updateHash(hash);
1073
+ for (let ci = 0; ci < childCount; ci++) {
1074
+ children[ci].updateHash(hash);
849
1075
  }
850
1076
  }
851
1077
 
@@ -907,7 +1133,9 @@ class ConcatSource extends Source {
907
1133
  newChildren.push(currentRawSources);
908
1134
  }
909
1135
  };
910
- for (const child of this._children) {
1136
+ const children = this._children;
1137
+ for (let ci = 0, cl = children.length; ci < cl; ci++) {
1138
+ const child = children[ci];
911
1139
  if (typeof child === "string") {
912
1140
  if (currentString === undefined) {
913
1141
  currentString = child;
@@ -949,7 +1177,7 @@ module.exports = ConcatSource;
949
1177
 
950
1178
  /***/ }),
951
1179
 
952
- /***/ 792:
1180
+ /***/ 924:
953
1181
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
954
1182
 
955
1183
  /*
@@ -959,15 +1187,15 @@ module.exports = ConcatSource;
959
1187
 
960
1188
 
961
1189
 
962
- const Source = __nccwpck_require__(331);
963
- const { getMap, getSourceAndMap } = __nccwpck_require__(568);
964
- const getGeneratedSourceInfo = __nccwpck_require__(784);
965
- const splitIntoLines = __nccwpck_require__(509);
966
- const splitIntoPotentialTokens = __nccwpck_require__(674);
1190
+ const Source = __nccwpck_require__(143);
1191
+ const { getMap, getSourceAndMap } = __nccwpck_require__(468);
1192
+ const getGeneratedSourceInfo = __nccwpck_require__(724);
1193
+ const splitIntoPotentialTokens = __nccwpck_require__(574);
967
1194
  const {
968
1195
  isDualStringBufferCachingEnabled,
969
- } = __nccwpck_require__(806);
1196
+ } = __nccwpck_require__(386);
970
1197
 
1198
+ /** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */
971
1199
  /** @typedef {import("./Source").HashLike} HashLike */
972
1200
  /** @typedef {import("./Source").MapOptions} MapOptions */
973
1201
  /** @typedef {import("./Source").RawSourceMap} RawSourceMap */
@@ -1026,6 +1254,9 @@ class OriginalSource extends Source {
1026
1254
  return this._value;
1027
1255
  }
1028
1256
 
1257
+ /**
1258
+ * @returns {Buffer} buffer
1259
+ */
1029
1260
  buffer() {
1030
1261
  if (this._valueAsBuffer === undefined) {
1031
1262
  const value = Buffer.from(/** @type {string} */ (this._value), "utf8");
@@ -1037,6 +1268,20 @@ class OriginalSource extends Source {
1037
1268
  return this._valueAsBuffer;
1038
1269
  }
1039
1270
 
1271
+ /**
1272
+ * @returns {number} size
1273
+ */
1274
+ size() {
1275
+ if (this._cachedSize !== undefined) return this._cachedSize;
1276
+ if (this._valueAsBuffer !== undefined) {
1277
+ return (this._cachedSize = this._valueAsBuffer.length);
1278
+ }
1279
+ return (this._cachedSize = Buffer.byteLength(
1280
+ /** @type {string} */ (this._value),
1281
+ "utf8",
1282
+ ));
1283
+ }
1284
+
1040
1285
  /**
1041
1286
  * @param {MapOptions=} options map options
1042
1287
  * @returns {RawSourceMap | null} map
@@ -1119,27 +1364,64 @@ class OriginalSource extends Source {
1119
1364
  }
1120
1365
  return result;
1121
1366
  }
1122
- // Without column info, but also without final source
1123
- // we need to split source by lines
1367
+ // Without column info, but also without final source.
1368
+ // We only get here when (options.columns === false && !finalSource),
1369
+ // so the source field is always undefined and the chunk arg is always
1370
+ // the line text. Single-pass scan over newlines avoids the
1371
+ // splitIntoLines array allocation.
1372
+ const value = this._value;
1373
+ const len = value.length;
1374
+ if (len === 0) {
1375
+ return { generatedLine: 1, generatedColumn: 0, source: undefined };
1376
+ }
1124
1377
  let line = 1;
1125
- const matches = splitIntoLines(this._value);
1126
- /** @type {string | undefined} */
1127
- let match;
1128
- for (match of matches) {
1129
- onChunk(finalSource ? undefined : match, line, 0, 0, line, 0, -1);
1378
+ let i = 0;
1379
+ while (i < len) {
1380
+ const n = value.indexOf("\n", i);
1381
+ if (n === -1) {
1382
+ const lastLine = i === 0 ? value : value.slice(i);
1383
+ onChunk(lastLine, line, 0, 0, line, 0, -1);
1384
+ return {
1385
+ generatedLine: line,
1386
+ generatedColumn: lastLine.length,
1387
+ source: undefined,
1388
+ };
1389
+ }
1390
+ const chunk = n === i ? "\n" : value.slice(i, n + 1);
1391
+ onChunk(chunk, line, 0, 0, line, 0, -1);
1130
1392
  line++;
1393
+ i = n + 1;
1394
+ }
1395
+ // Source ended with a newline.
1396
+ return { generatedLine: line, generatedColumn: 0, source: undefined };
1397
+ }
1398
+
1399
+ /**
1400
+ * Release cached data held by this source. clearCache is a memory
1401
+ * hint: it never affects correctness or output, only how expensive
1402
+ * the next read is. Subclasses override; the base is a no-op so
1403
+ * every Source supports the call. Composite sources always recurse
1404
+ * into wrapped sources. When the same child is reachable via several
1405
+ * parents (e.g. modules shared across webpack chunks), pass a shared
1406
+ * `visited` WeakSet so each subtree is walked at most once.
1407
+ * Not safe to call concurrently with source/map/sourceAndMap/
1408
+ * streamChunks/updateHash on the same instance.
1409
+ * @param {ClearCacheOptions=} options selectors
1410
+ * @param {WeakSet<Source>=} visited de-duplication set shared across calls
1411
+ * @returns {void}
1412
+ */
1413
+ clearCache(options, visited) {
1414
+ if (visited !== undefined) {
1415
+ if (visited.has(this)) return;
1416
+ visited.add(this);
1417
+ }
1418
+ if (options !== undefined && options.source === false) return;
1419
+ if (this._value !== undefined && this._valueAsBuffer !== undefined) {
1420
+ // When both forms are cached, drop the string (UTF-16 in V8 is
1421
+ // ~2 bytes/char) and keep the more compact buffer. source() will
1422
+ // rehydrate the string on demand.
1423
+ this._value = undefined;
1131
1424
  }
1132
- return matches.length === 0 || /** @type {string} */ (match).endsWith("\n")
1133
- ? {
1134
- generatedLine: matches.length + 1,
1135
- generatedColumn: 0,
1136
- source: finalSource ? this._value : undefined,
1137
- }
1138
- : {
1139
- generatedLine: matches.length,
1140
- generatedColumn: /** @type {string} */ (match).length,
1141
- source: finalSource ? this._value : undefined,
1142
- };
1143
1425
  }
1144
1426
 
1145
1427
  /**
@@ -1158,7 +1440,7 @@ module.exports = OriginalSource;
1158
1440
 
1159
1441
  /***/ }),
1160
1442
 
1161
- /***/ 199:
1443
+ /***/ 11:
1162
1444
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
1163
1445
 
1164
1446
  /*
@@ -1168,11 +1450,12 @@ module.exports = OriginalSource;
1168
1450
 
1169
1451
 
1170
1452
 
1171
- const RawSource = __nccwpck_require__(855);
1172
- const Source = __nccwpck_require__(331);
1173
- const { getMap, getSourceAndMap } = __nccwpck_require__(568);
1174
- const streamChunks = __nccwpck_require__(786);
1453
+ const RawSource = __nccwpck_require__(371);
1454
+ const Source = __nccwpck_require__(143);
1455
+ const { getMap, getSourceAndMap } = __nccwpck_require__(468);
1456
+ const streamChunks = __nccwpck_require__(750);
1175
1457
 
1458
+ /** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */
1176
1459
  /** @typedef {import("./Source").HashLike} HashLike */
1177
1460
  /** @typedef {import("./Source").MapOptions} MapOptions */
1178
1461
  /** @typedef {import("./Source").RawSourceMap} RawSourceMap */
@@ -1184,7 +1467,31 @@ const streamChunks = __nccwpck_require__(786);
1184
1467
  /** @typedef {import("./helpers/streamChunks").OnSource} OnSource */
1185
1468
  /** @typedef {import("./helpers/streamChunks").Options} Options */
1186
1469
 
1187
- const REPLACE_REGEX = /\n(?=.|\s)/g;
1470
+ // `/\n/g` (no lookahead) lets V8's regex compiler take its
1471
+ // literal-character fast path; the previous `/\n(?=.|\s)/g` form
1472
+ // disabled it. Output stays identical because `buildPrefixed` strips
1473
+ // the spurious trailing prefix when the input ended with a newline.
1474
+ const NEWLINE_REGEX = /\n/g;
1475
+
1476
+ /**
1477
+ * Prepend `prefix` and insert `prefix` after every newline that has
1478
+ * content following — the original `/\n(?=.|\s)/g` semantics, but
1479
+ * implemented as a fast-path regex + tail-strip.
1480
+ * @param {string} prefix prefix
1481
+ * @param {string} node underlying source string
1482
+ * @returns {string} prefixed string
1483
+ */
1484
+ const buildPrefixed = (prefix, node) => {
1485
+ if (prefix.length === 0) return node;
1486
+ const replaced = node.replace(NEWLINE_REGEX, `\n${prefix}`);
1487
+ const len = node.length;
1488
+ // `/\n/g` matches the trailing newline too, so the replace appended
1489
+ // a spurious prefix at the end. Trim it.
1490
+ if (len > 0 && node.charCodeAt(len - 1) === 10) {
1491
+ return prefix + replaced.slice(0, replaced.length - prefix.length);
1492
+ }
1493
+ return prefix + replaced;
1494
+ };
1188
1495
 
1189
1496
  class PrefixSource extends Source {
1190
1497
  /**
@@ -1220,12 +1527,19 @@ class PrefixSource extends Source {
1220
1527
  * @returns {SourceValue} source
1221
1528
  */
1222
1529
  source() {
1223
- const node = /** @type {string} */ (this._source.source());
1224
- const prefix = this._prefix;
1225
- return prefix + node.replace(REPLACE_REGEX, `\n${prefix}`);
1530
+ return buildPrefixed(
1531
+ this._prefix,
1532
+ /** @type {string} */ (this._source.source()),
1533
+ );
1226
1534
  }
1227
1535
 
1228
- // TODO efficient buffer() implementation
1536
+ // buffer() / buffers() / size() inherit from Source.prototype.
1537
+ // Source.buffer() does Buffer.from(this.source(), "utf8") — cheaper
1538
+ // in CodSpeed instruction count than any safe override we tried
1539
+ // (caching is unsafe with mutable child; a JS-side splice loop
1540
+ // regressed ~5x in instruction count). Speeding up source() via the
1541
+ // simpler regex above lifts buffer(), buffers(), size(), and any
1542
+ // other `this.source()`-using path with no override needed.
1229
1543
 
1230
1544
  /**
1231
1545
  * @param {MapOptions=} options map options
@@ -1304,10 +1618,7 @@ class PrefixSource extends Source {
1304
1618
  generatedColumn === 0
1305
1619
  ? 0
1306
1620
  : prefixOffset + /** @type {number} */ (generatedColumn),
1307
- source:
1308
- source !== undefined
1309
- ? prefix + source.replace(REPLACE_REGEX, `\n${prefix}`)
1310
- : undefined,
1621
+ source: source !== undefined ? buildPrefixed(prefix, source) : undefined,
1311
1622
  };
1312
1623
  }
1313
1624
 
@@ -1320,6 +1631,28 @@ class PrefixSource extends Source {
1320
1631
  this._source.updateHash(hash);
1321
1632
  hash.update(this._prefix);
1322
1633
  }
1634
+
1635
+ /**
1636
+ * Release cached data held by this source. clearCache is a memory
1637
+ * hint: it never affects correctness or output, only how expensive
1638
+ * the next read is. Subclasses override; the base is a no-op so
1639
+ * every Source supports the call. Composite sources always recurse
1640
+ * into wrapped sources. When the same child is reachable via several
1641
+ * parents (e.g. modules shared across webpack chunks), pass a shared
1642
+ * `visited` WeakSet so each subtree is walked at most once.
1643
+ * Not safe to call concurrently with source/map/sourceAndMap/
1644
+ * streamChunks/updateHash on the same instance.
1645
+ * @param {ClearCacheOptions=} options selectors
1646
+ * @param {WeakSet<Source>=} visited de-duplication set shared across calls
1647
+ * @returns {void}
1648
+ */
1649
+ clearCache(options, visited) {
1650
+ if (visited !== undefined && visited.has(this)) return;
1651
+ let v = visited;
1652
+ if (v === undefined) v = new WeakSet();
1653
+ v.add(this);
1654
+ this._source.clearCache(options, v);
1655
+ }
1323
1656
  }
1324
1657
 
1325
1658
  module.exports = PrefixSource;
@@ -1327,7 +1660,7 @@ module.exports = PrefixSource;
1327
1660
 
1328
1661
  /***/ }),
1329
1662
 
1330
- /***/ 855:
1663
+ /***/ 371:
1331
1664
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
1332
1665
 
1333
1666
  /*
@@ -1337,13 +1670,14 @@ module.exports = PrefixSource;
1337
1670
 
1338
1671
 
1339
1672
 
1340
- const Source = __nccwpck_require__(331);
1341
- const streamChunksOfRawSource = __nccwpck_require__(300);
1673
+ const Source = __nccwpck_require__(143);
1674
+ const streamChunksOfRawSource = __nccwpck_require__(824);
1342
1675
  const {
1343
1676
  internString,
1344
1677
  isDualStringBufferCachingEnabled,
1345
- } = __nccwpck_require__(806);
1678
+ } = __nccwpck_require__(386);
1346
1679
 
1680
+ /** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */
1347
1681
  /** @typedef {import("./Source").HashLike} HashLike */
1348
1682
  /** @typedef {import("./Source").MapOptions} MapOptions */
1349
1683
  /** @typedef {import("./Source").RawSourceMap} RawSourceMap */
@@ -1362,36 +1696,36 @@ class RawSource extends Source {
1362
1696
  constructor(value, convertToString = false) {
1363
1697
  super();
1364
1698
  const isBuffer = Buffer.isBuffer(value);
1365
- if (!isBuffer && typeof value !== "string") {
1699
+ if (isBuffer) {
1700
+ /**
1701
+ * @private
1702
+ * @type {boolean}
1703
+ */
1704
+ this._valueIsBuffer = !convertToString;
1705
+ /**
1706
+ * @private
1707
+ * @type {undefined | string | Buffer}
1708
+ */
1709
+ this._value = convertToString ? undefined : value;
1710
+ /**
1711
+ * @private
1712
+ * @type {undefined | Buffer}
1713
+ */
1714
+ this._valueAsBuffer = value;
1715
+ /**
1716
+ * @private
1717
+ * @type {undefined | string}
1718
+ */
1719
+ this._valueAsString = undefined;
1720
+ } else if (typeof value === "string") {
1721
+ const interned = internString(value);
1722
+ this._valueIsBuffer = false;
1723
+ this._value = interned;
1724
+ this._valueAsBuffer = undefined;
1725
+ this._valueAsString = interned;
1726
+ } else {
1366
1727
  throw new TypeError("argument 'value' must be either string or Buffer");
1367
1728
  }
1368
- /**
1369
- * @private
1370
- * @type {boolean}
1371
- */
1372
- this._valueIsBuffer = !convertToString && isBuffer;
1373
- const internedString =
1374
- typeof value === "string" ? internString(value) : undefined;
1375
- /**
1376
- * @private
1377
- * @type {undefined | string | Buffer}
1378
- */
1379
- this._value =
1380
- convertToString && isBuffer
1381
- ? undefined
1382
- : typeof value === "string"
1383
- ? internedString
1384
- : value;
1385
- /**
1386
- * @private
1387
- * @type {undefined | Buffer}
1388
- */
1389
- this._valueAsBuffer = isBuffer ? value : undefined;
1390
- /**
1391
- * @private
1392
- * @type {undefined | string}
1393
- */
1394
- this._valueAsString = isBuffer ? undefined : internedString;
1395
1729
  }
1396
1730
 
1397
1731
  isBuffer() {
@@ -1414,6 +1748,9 @@ class RawSource extends Source {
1414
1748
  return this._value;
1415
1749
  }
1416
1750
 
1751
+ /**
1752
+ * @returns {Buffer} buffer
1753
+ */
1417
1754
  buffer() {
1418
1755
  if (this._valueAsBuffer === undefined) {
1419
1756
  const value = Buffer.from(/** @type {string} */ (this._value), "utf8");
@@ -1425,6 +1762,20 @@ class RawSource extends Source {
1425
1762
  return this._valueAsBuffer;
1426
1763
  }
1427
1764
 
1765
+ /**
1766
+ * @returns {number} size
1767
+ */
1768
+ size() {
1769
+ if (this._cachedSize !== undefined) return this._cachedSize;
1770
+ if (this._valueAsBuffer !== undefined) {
1771
+ return (this._cachedSize = this._valueAsBuffer.length);
1772
+ }
1773
+ return (this._cachedSize = Buffer.byteLength(
1774
+ /** @type {string} */ (this._valueAsString),
1775
+ "utf8",
1776
+ ));
1777
+ }
1778
+
1428
1779
  /**
1429
1780
  * @param {MapOptions=} options map options
1430
1781
  * @returns {RawSourceMap | null} map
@@ -1459,6 +1810,40 @@ class RawSource extends Source {
1459
1810
  );
1460
1811
  }
1461
1812
 
1813
+ /**
1814
+ * Release cached data held by this source. clearCache is a memory
1815
+ * hint: it never affects correctness or output, only how expensive
1816
+ * the next read is. Subclasses override; the base is a no-op so
1817
+ * every Source supports the call. Composite sources always recurse
1818
+ * into wrapped sources. When the same child is reachable via several
1819
+ * parents (e.g. modules shared across webpack chunks), pass a shared
1820
+ * `visited` WeakSet so each subtree is walked at most once.
1821
+ * Not safe to call concurrently with source/map/sourceAndMap/
1822
+ * streamChunks/updateHash on the same instance.
1823
+ * @param {ClearCacheOptions=} options selectors
1824
+ * @param {WeakSet<Source>=} visited de-duplication set shared across calls
1825
+ * @returns {void}
1826
+ */
1827
+ clearCache(options, visited) {
1828
+ if (visited !== undefined) {
1829
+ if (visited.has(this)) return;
1830
+ visited.add(this);
1831
+ }
1832
+ if (options !== undefined && options.source === false) return;
1833
+ if (this._valueIsBuffer) {
1834
+ // Buffer is the primary representation (and lives in `_value`);
1835
+ // only the string form, populated lazily by streamChunks, is
1836
+ // safe to drop.
1837
+ this._valueAsString = undefined;
1838
+ } else if (this._valueAsBuffer !== undefined && this._value !== undefined) {
1839
+ // The source was constructed from a string (so `_value` and
1840
+ // `_valueAsString` reference the same interned string) and the
1841
+ // buffer form was materialized later by `buffer()` /
1842
+ // `updateHash()`. The buffer is therefore safe to drop.
1843
+ this._valueAsBuffer = undefined;
1844
+ }
1845
+ }
1846
+
1462
1847
  /**
1463
1848
  * @param {HashLike} hash hash
1464
1849
  * @returns {void}
@@ -1474,7 +1859,7 @@ module.exports = RawSource;
1474
1859
 
1475
1860
  /***/ }),
1476
1861
 
1477
- /***/ 197:
1862
+ /***/ 753:
1478
1863
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
1479
1864
 
1480
1865
  /*
@@ -1484,11 +1869,12 @@ module.exports = RawSource;
1484
1869
 
1485
1870
 
1486
1871
 
1487
- const Source = __nccwpck_require__(331);
1488
- const { getMap, getSourceAndMap } = __nccwpck_require__(568);
1489
- const splitIntoLines = __nccwpck_require__(509);
1490
- const streamChunks = __nccwpck_require__(786);
1872
+ const Source = __nccwpck_require__(143);
1873
+ const { getMap, getSourceAndMap } = __nccwpck_require__(468);
1874
+ const splitIntoLines = __nccwpck_require__(409);
1875
+ const streamChunks = __nccwpck_require__(750);
1491
1876
 
1877
+ /** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */
1492
1878
  /** @typedef {import("./Source").HashLike} HashLike */
1493
1879
  /** @typedef {import("./Source").MapOptions} MapOptions */
1494
1880
  /** @typedef {import("./Source").RawSourceMap} RawSourceMap */
@@ -1510,6 +1896,35 @@ const hasStableSort =
1510
1896
  // This is larger than max string length
1511
1897
  const MAX_SOURCE_POSITION = 0x20000000;
1512
1898
 
1899
+ /**
1900
+ * Stable comparator hoisted to module scope so each `_sortReplacements()`
1901
+ * call doesn't allocate a fresh closure.
1902
+ * @param {Replacement} a a
1903
+ * @param {Replacement} b b
1904
+ * @returns {number} order
1905
+ */
1906
+ const compareStable = (a, b) => {
1907
+ const diff1 = a.start - b.start;
1908
+ if (diff1 !== 0) return diff1;
1909
+ const diff2 = a.end - b.end;
1910
+ if (diff2 !== 0) return diff2;
1911
+ return 0;
1912
+ };
1913
+
1914
+ /**
1915
+ * Index-stabilising comparator for v8 < 7.0 (pre-stable Array.prototype.sort).
1916
+ * @param {Replacement} a a
1917
+ * @param {Replacement} b b
1918
+ * @returns {number} order
1919
+ */
1920
+ const compareUnstableFallback = (a, b) => {
1921
+ const diff1 = a.start - b.start;
1922
+ if (diff1 !== 0) return diff1;
1923
+ const diff2 = a.end - b.end;
1924
+ if (diff2 !== 0) return diff2;
1925
+ return /** @type {number} */ (a.index) - /** @type {number} */ (b.index);
1926
+ };
1927
+
1513
1928
  class Replacement {
1514
1929
  /**
1515
1930
  * @param {number} start start
@@ -1603,7 +2018,7 @@ class ReplaceSource extends Source {
1603
2018
  if (this._replacements.length === 0) {
1604
2019
  return this._source.source();
1605
2020
  }
1606
- let current = this._source.source();
2021
+ const current = /** @type {string} */ (this._source.source());
1607
2022
  let pos = 0;
1608
2023
  const result = [];
1609
2024
 
@@ -1612,22 +2027,45 @@ class ReplaceSource extends Source {
1612
2027
  const start = Math.floor(replacement.start);
1613
2028
  const end = Math.floor(replacement.end + 1);
1614
2029
  if (pos < start) {
1615
- const offset = start - pos;
1616
- result.push(current.slice(0, offset));
1617
- current = current.slice(offset);
2030
+ // slice directly from the original string rather than repeatedly
2031
+ // producing smaller intermediate strings, which avoids O(n) copies.
2032
+ result.push(current.slice(pos, start));
1618
2033
  pos = start;
1619
2034
  }
1620
2035
  result.push(replacement.content);
1621
2036
  if (pos < end) {
1622
- const offset = end - pos;
1623
- current = current.slice(offset);
1624
2037
  pos = end;
1625
2038
  }
1626
2039
  }
1627
- result.push(current);
2040
+ if (pos < current.length) {
2041
+ result.push(pos === 0 ? current : current.slice(pos));
2042
+ }
1628
2043
  return result.join("");
1629
2044
  }
1630
2045
 
2046
+ /**
2047
+ * @returns {Buffer} buffer
2048
+ */
2049
+ buffer() {
2050
+ if (this._replacements.length === 0) {
2051
+ return this._source.buffer();
2052
+ }
2053
+ return super.buffer();
2054
+ }
2055
+
2056
+ /**
2057
+ * @returns {Buffer[]} buffers
2058
+ */
2059
+ buffers() {
2060
+ if (this._replacements.length === 0) {
2061
+ // TODO remove in the next major release
2062
+ return typeof this._source.buffers === "function"
2063
+ ? this._source.buffers()
2064
+ : [this._source.buffer()];
2065
+ }
2066
+ return [this.buffer()];
2067
+ }
2068
+
1631
2069
  /**
1632
2070
  * @param {MapOptions=} options map options
1633
2071
  * @returns {RawSourceMap | null} map
@@ -1657,24 +2095,10 @@ class ReplaceSource extends Source {
1657
2095
  _sortReplacements() {
1658
2096
  if (this._isSorted) return;
1659
2097
  if (hasStableSort) {
1660
- this._replacements.sort((a, b) => {
1661
- const diff1 = a.start - b.start;
1662
- if (diff1 !== 0) return diff1;
1663
- const diff2 = a.end - b.end;
1664
- if (diff2 !== 0) return diff2;
1665
- return 0;
1666
- });
2098
+ this._replacements.sort(compareStable);
1667
2099
  } else {
1668
2100
  for (const [i, repl] of this._replacements.entries()) repl.index = i;
1669
- this._replacements.sort((a, b) => {
1670
- const diff1 = a.start - b.start;
1671
- if (diff1 !== 0) return diff1;
1672
- const diff2 = a.end - b.end;
1673
- if (diff2 !== 0) return diff2;
1674
- return (
1675
- /** @type {number} */ (a.index) - /** @type {number} */ (b.index)
1676
- );
1677
- });
2101
+ this._replacements.sort(compareUnstableFallback);
1678
2102
  }
1679
2103
  this._isSorted = true;
1680
2104
  }
@@ -2015,6 +2439,28 @@ class ReplaceSource extends Source {
2015
2439
  };
2016
2440
  }
2017
2441
 
2442
+ /**
2443
+ * Release cached data held by this source. clearCache is a memory
2444
+ * hint: it never affects correctness or output, only how expensive
2445
+ * the next read is. Subclasses override; the base is a no-op so
2446
+ * every Source supports the call. Composite sources always recurse
2447
+ * into wrapped sources. When the same child is reachable via several
2448
+ * parents (e.g. modules shared across webpack chunks), pass a shared
2449
+ * `visited` WeakSet so each subtree is walked at most once.
2450
+ * Not safe to call concurrently with source/map/sourceAndMap/
2451
+ * streamChunks/updateHash on the same instance.
2452
+ * @param {ClearCacheOptions=} options selectors
2453
+ * @param {WeakSet<Source>=} visited de-duplication set shared across calls
2454
+ * @returns {void}
2455
+ */
2456
+ clearCache(options, visited) {
2457
+ if (visited !== undefined && visited.has(this)) return;
2458
+ let v = visited;
2459
+ if (v === undefined) v = new WeakSet();
2460
+ v.add(this);
2461
+ this._source.clearCache(options, v);
2462
+ }
2463
+
2018
2464
  /**
2019
2465
  * @param {HashLike} hash hash
2020
2466
  * @returns {void}
@@ -2024,10 +2470,14 @@ class ReplaceSource extends Source {
2024
2470
  hash.update("ReplaceSource");
2025
2471
  this._source.updateHash(hash);
2026
2472
  hash.update(this._name || "");
2473
+ // Feed each replacement as multiple updates instead of building one
2474
+ // combined template literal per replacement. The resulting digest is
2475
+ // identical (hash.update is additive over bytes), but we avoid
2476
+ // allocating a new string per replacement.
2027
2477
  for (const repl of this._replacements) {
2028
- hash.update(
2029
- `${repl.start}${repl.end}${repl.content}${repl.name ? repl.name : ""}`,
2030
- );
2478
+ hash.update(`${repl.start}${repl.end}`);
2479
+ hash.update(repl.content);
2480
+ if (repl.name) hash.update(repl.name);
2031
2481
  }
2032
2482
  }
2033
2483
  }
@@ -2038,7 +2488,7 @@ module.exports.Replacement = Replacement;
2038
2488
 
2039
2489
  /***/ }),
2040
2490
 
2041
- /***/ 628:
2491
+ /***/ 216:
2042
2492
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2043
2493
 
2044
2494
  /*
@@ -2048,7 +2498,7 @@ module.exports.Replacement = Replacement;
2048
2498
 
2049
2499
 
2050
2500
 
2051
- const Source = __nccwpck_require__(331);
2501
+ const Source = __nccwpck_require__(143);
2052
2502
 
2053
2503
  /** @typedef {import("./Source").HashLike} HashLike */
2054
2504
  /** @typedef {import("./Source").MapOptions} MapOptions */
@@ -2074,6 +2524,9 @@ class SizeOnlySource extends Source {
2074
2524
  );
2075
2525
  }
2076
2526
 
2527
+ /**
2528
+ * @returns {number} size
2529
+ */
2077
2530
  size() {
2078
2531
  return this._size;
2079
2532
  }
@@ -2092,6 +2545,13 @@ class SizeOnlySource extends Source {
2092
2545
  throw this._error();
2093
2546
  }
2094
2547
 
2548
+ /**
2549
+ * @returns {Buffer[]} buffers
2550
+ */
2551
+ buffers() {
2552
+ throw this._error();
2553
+ }
2554
+
2095
2555
  /**
2096
2556
  * @param {MapOptions=} options map options
2097
2557
  * @returns {RawSourceMap | null} map
@@ -2116,7 +2576,7 @@ module.exports = SizeOnlySource;
2116
2576
 
2117
2577
  /***/ }),
2118
2578
 
2119
- /***/ 331:
2579
+ /***/ 143:
2120
2580
  /***/ ((module) => {
2121
2581
 
2122
2582
  /*
@@ -2159,6 +2619,13 @@ module.exports = SizeOnlySource;
2159
2619
  * @property {(encoding?: string) => string | Buffer} digest get hash digest
2160
2620
  */
2161
2621
 
2622
+ /**
2623
+ * @typedef {object} ClearCacheOptions
2624
+ * @property {boolean=} maps drop cached source maps (default `true`)
2625
+ * @property {boolean=} source drop cached source/buffer copies (default `true`)
2626
+ * @property {boolean=} parsedMap drop the parsed object form of cached source maps on `SourceMapSource` instances (default `false` — re-parsing JSON is significantly more expensive than `toString`). Only takes effect when a serialized form (buffer or string) is also retained, so the data remains recoverable.
2627
+ */
2628
+
2162
2629
  class Source {
2163
2630
  /**
2164
2631
  * @returns {SourceValue} source
@@ -2167,12 +2634,25 @@ class Source {
2167
2634
  throw new Error("Abstract");
2168
2635
  }
2169
2636
 
2637
+ /**
2638
+ * @returns {Buffer} buffer
2639
+ */
2170
2640
  buffer() {
2171
2641
  const source = this.source();
2172
2642
  if (Buffer.isBuffer(source)) return source;
2173
2643
  return Buffer.from(source, "utf8");
2174
2644
  }
2175
2645
 
2646
+ /**
2647
+ * @returns {Buffer[]} buffers
2648
+ */
2649
+ buffers() {
2650
+ return [this.buffer()];
2651
+ }
2652
+
2653
+ /**
2654
+ * @returns {number} size
2655
+ */
2176
2656
  size() {
2177
2657
  return this.buffer().length;
2178
2658
  }
@@ -2205,6 +2685,23 @@ class Source {
2205
2685
  updateHash(hash) {
2206
2686
  throw new Error("Abstract");
2207
2687
  }
2688
+
2689
+ /**
2690
+ * Release cached data held by this source. clearCache is a memory
2691
+ * hint: it never affects correctness or output, only how expensive
2692
+ * the next read is. Subclasses override; the base is a no-op so
2693
+ * every Source supports the call. Composite sources always recurse
2694
+ * into wrapped sources. When the same child is reachable via several
2695
+ * parents (e.g. modules shared across webpack chunks), pass a shared
2696
+ * `visited` WeakSet so each subtree is walked at most once.
2697
+ * Not safe to call concurrently with source/map/sourceAndMap/
2698
+ * streamChunks/updateHash on the same instance.
2699
+ * @param {ClearCacheOptions=} options selectors
2700
+ * @param {WeakSet<Source>=} visited de-duplication set shared across calls
2701
+ * @returns {void}
2702
+ */
2703
+ // eslint-disable-next-line no-unused-vars
2704
+ clearCache(options, visited) {}
2208
2705
  }
2209
2706
 
2210
2707
  module.exports = Source;
@@ -2212,7 +2709,7 @@ module.exports = Source;
2212
2709
 
2213
2710
  /***/ }),
2214
2711
 
2215
- /***/ 476:
2712
+ /***/ 8:
2216
2713
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2217
2714
 
2218
2715
  /*
@@ -2222,14 +2719,15 @@ module.exports = Source;
2222
2719
 
2223
2720
 
2224
2721
 
2225
- const Source = __nccwpck_require__(331);
2226
- const { getMap, getSourceAndMap } = __nccwpck_require__(568);
2227
- const streamChunksOfCombinedSourceMap = __nccwpck_require__(647);
2228
- const streamChunksOfSourceMap = __nccwpck_require__(814);
2722
+ const Source = __nccwpck_require__(143);
2723
+ const { getMap, getSourceAndMap } = __nccwpck_require__(468);
2724
+ const streamChunksOfCombinedSourceMap = __nccwpck_require__(459);
2725
+ const streamChunksOfSourceMap = __nccwpck_require__(938);
2229
2726
  const {
2230
2727
  isDualStringBufferCachingEnabled,
2231
- } = __nccwpck_require__(806);
2728
+ } = __nccwpck_require__(386);
2232
2729
 
2730
+ /** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */
2233
2731
  /** @typedef {import("./Source").HashLike} HashLike */
2234
2732
  /** @typedef {import("./Source").MapOptions} MapOptions */
2235
2733
  /** @typedef {import("./Source").RawSourceMap} RawSourceMap */
@@ -2346,6 +2844,9 @@ class SourceMapSource extends Source {
2346
2844
  ];
2347
2845
  }
2348
2846
 
2847
+ /**
2848
+ * @returns {Buffer} buffer
2849
+ */
2349
2850
  buffer() {
2350
2851
  if (this._valueAsBuffer === undefined) {
2351
2852
  const value = Buffer.from(
@@ -2360,6 +2861,20 @@ class SourceMapSource extends Source {
2360
2861
  return this._valueAsBuffer;
2361
2862
  }
2362
2863
 
2864
+ /**
2865
+ * @returns {number} size
2866
+ */
2867
+ size() {
2868
+ if (this._cachedSize !== undefined) return this._cachedSize;
2869
+ if (this._valueAsBuffer !== undefined) {
2870
+ return (this._cachedSize = this._valueAsBuffer.length);
2871
+ }
2872
+ return (this._cachedSize = Buffer.byteLength(
2873
+ /** @type {string} */ (this._valueAsString),
2874
+ "utf8",
2875
+ ));
2876
+ }
2877
+
2363
2878
  /**
2364
2879
  * @returns {SourceValue} source
2365
2880
  */
@@ -2554,6 +3069,80 @@ class SourceMapSource extends Source {
2554
3069
  );
2555
3070
  }
2556
3071
 
3072
+ /**
3073
+ * Release cached data held by this source. clearCache is a memory
3074
+ * hint: it never affects correctness or output, only how expensive
3075
+ * the next read is. Subclasses override; the base is a no-op so
3076
+ * every Source supports the call. Composite sources always recurse
3077
+ * into wrapped sources. When the same child is reachable via several
3078
+ * parents (e.g. modules shared across webpack chunks), pass a shared
3079
+ * `visited` WeakSet so each subtree is walked at most once.
3080
+ * Not safe to call concurrently with source/map/sourceAndMap/
3081
+ * streamChunks/updateHash on the same instance.
3082
+ * @param {ClearCacheOptions=} options selectors
3083
+ * @param {WeakSet<Source>=} visited de-duplication set shared across calls
3084
+ * @returns {void}
3085
+ */
3086
+ clearCache(options, visited) {
3087
+ if (visited !== undefined) {
3088
+ if (visited.has(this)) return;
3089
+ visited.add(this);
3090
+ }
3091
+ const clearSource = !options || options.source !== false;
3092
+ const clearMaps = !options || options.maps !== false;
3093
+ const clearParsedMap = options !== undefined && options.parsedMap === true;
3094
+ // For every dual-cached pair, drop the string form when the
3095
+ // buffer is also held — buffer is more compact in V8 (1 byte/char
3096
+ // vs 2) and the string rehydrates cheaply. Parsed object forms
3097
+ // of source maps are heavier but only dropped when
3098
+ // `parsedMap: true` is set, because re-parsing JSON is much more
3099
+ // expensive than `toString` from a buffer.
3100
+ if (clearSource) {
3101
+ if (
3102
+ this._valueAsString !== undefined &&
3103
+ this._valueAsBuffer !== undefined
3104
+ ) {
3105
+ this._valueAsString = undefined;
3106
+ }
3107
+ if (
3108
+ this._originalSourceAsString !== undefined &&
3109
+ this._originalSourceAsBuffer !== undefined
3110
+ ) {
3111
+ this._originalSourceAsString = undefined;
3112
+ }
3113
+ }
3114
+ if (clearMaps) {
3115
+ if (
3116
+ this._sourceMapAsString !== undefined &&
3117
+ this._sourceMapAsBuffer !== undefined
3118
+ ) {
3119
+ this._sourceMapAsString = undefined;
3120
+ }
3121
+ if (
3122
+ clearParsedMap &&
3123
+ this._sourceMapAsObject !== undefined &&
3124
+ (this._sourceMapAsBuffer !== undefined ||
3125
+ this._sourceMapAsString !== undefined)
3126
+ ) {
3127
+ this._sourceMapAsObject = undefined;
3128
+ }
3129
+ if (
3130
+ this._innerSourceMapAsString !== undefined &&
3131
+ this._innerSourceMapAsBuffer !== undefined
3132
+ ) {
3133
+ this._innerSourceMapAsString = undefined;
3134
+ }
3135
+ if (
3136
+ clearParsedMap &&
3137
+ this._innerSourceMapAsObject !== undefined &&
3138
+ (this._innerSourceMapAsBuffer !== undefined ||
3139
+ this._innerSourceMapAsString !== undefined)
3140
+ ) {
3141
+ this._innerSourceMapAsObject = undefined;
3142
+ }
3143
+ }
3144
+ }
3145
+
2557
3146
  /**
2558
3147
  * @param {HashLike} hash hash
2559
3148
  * @returns {void}
@@ -2586,7 +3175,7 @@ module.exports = SourceMapSource;
2586
3175
 
2587
3176
  /***/ }),
2588
3177
 
2589
- /***/ 983:
3178
+ /***/ 859:
2590
3179
  /***/ ((module) => {
2591
3180
 
2592
3181
  /*
@@ -2613,6 +3202,29 @@ const ALPHABET = [
2613
3202
 
2614
3203
  const CONTINUATION_BIT = 0x20;
2615
3204
 
3205
+ /**
3206
+ * Append a VLQ-encoded signed integer to `str`. Hoisted to module scope so
3207
+ * that both serializers share a single function object and avoid allocating
3208
+ * a new closure on every call.
3209
+ * @param {string} str current string buffer
3210
+ * @param {number} value signed integer to encode
3211
+ * @returns {string} updated string buffer
3212
+ */
3213
+ const writeValue = (str, value) => {
3214
+ const sign = (value >>> 31) & 1;
3215
+ const mask = value >> 31;
3216
+ const absValue = (value + mask) ^ mask;
3217
+ let data = (absValue << 1) | sign;
3218
+ for (;;) {
3219
+ const sextet = data & 0x1f;
3220
+ data >>= 5;
3221
+ if (data === 0) {
3222
+ return str + ALPHABET[sextet];
3223
+ }
3224
+ str += ALPHABET[sextet | CONTINUATION_BIT];
3225
+ }
3226
+ };
3227
+
2616
3228
  const createFullMappingsSerializer = () => {
2617
3229
  let currentLine = 1;
2618
3230
  let currentColumn = 0;
@@ -2651,10 +3263,14 @@ const createFullMappingsSerializer = () => {
2651
3263
  return "";
2652
3264
  }
2653
3265
 
2654
- /** @type {undefined | string} */
2655
3266
  let str;
2656
3267
  if (currentLine < generatedLine) {
2657
- str = ";".repeat(generatedLine - currentLine);
3268
+ // Consecutive lines (diff === 1) are the dominant case; avoid the
3269
+ // `.repeat()` call entirely for them.
3270
+ str =
3271
+ generatedLine === currentLine + 1
3272
+ ? ";"
3273
+ : ";".repeat(generatedLine - currentLine);
2658
3274
  currentLine = generatedLine;
2659
3275
  currentColumn = 0;
2660
3276
  initial = false;
@@ -2665,46 +3281,26 @@ const createFullMappingsSerializer = () => {
2665
3281
  str = ",";
2666
3282
  }
2667
3283
 
2668
- /**
2669
- * @param {number} value value
2670
- * @returns {void}
2671
- */
2672
- const writeValue = (value) => {
2673
- const sign = (value >>> 31) & 1;
2674
- const mask = value >> 31;
2675
- const absValue = (value + mask) ^ mask;
2676
- let data = (absValue << 1) | sign;
2677
- for (;;) {
2678
- const sextet = data & 0x1f;
2679
- data >>= 5;
2680
- if (data === 0) {
2681
- str += ALPHABET[sextet];
2682
- break;
2683
- } else {
2684
- str += ALPHABET[sextet | CONTINUATION_BIT];
2685
- }
2686
- }
2687
- };
2688
- writeValue(generatedColumn - currentColumn);
3284
+ str = writeValue(str, generatedColumn - currentColumn);
2689
3285
  currentColumn = generatedColumn;
2690
3286
  if (sourceIndex >= 0) {
2691
3287
  activeMapping = true;
2692
3288
  if (sourceIndex === currentSourceIndex) {
2693
3289
  str += "A";
2694
3290
  } else {
2695
- writeValue(sourceIndex - currentSourceIndex);
3291
+ str = writeValue(str, sourceIndex - currentSourceIndex);
2696
3292
  currentSourceIndex = sourceIndex;
2697
3293
  }
2698
- writeValue(originalLine - currentOriginalLine);
3294
+ str = writeValue(str, originalLine - currentOriginalLine);
2699
3295
  currentOriginalLine = originalLine;
2700
3296
  if (originalColumn === currentOriginalColumn) {
2701
3297
  str += "A";
2702
3298
  } else {
2703
- writeValue(originalColumn - currentOriginalColumn);
3299
+ str = writeValue(str, originalColumn - currentOriginalColumn);
2704
3300
  currentOriginalColumn = originalColumn;
2705
3301
  }
2706
3302
  if (nameIndex >= 0) {
2707
- writeValue(nameIndex - currentNameIndex);
3303
+ str = writeValue(str, nameIndex - currentNameIndex);
2708
3304
  currentNameIndex = nameIndex;
2709
3305
  activeName = true;
2710
3306
  } else {
@@ -2739,28 +3335,7 @@ const createLinesOnlyMappingsSerializer = () => {
2739
3335
  // avoid writing multiple original mappings per line
2740
3336
  return "";
2741
3337
  }
2742
- /** @type {undefined | string} */
2743
3338
  let str;
2744
- /**
2745
- * @param {number} value value
2746
- * @returns {void}
2747
- */
2748
- const writeValue = (value) => {
2749
- const sign = (value >>> 31) & 1;
2750
- const mask = value >> 31;
2751
- const absValue = (value + mask) ^ mask;
2752
- let data = (absValue << 1) | sign;
2753
- for (;;) {
2754
- const sextet = data & 0x1f;
2755
- data >>= 5;
2756
- if (data === 0) {
2757
- str += ALPHABET[sextet];
2758
- break;
2759
- } else {
2760
- str += ALPHABET[sextet | CONTINUATION_BIT];
2761
- }
2762
- }
2763
- };
2764
3339
  lastWrittenLine = generatedLine;
2765
3340
  if (generatedLine === currentLine + 1) {
2766
3341
  currentLine = generatedLine;
@@ -2770,14 +3345,14 @@ const createLinesOnlyMappingsSerializer = () => {
2770
3345
  return ";AACA";
2771
3346
  }
2772
3347
  str = ";AA";
2773
- writeValue(originalLine - currentOriginalLine);
3348
+ str = writeValue(str, originalLine - currentOriginalLine);
2774
3349
  currentOriginalLine = originalLine;
2775
3350
  return `${str}A`;
2776
3351
  }
2777
3352
  str = ";A";
2778
- writeValue(sourceIndex - currentSourceIndex);
3353
+ str = writeValue(str, sourceIndex - currentSourceIndex);
2779
3354
  currentSourceIndex = sourceIndex;
2780
- writeValue(originalLine - currentOriginalLine);
3355
+ str = writeValue(str, originalLine - currentOriginalLine);
2781
3356
  currentOriginalLine = originalLine;
2782
3357
  return `${str}A`;
2783
3358
  }
@@ -2789,14 +3364,14 @@ const createLinesOnlyMappingsSerializer = () => {
2789
3364
  return `${str}AACA`;
2790
3365
  }
2791
3366
  str += "AA";
2792
- writeValue(originalLine - currentOriginalLine);
3367
+ str = writeValue(str, originalLine - currentOriginalLine);
2793
3368
  currentOriginalLine = originalLine;
2794
3369
  return `${str}A`;
2795
3370
  }
2796
3371
  str += "A";
2797
- writeValue(sourceIndex - currentSourceIndex);
3372
+ str = writeValue(str, sourceIndex - currentSourceIndex);
2798
3373
  currentSourceIndex = sourceIndex;
2799
- writeValue(originalLine - currentOriginalLine);
3374
+ str = writeValue(str, originalLine - currentOriginalLine);
2800
3375
  currentOriginalLine = originalLine;
2801
3376
  return `${str}A`;
2802
3377
  };
@@ -2818,7 +3393,7 @@ module.exports = createMappingsSerializer;
2818
3393
 
2819
3394
  /***/ }),
2820
3395
 
2821
- /***/ 568:
3396
+ /***/ 468:
2822
3397
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2823
3398
 
2824
3399
  /*
@@ -2828,7 +3403,7 @@ module.exports = createMappingsSerializer;
2828
3403
 
2829
3404
 
2830
3405
 
2831
- const createMappingsSerializer = __nccwpck_require__(983);
3406
+ const createMappingsSerializer = __nccwpck_require__(859);
2832
3407
 
2833
3408
  /** @typedef {import("../Source").RawSourceMap} RawSourceMap */
2834
3409
  /** @typedef {import("../Source").SourceAndMap} SourceAndMap */
@@ -2984,7 +3559,7 @@ module.exports.getSourceAndMap = (inputSource, options) => {
2984
3559
 
2985
3560
  /***/ }),
2986
3561
 
2987
- /***/ 784:
3562
+ /***/ 724:
2988
3563
  /***/ ((module) => {
2989
3564
 
2990
3565
  /*
@@ -2994,8 +3569,6 @@ module.exports.getSourceAndMap = (inputSource, options) => {
2994
3569
 
2995
3570
 
2996
3571
 
2997
- const CHAR_CODE_NEW_LINE = "\n".charCodeAt(0);
2998
-
2999
3572
  /**
3000
3573
  * @typedef {object} GeneratedSourceInfo
3001
3574
  * @property {number=} generatedLine generated line
@@ -3019,9 +3592,14 @@ const getGeneratedSourceInfo = (source) => {
3019
3592
  source,
3020
3593
  };
3021
3594
  }
3595
+ // Use native indexOf to scan for newlines instead of charCodeAt loops.
3596
+ // This is significantly faster on large sources since indexOf uses
3597
+ // vectorized/native string scanning.
3022
3598
  let generatedLine = 2;
3023
- for (let i = 0; i < lastLineStart; i++) {
3024
- if (source.charCodeAt(i) === CHAR_CODE_NEW_LINE) generatedLine++;
3599
+ let idx = source.indexOf("\n");
3600
+ while (idx !== -1 && idx < lastLineStart) {
3601
+ generatedLine++;
3602
+ idx = source.indexOf("\n", idx + 1);
3025
3603
  }
3026
3604
  return {
3027
3605
  generatedLine,
@@ -3035,7 +3613,7 @@ module.exports = getGeneratedSourceInfo;
3035
3613
 
3036
3614
  /***/ }),
3037
3615
 
3038
- /***/ 711:
3616
+ /***/ 707:
3039
3617
  /***/ ((module) => {
3040
3618
 
3041
3619
  /*
@@ -3066,7 +3644,7 @@ module.exports = getSource;
3066
3644
 
3067
3645
  /***/ }),
3068
3646
 
3069
- /***/ 28:
3647
+ /***/ 651:
3070
3648
  /***/ ((module) => {
3071
3649
 
3072
3650
  /*
@@ -3106,8 +3684,8 @@ const ccMax = ccToValue.length - 1;
3106
3684
  * @returns {void}
3107
3685
  */
3108
3686
  const readMappings = (mappings, onMapping) => {
3109
- // generatedColumn, [sourceIndex, originalLine, orignalColumn, [nameIndex]]
3110
- const currentData = new Uint32Array([0, 0, 1, 0, 0]);
3687
+ // generatedColumn, [sourceIndex, originalLine, originalColumn, [nameIndex]]
3688
+ const currentData = new Int32Array([0, 0, 1, 0, 0]);
3111
3689
  let currentDataPos = 0;
3112
3690
  // currentValue will include a sign bit at bit 0
3113
3691
  let currentValue = 0;
@@ -3142,7 +3720,10 @@ const readMappings = (mappings, onMapping) => {
3142
3720
  currentData[4],
3143
3721
  );
3144
3722
  }
3145
- [generatedColumn] = currentData;
3723
+ // Direct typed-array index is faster here than destructuring,
3724
+ // which would invoke the Int32Array iterator protocol.
3725
+ // eslint-disable-next-line prefer-destructuring
3726
+ generatedColumn = currentData[0];
3146
3727
  }
3147
3728
  currentDataPos = 0;
3148
3729
  if (value === NEXT_LINE) {
@@ -3193,7 +3774,7 @@ module.exports = readMappings;
3193
3774
 
3194
3775
  /***/ }),
3195
3776
 
3196
- /***/ 509:
3777
+ /***/ 409:
3197
3778
  /***/ ((module) => {
3198
3779
 
3199
3780
  /*
@@ -3212,18 +3793,19 @@ const splitIntoLines = (str) => {
3212
3793
  const len = str.length;
3213
3794
  let i = 0;
3214
3795
  while (i < len) {
3215
- const cc = str.charCodeAt(i);
3216
- // 10 is "\n".charCodeAt(0)
3217
- if (cc === 10) {
3796
+ // indexOf is implemented natively and is significantly faster than
3797
+ // scanning char-by-char with charCodeAt for long lines.
3798
+ const n = str.indexOf("\n", i);
3799
+ if (n === -1) {
3800
+ results.push(i === 0 ? str : str.slice(i));
3801
+ break;
3802
+ }
3803
+ if (n === i) {
3218
3804
  results.push("\n");
3219
- i++;
3220
3805
  } else {
3221
- let j = i + 1;
3222
- // 10 is "\n".charCodeAt(0)
3223
- while (j < len && str.charCodeAt(j) !== 10) j++;
3224
- results.push(str.slice(i, j + 1));
3225
- i = j + 1;
3806
+ results.push(str.slice(i, n + 1));
3226
3807
  }
3808
+ i = n + 1;
3227
3809
  }
3228
3810
  return results;
3229
3811
  };
@@ -3233,7 +3815,7 @@ module.exports = splitIntoLines;
3233
3815
 
3234
3816
  /***/ }),
3235
3817
 
3236
- /***/ 674:
3818
+ /***/ 574:
3237
3819
  /***/ ((module) => {
3238
3820
 
3239
3821
  /*
@@ -3293,7 +3875,7 @@ module.exports = splitIntoPotentialTokens;
3293
3875
 
3294
3876
  /***/ }),
3295
3877
 
3296
- /***/ 439:
3878
+ /***/ 579:
3297
3879
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
3298
3880
 
3299
3881
  /*
@@ -3303,8 +3885,8 @@ module.exports = splitIntoPotentialTokens;
3303
3885
 
3304
3886
 
3305
3887
 
3306
- const createMappingsSerializer = __nccwpck_require__(983);
3307
- const streamChunks = __nccwpck_require__(786);
3888
+ const createMappingsSerializer = __nccwpck_require__(859);
3889
+ const streamChunks = __nccwpck_require__(750);
3308
3890
 
3309
3891
  /** @typedef {import("../Source").RawSourceMap} RawSourceMap */
3310
3892
  /** @typedef {import("./streamChunks").GeneratedSourceInfo} GeneratedSourceInfo */
@@ -3423,7 +4005,7 @@ module.exports = streamAndGetSourceAndMap;
3423
4005
 
3424
4006
  /***/ }),
3425
4007
 
3426
- /***/ 786:
4008
+ /***/ 750:
3427
4009
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
3428
4010
 
3429
4011
  /*
@@ -3433,8 +4015,8 @@ module.exports = streamAndGetSourceAndMap;
3433
4015
 
3434
4016
 
3435
4017
 
3436
- const streamChunksOfRawSource = __nccwpck_require__(300);
3437
- const streamChunksOfSourceMap = __nccwpck_require__(814);
4018
+ const streamChunksOfRawSource = __nccwpck_require__(824);
4019
+ const streamChunksOfSourceMap = __nccwpck_require__(938);
3438
4020
 
3439
4021
  /** @typedef {import("../Source")} Source */
3440
4022
  /** @typedef {import("./getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */
@@ -3492,7 +4074,7 @@ module.exports = (source, options, onChunk, onSource, onName) => {
3492
4074
 
3493
4075
  /***/ }),
3494
4076
 
3495
- /***/ 647:
4077
+ /***/ 459:
3496
4078
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
3497
4079
 
3498
4080
  /*
@@ -3502,8 +4084,8 @@ module.exports = (source, options, onChunk, onSource, onName) => {
3502
4084
 
3503
4085
 
3504
4086
 
3505
- const splitIntoLines = __nccwpck_require__(509);
3506
- const streamChunksOfSourceMap = __nccwpck_require__(814);
4087
+ const splitIntoLines = __nccwpck_require__(409);
4088
+ const streamChunksOfSourceMap = __nccwpck_require__(938);
3507
4089
 
3508
4090
  /** @typedef {import("../Source").RawSourceMap} RawSourceMap */
3509
4091
  /** @typedef {import("./getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */
@@ -3573,7 +4155,11 @@ const streamChunksOfCombinedSourceMap = (
3573
4155
  if (line > innerSourceMapLineData.length) return -1;
3574
4156
  const { mappingsData } = innerSourceMapLineData[line - 1];
3575
4157
  let l = 0;
3576
- let r = mappingsData.length / 5;
4158
+ // `mappingsData.length` is always a multiple of 5 (five values pushed
4159
+ // per mapping), so dividing is exact. Coerce the bound to an int32 so
4160
+ // the binary-search loop stays on V8's fast small-int path instead of
4161
+ // comparing an int against a float.
4162
+ let r = (mappingsData.length / 5) | 0;
3577
4163
  while (l < r) {
3578
4164
  const m = (l + r) >> 1;
3579
4165
  if (mappingsData[m * 5] <= column) {
@@ -3865,7 +4451,7 @@ module.exports = streamChunksOfCombinedSourceMap;
3865
4451
 
3866
4452
  /***/ }),
3867
4453
 
3868
- /***/ 300:
4454
+ /***/ 824:
3869
4455
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
3870
4456
 
3871
4457
  /*
@@ -3875,8 +4461,7 @@ module.exports = streamChunksOfCombinedSourceMap;
3875
4461
 
3876
4462
 
3877
4463
 
3878
- const getGeneratedSourceInfo = __nccwpck_require__(784);
3879
- const splitIntoLines = __nccwpck_require__(509);
4464
+ const getGeneratedSourceInfo = __nccwpck_require__(724);
3880
4465
 
3881
4466
  /** @typedef {import("./getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */
3882
4467
  /** @typedef {import("./streamChunks").OnChunk} OnChunk */
@@ -3889,25 +4474,34 @@ const splitIntoLines = __nccwpck_require__(509);
3889
4474
  * @param {OnSource} _onSource on source
3890
4475
  * @param {OnName} _onName on name
3891
4476
  * @returns {GeneratedSourceInfo} source info
4477
+ *
4478
+ * Single-pass equivalent of `splitIntoLines(source).forEach(emit)` — emits
4479
+ * each line via onChunk while scanning for newlines, so we never allocate
4480
+ * the intermediate array of lines.
3892
4481
  */
3893
4482
  const streamChunksOfRawSource = (source, onChunk, _onSource, _onName) => {
4483
+ const len = source.length;
4484
+ if (len === 0) {
4485
+ return { generatedLine: 1, generatedColumn: 0 };
4486
+ }
3894
4487
  let line = 1;
3895
- const matches = splitIntoLines(source);
3896
- /** @type {undefined | string} */
3897
- let match;
3898
- for (match of matches) {
3899
- onChunk(match, line, 0, -1, -1, -1, -1);
4488
+ let i = 0;
4489
+ while (i < len) {
4490
+ const n = source.indexOf("\n", i);
4491
+ if (n === -1) {
4492
+ // Trailing partial line (no \n). Emit and return its length as the
4493
+ // final column.
4494
+ const lastLine = i === 0 ? source : source.slice(i);
4495
+ onChunk(lastLine, line, 0, -1, -1, -1, -1);
4496
+ return { generatedLine: line, generatedColumn: lastLine.length };
4497
+ }
4498
+ const chunk = n === i ? "\n" : source.slice(i, n + 1);
4499
+ onChunk(chunk, line, 0, -1, -1, -1, -1);
3900
4500
  line++;
4501
+ i = n + 1;
3901
4502
  }
3902
- return matches.length === 0 || /** @type {string} */ (match).endsWith("\n")
3903
- ? {
3904
- generatedLine: matches.length + 1,
3905
- generatedColumn: 0,
3906
- }
3907
- : {
3908
- generatedLine: matches.length,
3909
- generatedColumn: /** @type {string} */ (match).length,
3910
- };
4503
+ // Source ended with a newline the next "logical" line is empty.
4504
+ return { generatedLine: line, generatedColumn: 0 };
3911
4505
  };
3912
4506
 
3913
4507
  /**
@@ -3926,7 +4520,7 @@ module.exports = (source, onChunk, onSource, onName, finalSource) =>
3926
4520
 
3927
4521
  /***/ }),
3928
4522
 
3929
- /***/ 814:
4523
+ /***/ 938:
3930
4524
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
3931
4525
 
3932
4526
  /*
@@ -3936,10 +4530,10 @@ module.exports = (source, onChunk, onSource, onName, finalSource) =>
3936
4530
 
3937
4531
 
3938
4532
 
3939
- const getGeneratedSourceInfo = __nccwpck_require__(784);
3940
- const getSource = __nccwpck_require__(711);
3941
- const readMappings = __nccwpck_require__(28);
3942
- const splitIntoLines = __nccwpck_require__(509);
4533
+ const getGeneratedSourceInfo = __nccwpck_require__(724);
4534
+ const getSource = __nccwpck_require__(707);
4535
+ const readMappings = __nccwpck_require__(651);
4536
+ const splitIntoLines = __nccwpck_require__(409);
3943
4537
 
3944
4538
  /** @typedef {import("../Source").RawSourceMap} RawSourceMap */
3945
4539
  /** @typedef {import("./getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */
@@ -3963,7 +4557,8 @@ const streamChunksOfSourceMapFull = (
3963
4557
  onName,
3964
4558
  ) => {
3965
4559
  const lines = splitIntoLines(source);
3966
- if (lines.length === 0) {
4560
+ const linesLength = lines.length;
4561
+ if (linesLength === 0) {
3967
4562
  return {
3968
4563
  generatedLine: 1,
3969
4564
  generatedColumn: 0,
@@ -3983,9 +4578,9 @@ const streamChunksOfSourceMapFull = (
3983
4578
  }
3984
4579
  }
3985
4580
 
3986
- const lastLine = lines[lines.length - 1];
4581
+ const lastLine = lines[linesLength - 1];
3987
4582
  const lastNewLine = lastLine.endsWith("\n");
3988
- const finalLine = lastNewLine ? lines.length + 1 : lines.length;
4583
+ const finalLine = lastNewLine ? linesLength + 1 : linesLength;
3989
4584
  const finalColumn = lastNewLine ? 0 : lastLine.length;
3990
4585
 
3991
4586
  let currentGeneratedLine = 1;
@@ -4014,7 +4609,7 @@ const streamChunksOfSourceMapFull = (
4014
4609
  originalColumn,
4015
4610
  nameIndex,
4016
4611
  ) => {
4017
- if (mappingActive && currentGeneratedLine <= lines.length) {
4612
+ if (mappingActive && currentGeneratedLine <= linesLength) {
4018
4613
  let chunk;
4019
4614
  const mappingLine = currentGeneratedLine;
4020
4615
  const mappingColumn = currentGeneratedColumn;
@@ -4041,7 +4636,7 @@ const streamChunksOfSourceMapFull = (
4041
4636
  mappingActive = false;
4042
4637
  }
4043
4638
  if (generatedLine > currentGeneratedLine && currentGeneratedColumn > 0) {
4044
- if (currentGeneratedLine <= lines.length) {
4639
+ if (currentGeneratedLine <= linesLength) {
4045
4640
  const chunk = lines[currentGeneratedLine - 1].slice(
4046
4641
  currentGeneratedColumn,
4047
4642
  );
@@ -4058,22 +4653,29 @@ const streamChunksOfSourceMapFull = (
4058
4653
  currentGeneratedLine++;
4059
4654
  currentGeneratedColumn = 0;
4060
4655
  }
4061
- while (generatedLine > currentGeneratedLine) {
4062
- if (currentGeneratedLine <= lines.length) {
4063
- onChunk(
4064
- lines[currentGeneratedLine - 1],
4065
- currentGeneratedLine,
4066
- 0,
4067
- -1,
4068
- -1,
4069
- -1,
4070
- -1,
4071
- );
4072
- }
4656
+ // Emit each fully-passed generated line. Once we move past the last
4657
+ // available line we stop emitting, but still need to advance the
4658
+ // counter to `generatedLine` so subsequent state matches the caller.
4659
+ while (
4660
+ generatedLine > currentGeneratedLine &&
4661
+ currentGeneratedLine <= linesLength
4662
+ ) {
4663
+ onChunk(
4664
+ lines[currentGeneratedLine - 1],
4665
+ currentGeneratedLine,
4666
+ 0,
4667
+ -1,
4668
+ -1,
4669
+ -1,
4670
+ -1,
4671
+ );
4073
4672
  currentGeneratedLine++;
4074
4673
  }
4674
+ if (currentGeneratedLine < generatedLine) {
4675
+ currentGeneratedLine = generatedLine;
4676
+ }
4075
4677
  if (generatedColumn > currentGeneratedColumn) {
4076
- if (currentGeneratedLine <= lines.length) {
4678
+ if (currentGeneratedLine <= linesLength) {
4077
4679
  const chunk = lines[currentGeneratedLine - 1].slice(
4078
4680
  currentGeneratedColumn,
4079
4681
  generatedColumn,
@@ -4126,7 +4728,8 @@ const streamChunksOfSourceMapLinesFull = (
4126
4728
  _onName,
4127
4729
  ) => {
4128
4730
  const lines = splitIntoLines(source);
4129
- if (lines.length === 0) {
4731
+ const linesLength = lines.length;
4732
+ if (linesLength === 0) {
4130
4733
  return {
4131
4734
  generatedLine: 1,
4132
4735
  generatedColumn: 0,
@@ -4163,39 +4766,38 @@ const streamChunksOfSourceMapLinesFull = (
4163
4766
  if (
4164
4767
  sourceIndex < 0 ||
4165
4768
  generatedLine < currentGeneratedLine ||
4166
- generatedLine > lines.length
4769
+ generatedLine > linesLength
4167
4770
  ) {
4168
4771
  return;
4169
4772
  }
4773
+ // `generatedLine <= linesLength` is guaranteed by the guard above, so
4774
+ // every line we iterate over is in bounds — no per-iteration length
4775
+ // check needed.
4170
4776
  while (generatedLine > currentGeneratedLine) {
4171
- if (currentGeneratedLine <= lines.length) {
4172
- onChunk(
4173
- lines[currentGeneratedLine - 1],
4174
- currentGeneratedLine,
4175
- 0,
4176
- -1,
4177
- -1,
4178
- -1,
4179
- -1,
4180
- );
4181
- }
4182
- currentGeneratedLine++;
4183
- }
4184
- if (generatedLine <= lines.length) {
4185
4777
  onChunk(
4186
- lines[generatedLine - 1],
4187
- generatedLine,
4778
+ lines[currentGeneratedLine - 1],
4779
+ currentGeneratedLine,
4188
4780
  0,
4189
- sourceIndex,
4190
- originalLine,
4191
- originalColumn,
4781
+ -1,
4782
+ -1,
4783
+ -1,
4192
4784
  -1,
4193
4785
  );
4194
4786
  currentGeneratedLine++;
4195
4787
  }
4788
+ onChunk(
4789
+ lines[generatedLine - 1],
4790
+ generatedLine,
4791
+ 0,
4792
+ sourceIndex,
4793
+ originalLine,
4794
+ originalColumn,
4795
+ -1,
4796
+ );
4797
+ currentGeneratedLine++;
4196
4798
  };
4197
4799
  readMappings(mappings, onMapping);
4198
- for (; currentGeneratedLine <= lines.length; currentGeneratedLine++) {
4800
+ for (; currentGeneratedLine <= linesLength; currentGeneratedLine++) {
4199
4801
  onChunk(
4200
4802
  lines[currentGeneratedLine - 1],
4201
4803
  currentGeneratedLine,
@@ -4207,10 +4809,10 @@ const streamChunksOfSourceMapLinesFull = (
4207
4809
  );
4208
4810
  }
4209
4811
 
4210
- const lastLine = lines[lines.length - 1];
4812
+ const lastLine = lines[linesLength - 1];
4211
4813
  const lastNewLine = lastLine.endsWith("\n");
4212
4814
 
4213
- const finalLine = lastNewLine ? lines.length + 1 : lines.length;
4815
+ const finalLine = lastNewLine ? linesLength + 1 : linesLength;
4214
4816
  const finalColumn = lastNewLine ? 0 : lastLine.length;
4215
4817
 
4216
4818
  return {
@@ -4432,7 +5034,7 @@ module.exports = (
4432
5034
 
4433
5035
  /***/ }),
4434
5036
 
4435
- /***/ 806:
5037
+ /***/ 386:
4436
5038
  /***/ ((module) => {
4437
5039
 
4438
5040
  /*
@@ -4556,7 +5158,7 @@ module.exports = {
4556
5158
 
4557
5159
  /***/ }),
4558
5160
 
4559
- /***/ 340:
5161
+ /***/ 864:
4560
5162
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
4561
5163
 
4562
5164
  /*
@@ -4643,38 +5245,38 @@ module.exports = mergeExports(
4643
5245
  {},
4644
5246
  {
4645
5247
  get Source() {
4646
- return __nccwpck_require__(331);
5248
+ return __nccwpck_require__(143);
4647
5249
  },
4648
5250
  get RawSource() {
4649
- return __nccwpck_require__(855);
5251
+ return __nccwpck_require__(371);
4650
5252
  },
4651
5253
  get OriginalSource() {
4652
- return __nccwpck_require__(792);
5254
+ return __nccwpck_require__(924);
4653
5255
  },
4654
5256
  get SourceMapSource() {
4655
- return __nccwpck_require__(476);
5257
+ return __nccwpck_require__(8);
4656
5258
  },
4657
5259
  get CachedSource() {
4658
- return __nccwpck_require__(61);
5260
+ return __nccwpck_require__(969);
4659
5261
  },
4660
5262
  get ConcatSource() {
4661
- return __nccwpck_require__(523);
5263
+ return __nccwpck_require__(415);
4662
5264
  },
4663
5265
  get ReplaceSource() {
4664
- return __nccwpck_require__(197);
5266
+ return __nccwpck_require__(753);
4665
5267
  },
4666
5268
  get PrefixSource() {
4667
- return __nccwpck_require__(199);
5269
+ return __nccwpck_require__(11);
4668
5270
  },
4669
5271
  get SizeOnlySource() {
4670
- return __nccwpck_require__(628);
5272
+ return __nccwpck_require__(216);
4671
5273
  },
4672
5274
  get CompatSource() {
4673
- return __nccwpck_require__(961);
5275
+ return __nccwpck_require__(589);
4674
5276
  },
4675
5277
  util: {
4676
5278
  get stringBufferUtils() {
4677
- return __nccwpck_require__(806);
5279
+ return __nccwpck_require__(386);
4678
5280
  },
4679
5281
  },
4680
5282
  },
@@ -4725,7 +5327,7 @@ module.exports = mergeExports(
4725
5327
  /******/ // startup
4726
5328
  /******/ // Load entry module and return exports
4727
5329
  /******/ // This entry module is referenced by other modules so it can't be inlined
4728
- /******/ var __webpack_exports__ = __nccwpck_require__(340);
5330
+ /******/ var __webpack_exports__ = __nccwpck_require__(864);
4729
5331
  /******/ module.exports = __webpack_exports__;
4730
5332
  /******/
4731
5333
  /******/ })()