webpack 5.112.1 → 5.112.2

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.
@@ -1471,8 +1471,6 @@ class ConcatenatedModule extends Module {
1471
1471
  if (runtimeCondition === false) continue;
1472
1472
  const nonDeferAccess = !defer;
1473
1473
  const module = connection.module;
1474
- if (targets === undefined) targets = [module];
1475
- else if (!targets.includes(module)) targets.push(module);
1476
1474
  const dependency = connection.dependency;
1477
1475
  if (
1478
1476
  dependency !== null &&
@@ -1483,6 +1481,8 @@ class ConcatenatedModule extends Module {
1483
1481
  }
1484
1482
  const entry = referencesMap.get(module);
1485
1483
  if (entry === undefined) {
1484
+ if (targets === undefined) targets = [module];
1485
+ else targets.push(module);
1486
1486
  referencesMap.set(module, {
1487
1487
  connection,
1488
1488
  runtimeCondition,
@@ -335,7 +335,7 @@ const FLATTEN_BLOCK = 64 * 1024;
335
335
 
336
336
  // Most prints do not ask for a source map. Sharing their permanently empty
337
337
  // mapping column avoids allocating an array for every inline CSS/HTML body.
338
- /** @type {[number, number, number, number][]} */
338
+ /** @type {number[]} */
339
339
  const EMPTY_MAPPINGS = [];
340
340
 
341
341
  // Base64 VLQ, the source-map `mappings` encoding. Hand-rolled so producing a map
@@ -347,6 +347,28 @@ const _B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
347
347
  * @returns {string} its Base64 VLQ encoding
348
348
  */
349
349
  const _vlq = (n) => {
350
+ // Most deltas are small, and each is spelled the same every time.
351
+ if (n > -_VLQ_CACHED && n < _VLQ_CACHED) {
352
+ if (_vlqCache === null) _vlqCache = Array.from({ length: _VLQ_CACHED * 2 });
353
+ const cached = _vlqCache[n + _VLQ_CACHED];
354
+ if (cached !== undefined) return cached;
355
+ return (_vlqCache[n + _VLQ_CACHED] = _encodeVlq(n));
356
+ }
357
+ return _encodeVlq(n);
358
+ };
359
+
360
+ // `_vlq` of every delta within this of zero, filled in as they are written,
361
+ // and made only once a map is.
362
+ const _VLQ_CACHED = 1024;
363
+ /** @type {(string | undefined)[] | null} */
364
+ let _vlqCache = null;
365
+
366
+ /**
367
+ * One value as a Base64 VLQ, spelled out.
368
+ * @param {number} n the value
369
+ * @returns {string} its VLQ
370
+ */
371
+ const _encodeVlq = (n) => {
350
372
  let v = n < 0 ? (-n << 1) | 1 : n << 1;
351
373
  let out = "";
352
374
  do {
@@ -436,9 +458,11 @@ class PrintContext {
436
458
  /** @type {boolean} whether {@link sourceMap} can still be asked for one */
437
459
  this.mapWanted =
438
460
  /** @type {{ source?: string }} */ (options).source !== undefined;
439
- /** @type {[number, number, number, number][]} `[chunkIndex, offsetInChunk, srcLine, srcCol]`, output-ordered; a `srcLine` of -1 is one {@link retract} took back with its piece */
461
+ // Flat rather than one array per mapping: a stylesheet anchors every rule,
462
+ // and those arrays live as long as the print does.
463
+ /** @type {number[]} `chunkIndex, offsetInChunk, srcLine, srcCol` per mapping, output-ordered; a `srcLine` of -1 is one {@link retract} took back with its piece */
440
464
  this._mappings = this.mapWanted ? [] : EMPTY_MAPPINGS;
441
- /** @type {number[] | null} by retractable piece index, the mapping anchored to it, so taking the piece back takes its mapping too */
465
+ /** @type {number[] | null} by retractable piece index, the index in `_mappings` of the mapping anchored to it, so taking the piece back takes its mapping too */
442
466
  this._retractableMappings = null;
443
467
  /** @type {[number, string][]} source-anchored literals to keep (comments), source-ordered */
444
468
  this._inserts = [];
@@ -651,9 +675,14 @@ class PrintContext {
651
675
  remove -= chunks[i].length - kept;
652
676
  chunks[i] = chunks[i].slice(0, kept);
653
677
  // A mapping into what went would point past its piece.
654
- this._mappings = this._mappings.filter(
655
- ([chunk, offset]) => chunk !== i || offset <= kept
656
- );
678
+ const mappings = this._mappings;
679
+ let to = 0;
680
+ for (let at = 0; at < mappings.length; at += 4) {
681
+ if (mappings[at] === i && mappings[at + 1] > kept) continue;
682
+ for (let k = 0; k < 4; k++) mappings[to + k] = mappings[at + k];
683
+ to += 4;
684
+ }
685
+ mappings.length = to;
657
686
  }
658
687
  this._emit(text);
659
688
  return true;
@@ -788,7 +817,7 @@ class PrintContext {
788
817
  this._chunks[index] = "";
789
818
  if (this._retractableMappings === null) return;
790
819
  const mapping = this._retractableMappings[index];
791
- if (mapping !== undefined) this._mappings[mapping][2] = -1;
820
+ if (mapping !== undefined) this._mappings[mapping + 2] = -1;
792
821
  }
793
822
 
794
823
  /**
@@ -923,12 +952,12 @@ class PrintContext {
923
952
  if (srcLine !== undefined && this.mapWanted) {
924
953
  // `_chunks.length` is where the tail will land once it is cut off, so
925
954
  // this stays right whether or not a piece is cut after it.
926
- this._mappings.push([
955
+ this._mappings.push(
927
956
  this._chunks.length,
928
957
  this._tailLength,
929
958
  srcLine,
930
959
  /** @type {number} */ (srcCol)
931
- ]);
960
+ );
932
961
  }
933
962
  }
934
963
 
@@ -1039,7 +1068,12 @@ class PrintContext {
1039
1068
  // Offset of the next newline at or after the cursor, `-1` for none left.
1040
1069
  // Carried rather than searched for per mapping: `indexOf` has no end bound.
1041
1070
  let nextNewline = text.indexOf("\n");
1042
- for (const [chunkIndex, chunkOffset, sl, sc] of this._mappings) {
1071
+ const mappings = this._mappings;
1072
+ for (let at = 0; at < mappings.length; at += 4) {
1073
+ const chunkIndex = mappings[at];
1074
+ const chunkOffset = mappings[at + 1];
1075
+ const sl = mappings[at + 2];
1076
+ const sc = mappings[at + 3];
1043
1077
  // Its piece was taken back, so there is no output left to anchor.
1044
1078
  if (sl === -1) continue;
1045
1079
  // A piece's length is stored, so summing them costs nothing per byte.
@@ -1100,7 +1134,7 @@ class PrintContext {
1100
1134
  let at = 0;
1101
1135
  for (let i = 0; i <= chunks.length; i++) {
1102
1136
  const text = i === chunks.length ? this._tail : chunks[i];
1103
- while (at < mappings.length && mappings[at][0] < i) at++;
1137
+ while (at < mappings.length && mappings[at] < i) at += 4;
1104
1138
  let start = text.indexOf(DEFERRED_MARKER);
1105
1139
  if (start === -1) continue;
1106
1140
  let out = "";
@@ -1139,9 +1173,9 @@ class PrintContext {
1139
1173
  chunks[i] = out;
1140
1174
  }
1141
1175
  let s = 0;
1142
- for (let k = at; k < mappings.length && mappings[k][0] === i; k++) {
1143
- while (s < shifts.length && shifts[s][0] <= mappings[k][1]) s++;
1144
- if (s !== 0) mappings[k][1] += shifts[s - 1][1];
1176
+ for (let k = at; k < mappings.length && mappings[k] === i; k += 4) {
1177
+ while (s < shifts.length && shifts[s][0] <= mappings[k + 1]) s++;
1178
+ if (s !== 0) mappings[k + 1] += shifts[s - 1][1];
1145
1179
  }
1146
1180
  }
1147
1181
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.112.1",
3
+ "version": "5.112.2",
4
4
  "description": "Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
5
5
  "homepage": "https://github.com/webpack/webpack",
6
6
  "bugs": "https://github.com/webpack/webpack/issues",
@@ -121,7 +121,8 @@
121
121
  "cover:minify": "yarn cover:base --testMatch \"<rootDir>/test/specCases/minify-corpora.spectest.js\" --coverage",
122
122
  "cover:minify-fuzz": "yarn cover:base --testMatch \"<rootDir>/test/specCases/js-fuzz.spectest.js\" --coverage",
123
123
  "cover:test262-parser": "yarn cover:base --testMatch \"<rootDir>/test/specCases/test262-parser.spectest.js\" --coverage",
124
- "cover:xmlconf": "yarn cover:base --testMatch \"<rootDir>/test/specCases/xmlconf.spectest.js\" --coverage"
124
+ "cover:xmlconf": "yarn cover:base --testMatch \"<rootDir>/test/specCases/xmlconf.spectest.js\" --coverage",
125
+ "cover:spec-css-html-xml": "yarn cover:base --testMatch \"<rootDir>/test/specCases/cssParsing-webpack.spectest.js\" \"<rootDir>/test/specCases/html5lib.spectest.js\" \"<rootDir>/test/specCases/xmlconf.spectest.js\" --coverage"
125
126
  },
126
127
  "lint-staged": {
127
128
  "*.{js,cjs,mjs}": [