lighthouse 12.3.0 → 12.4.0-dev.20250227

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 (142) hide show
  1. package/cli/test/smokehouse/core-tests.js +4 -0
  2. package/core/audits/audit.d.ts +5 -0
  3. package/core/audits/audit.js +12 -0
  4. package/core/audits/bootup-time.js +0 -2
  5. package/core/audits/byte-efficiency/duplicated-javascript.d.ts +4 -5
  6. package/core/audits/byte-efficiency/duplicated-javascript.js +9 -5
  7. package/core/audits/byte-efficiency/legacy-javascript.d.ts +2 -2
  8. package/core/audits/byte-efficiency/legacy-javascript.js +17 -5
  9. package/core/audits/byte-efficiency/polyfill-graph-data.json +48 -49
  10. package/core/audits/byte-efficiency/total-byte-weight.js +0 -2
  11. package/core/audits/clickjacking-mitigation.d.ts +42 -0
  12. package/core/audits/clickjacking-mitigation.js +139 -0
  13. package/core/audits/dobetterweb/dom-size.js +0 -2
  14. package/core/audits/insights/README.md +3 -0
  15. package/core/audits/insights/cls-culprits-insight.d.ts +25 -0
  16. package/core/audits/insights/cls-culprits-insight.js +137 -0
  17. package/core/audits/insights/document-latency-insight.d.ts +11 -0
  18. package/core/audits/insights/document-latency-insight.js +48 -0
  19. package/core/audits/insights/dom-size-insight.d.ts +11 -0
  20. package/core/audits/insights/dom-size-insight.js +85 -0
  21. package/core/audits/insights/font-display-insight.d.ts +11 -0
  22. package/core/audits/insights/font-display-insight.js +53 -0
  23. package/core/audits/insights/forced-reflow-insight.d.ts +11 -0
  24. package/core/audits/insights/forced-reflow-insight.js +52 -0
  25. package/core/audits/insights/image-delivery-insight.d.ts +11 -0
  26. package/core/audits/insights/image-delivery-insight.js +83 -0
  27. package/core/audits/insights/insight-audit.d.ts +23 -0
  28. package/core/audits/insights/insight-audit.js +133 -0
  29. package/core/audits/insights/interaction-to-next-paint-insight.d.ts +11 -0
  30. package/core/audits/insights/interaction-to-next-paint-insight.js +71 -0
  31. package/core/audits/insights/lcp-discovery-insight.d.ts +11 -0
  32. package/core/audits/insights/lcp-discovery-insight.js +48 -0
  33. package/core/audits/insights/lcp-phases-insight.d.ts +16 -0
  34. package/core/audits/insights/lcp-phases-insight.js +87 -0
  35. package/core/audits/insights/long-critical-network-tree-insight.d.ts +11 -0
  36. package/core/audits/insights/long-critical-network-tree-insight.js +53 -0
  37. package/core/audits/insights/render-blocking-insight.d.ts +11 -0
  38. package/core/audits/insights/render-blocking-insight.js +57 -0
  39. package/core/audits/insights/slow-css-selector-insight.d.ts +11 -0
  40. package/core/audits/insights/slow-css-selector-insight.js +52 -0
  41. package/core/audits/insights/third-parties-insight.d.ts +28 -0
  42. package/core/audits/insights/third-parties-insight.js +90 -0
  43. package/core/audits/insights/viewport-insight.d.ts +11 -0
  44. package/core/audits/insights/viewport-insight.js +54 -0
  45. package/core/audits/layout-shifts.d.ts +0 -1
  46. package/core/audits/layout-shifts.js +18 -21
  47. package/core/audits/mainthread-work-breakdown.js +0 -2
  48. package/core/audits/seo/is-crawlable.d.ts +1 -0
  49. package/core/audits/server-response-time.js +0 -1
  50. package/core/computed/metrics/lantern-metric.js +5 -1
  51. package/core/computed/trace-engine-result.js +71 -17
  52. package/core/config/default-config.js +37 -1
  53. package/core/gather/gatherers/inspector-issues.js +3 -0
  54. package/core/gather/gatherers/trace-elements.d.ts +10 -2
  55. package/core/gather/gatherers/trace-elements.js +89 -12
  56. package/core/lib/bf-cache-strings.d.ts +7 -4
  57. package/core/lib/bf-cache-strings.js +174 -140
  58. package/core/lib/cdt/generated/ParsedURL.d.ts +1 -0
  59. package/core/lib/cdt/generated/ParsedURL.js +16 -4
  60. package/core/lib/cdt/generated/SourceMap.d.ts +32 -5
  61. package/core/lib/cdt/generated/SourceMap.js +192 -100
  62. package/core/lib/deprecations-strings.d.ts +78 -98
  63. package/core/lib/deprecations-strings.js +23 -41
  64. package/core/lib/i18n/i18n.d.ts +1 -0
  65. package/core/lib/i18n/i18n.js +2 -0
  66. package/core/lib/trace-engine.d.ts +1 -0
  67. package/core/lib/trace-engine.js +2 -0
  68. package/core/runner.js +2 -0
  69. package/dist/report/bundle.esm.js +196 -9
  70. package/dist/report/flow.js +197 -10
  71. package/dist/report/standalone.js +197 -10
  72. package/flow-report/src/i18n/i18n.d.ts +2 -0
  73. package/package.json +15 -13
  74. package/readme.md +3 -0
  75. package/report/assets/styles.css +179 -5
  76. package/report/assets/templates.html +14 -0
  77. package/report/renderer/components.js +9 -3
  78. package/report/renderer/details-renderer.d.ts +5 -0
  79. package/report/renderer/details-renderer.js +24 -0
  80. package/report/renderer/dom.d.ts +12 -1
  81. package/report/renderer/dom.js +26 -1
  82. package/report/renderer/i18n-formatter.d.ts +1 -1
  83. package/report/renderer/performance-category-renderer.d.ts +10 -0
  84. package/report/renderer/performance-category-renderer.js +81 -20
  85. package/report/renderer/report-utils.d.ts +1 -0
  86. package/report/renderer/report-utils.js +2 -0
  87. package/report/renderer/topbar-features.js +7 -0
  88. package/shared/localization/locales/ar-XB.json +74 -26
  89. package/shared/localization/locales/ar.json +76 -28
  90. package/shared/localization/locales/bg.json +74 -26
  91. package/shared/localization/locales/ca.json +74 -26
  92. package/shared/localization/locales/cs.json +74 -26
  93. package/shared/localization/locales/da.json +74 -26
  94. package/shared/localization/locales/de.json +75 -27
  95. package/shared/localization/locales/el.json +74 -26
  96. package/shared/localization/locales/en-GB.json +74 -26
  97. package/shared/localization/locales/en-US.json +288 -30
  98. package/shared/localization/locales/en-XA.json +48 -24
  99. package/shared/localization/locales/en-XL.json +288 -30
  100. package/shared/localization/locales/es-419.json +74 -26
  101. package/shared/localization/locales/es.json +74 -26
  102. package/shared/localization/locales/fi.json +74 -26
  103. package/shared/localization/locales/fil.json +75 -27
  104. package/shared/localization/locales/fr.json +74 -26
  105. package/shared/localization/locales/he.json +82 -34
  106. package/shared/localization/locales/hi.json +74 -26
  107. package/shared/localization/locales/hr.json +75 -27
  108. package/shared/localization/locales/hu.json +74 -26
  109. package/shared/localization/locales/id.json +74 -26
  110. package/shared/localization/locales/it.json +85 -37
  111. package/shared/localization/locales/ja.json +75 -27
  112. package/shared/localization/locales/ko.json +75 -27
  113. package/shared/localization/locales/lt.json +75 -27
  114. package/shared/localization/locales/lv.json +74 -26
  115. package/shared/localization/locales/nl.json +74 -26
  116. package/shared/localization/locales/no.json +75 -27
  117. package/shared/localization/locales/pl.json +74 -26
  118. package/shared/localization/locales/pt-PT.json +74 -26
  119. package/shared/localization/locales/pt.json +74 -26
  120. package/shared/localization/locales/ro.json +74 -26
  121. package/shared/localization/locales/ru.json +74 -26
  122. package/shared/localization/locales/sk.json +74 -26
  123. package/shared/localization/locales/sl.json +74 -26
  124. package/shared/localization/locales/sr-Latn.json +74 -26
  125. package/shared/localization/locales/sr.json +74 -26
  126. package/shared/localization/locales/sv.json +74 -26
  127. package/shared/localization/locales/ta.json +74 -26
  128. package/shared/localization/locales/te.json +74 -26
  129. package/shared/localization/locales/th.json +76 -28
  130. package/shared/localization/locales/tr.json +74 -26
  131. package/shared/localization/locales/uk.json +74 -26
  132. package/shared/localization/locales/vi.json +74 -26
  133. package/shared/localization/locales/zh-HK.json +75 -27
  134. package/shared/localization/locales/zh-TW.json +74 -26
  135. package/shared/localization/locales/zh.json +74 -26
  136. package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +3 -0
  137. package/types/artifacts.d.ts +5 -3
  138. package/types/audit.d.ts +2 -0
  139. package/types/lhr/audit-details.d.ts +13 -1
  140. package/types/lhr/audit-result.d.ts +2 -0
  141. package/core/gather/gatherers/root-causes.d.ts +0 -19
  142. package/core/gather/gatherers/root-causes.js +0 -144
@@ -4,11 +4,18 @@
4
4
  "use strict";
5
5
  const Common = require('../Common.js');
6
6
  const Platform = require('../Platform.js');
7
+
8
+ const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
9
+ const BASE64_CODES = new Uint8Array(123);
10
+ for (let index = 0; index < BASE64_CHARS.length; ++index) {
11
+ BASE64_CODES[BASE64_CHARS.charCodeAt(index)] = index;
12
+ }
13
+
7
14
  // Copyright 2021 The Chromium Authors. All rights reserved.
8
15
  // Use of this source code is governed by a BSD-style license that can be
9
16
  // found in the LICENSE file.
10
17
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.SourceMap = exports.SourceMapEntry = void 0;
18
+ exports.TokenIterator = exports.SourceMap = exports.SourceMapEntry = void 0;
12
19
  exports.parseSourceMap = parseSourceMap;
13
20
  /*
14
21
  * Copyright (C) 2012 Google Inc. All rights reserved.
@@ -42,6 +49,9 @@ exports.parseSourceMap = parseSourceMap;
42
49
  ;
43
50
  ;
44
51
  ;
52
+ ;
53
+ ;
54
+ ;
45
55
  /**
46
56
  * Parses the {@link content} as JSON, ignoring BOM markers in the beginning, and
47
57
  * also handling the CORB bypass prefix correctly.
@@ -62,13 +72,15 @@ function parseSourceMap(content) {
62
72
  class SourceMapEntry {
63
73
  lineNumber;
64
74
  columnNumber;
75
+ sourceIndex;
65
76
  sourceURL;
66
77
  sourceLineNumber;
67
78
  sourceColumnNumber;
68
79
  name;
69
- constructor(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, name) {
80
+ constructor(lineNumber, columnNumber, sourceIndex, sourceURL, sourceLineNumber, sourceColumnNumber, name) {
70
81
  this.lineNumber = lineNumber;
71
82
  this.columnNumber = columnNumber;
83
+ this.sourceIndex = sourceIndex;
72
84
  this.sourceURL = sourceURL;
73
85
  this.sourceLineNumber = sourceLineNumber;
74
86
  this.sourceColumnNumber = sourceColumnNumber;
@@ -82,19 +94,15 @@ class SourceMapEntry {
82
94
  }
83
95
  }
84
96
  exports.SourceMapEntry = SourceMapEntry;
85
- const base64Digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
86
- const base64Map = new Map();
87
- for (let i = 0; i < base64Digits.length; ++i) {
88
- base64Map.set(base64Digits.charAt(i), i);
89
- }
90
- const sourceMapToSourceList = new WeakMap();
91
97
  class SourceMap {
92
98
  #json;
93
99
  #compiledURLInternal;
94
100
  #sourceMappingURL;
95
101
  #baseURL;
96
102
  #mappingsInternal;
97
- #sourceInfos;
103
+ #sourceInfos = [];
104
+ #sourceInfoByURL = new Map();
105
+ #scopesInfo = null;
98
106
  /**
99
107
  * Implements Source Map V3 model. See https://github.com/google/closure-compiler/wiki/Source-Maps
100
108
  * for format description.
@@ -103,9 +111,8 @@ class SourceMap {
103
111
  this.#json = payload;
104
112
  this.#compiledURLInternal = compiledURL;
105
113
  this.#sourceMappingURL = sourceMappingURL;
106
- this.#baseURL = (sourceMappingURL.startsWith('data:') ? compiledURL : sourceMappingURL);
114
+ this.#baseURL = (Common.ParsedURL.schemeIs(sourceMappingURL, 'data:')) ? compiledURL : sourceMappingURL;
107
115
  this.#mappingsInternal = null;
108
- this.#sourceInfos = new Map();
109
116
  if ('sections' in this.#json) {
110
117
  if (this.#json.sections.find(section => 'url' in section)) {
111
118
  console.warn(`SourceMap "${sourceMappingURL}" contains unsupported "URL" field in one of its sections.`);
@@ -113,6 +120,9 @@ class SourceMap {
113
120
  }
114
121
  this.eachSection(this.parseSources.bind(this));
115
122
  }
123
+ #sourceIndex(sourceURL) {
124
+ return this.#sourceInfos.findIndex(info => info.sourceURL === sourceURL);
125
+ }
116
126
  compiledURL() {
117
127
  return this.#compiledURLInternal;
118
128
  }
@@ -120,16 +130,40 @@ class SourceMap {
120
130
  return this.#sourceMappingURL;
121
131
  }
122
132
  sourceURLs() {
123
- return [...this.#sourceInfos.keys()];
133
+ return [...this.#sourceInfoByURL.keys()];
124
134
  }
125
135
  embeddedContentByURL(sourceURL) {
126
- const entry = this.#sourceInfos.get(sourceURL);
136
+ const entry = this.#sourceInfoByURL.get(sourceURL);
127
137
  if (!entry) {
128
138
  return null;
129
139
  }
130
140
  return entry.content;
131
141
  }
132
- findEntry(lineNumber, columnNumber) {
142
+ hasScopeInfo() {
143
+ this.#ensureMappingsProcessed();
144
+ return this.#scopesInfo !== null;
145
+ }
146
+ findEntry(lineNumber, columnNumber, inlineFrameIndex) {
147
+ this.#ensureMappingsProcessed();
148
+ if (inlineFrameIndex && this.#scopesInfo !== null) {
149
+ // For inlineFrameIndex != 0 we use the callsite info for the corresponding inlining site.
150
+ // Note that the callsite for "inlineFrameIndex" is actually in the previous frame.
151
+ const { inlinedFunctions } = this.#scopesInfo.findInlinedFunctions(lineNumber, columnNumber);
152
+ const { callsite } = inlinedFunctions[inlineFrameIndex - 1];
153
+ if (!callsite) {
154
+ console.error('Malformed source map. Expected to have a callsite info for index', inlineFrameIndex);
155
+ return null;
156
+ }
157
+ return {
158
+ lineNumber,
159
+ columnNumber,
160
+ sourceIndex: callsite.sourceIndex,
161
+ sourceURL: this.sourceURLs()[callsite.sourceIndex],
162
+ sourceLineNumber: callsite.line,
163
+ sourceColumnNumber: callsite.column,
164
+ name: undefined,
165
+ };
166
+ }
133
167
  const mappings = this.mappings();
134
168
  const index = Platform.ArrayUtilities.upperBound(mappings, undefined, (unused, entry) => lineNumber - entry.lineNumber || columnNumber - entry.columnNumber);
135
169
  return index ? mappings[index - 1] : null;
@@ -239,12 +273,18 @@ class SourceMap {
239
273
  }
240
274
  reversedMappings(sourceURL) {
241
275
  this.#ensureMappingsProcessed();
242
- return this.#sourceInfos.get(sourceURL)?.reverseMappings ?? [];
276
+ return this.#sourceInfoByURL.get(sourceURL)?.reverseMappings ?? [];
243
277
  }
244
278
  #ensureMappingsProcessed() {
245
279
  if (this.#mappingsInternal === null) {
246
280
  this.#mappingsInternal = [];
247
- this.eachSection(this.parseMap.bind(this));
281
+ try {
282
+ this.eachSection(this.parseMap.bind(this));
283
+ }
284
+ catch (e) {
285
+ console.error('Failed to parse source map', e);
286
+ this.#mappingsInternal = [];
287
+ }
248
288
  // As per spec, mappings are not necessarily sorted.
249
289
  this.mappings().sort(SourceMapEntry.compare);
250
290
  this.#computeReverseMappings(this.#mappingsInternal);
@@ -266,7 +306,7 @@ class SourceMap {
266
306
  reverseMap.push(i);
267
307
  }
268
308
  for (const [url, reverseMap] of reverseMappingsPerUrl.entries()) {
269
- const info = this.#sourceInfos.get(url);
309
+ const info = this.#sourceInfoByURL.get(url);
270
310
  if (!info) {
271
311
  continue;
272
312
  }
@@ -285,20 +325,21 @@ class SourceMap {
285
325
  return;
286
326
  }
287
327
  if ('sections' in this.#json) {
328
+ let sourcesIndex = 0;
288
329
  for (const section of this.#json.sections) {
289
330
  if ('map' in section) {
290
- callback(section.map, section.offset.line, section.offset.column);
331
+ callback(section.map, sourcesIndex, section.offset.line, section.offset.column);
332
+ sourcesIndex += section.map.sources.length;
291
333
  }
292
334
  }
293
335
  }
294
336
  else {
295
- callback(this.#json, 0, 0);
337
+ callback(this.#json, 0, 0, 0);
296
338
  }
297
339
  }
298
340
  parseSources(sourceMap) {
299
- const sourcesList = [];
300
341
  const sourceRoot = sourceMap.sourceRoot ?? '';
301
- const ignoreList = new Set(sourceMap.x_google_ignoreList);
342
+ const ignoreList = new Set(sourceMap.ignoreList ?? sourceMap.x_google_ignoreList);
302
343
  for (let i = 0; i < sourceMap.sources.length; ++i) {
303
344
  let href = sourceMap.sources[i];
304
345
  // The source map v3 proposal says to prepend the sourceRoot to the source URL
@@ -316,84 +357,83 @@ class SourceMap {
316
357
  }
317
358
  const url = '' || href;
318
359
  const source = sourceMap.sourcesContent && sourceMap.sourcesContent[i];
319
- sourcesList.push(url);
320
- if (!this.#sourceInfos.has(url)) {
321
- const content = source ?? null;
322
- const ignoreListHint = ignoreList.has(i);
323
- this.#sourceInfos.set(url, { content, ignoreListHint, reverseMappings: null });
360
+ const sourceInfo = {
361
+ sourceURL: url,
362
+ content: source ?? null,
363
+ ignoreListHint: ignoreList.has(i),
364
+ reverseMappings: null,
365
+ };
366
+ this.#sourceInfos.push(sourceInfo);
367
+ if (!this.#sourceInfoByURL.has(url)) {
368
+ this.#sourceInfoByURL.set(url, sourceInfo);
324
369
  }
325
370
  }
326
- sourceMapToSourceList.set(sourceMap, sourcesList);
327
371
  }
328
- parseMap(map, lineNumber, columnNumber) {
329
- let sourceIndex = 0;
372
+ parseMap(map, baseSourceIndex, baseLineNumber, baseColumnNumber) {
373
+ let sourceIndex = baseSourceIndex;
374
+ let lineNumber = baseLineNumber;
375
+ let columnNumber = baseColumnNumber;
330
376
  let sourceLineNumber = 0;
331
377
  let sourceColumnNumber = 0;
332
378
  let nameIndex = 0;
333
- // TODO(crbug.com/1011811): refactor away map.
334
- // `sources` can be undefined if it wasn't previously
335
- // processed and added to the list. However, that
336
- // is not WAI and we should make sure that we can
337
- // only reach this point when we are certain
338
- // we have the list available.
339
- const sources = sourceMapToSourceList.get(map);
340
379
  const names = map.names ?? [];
341
- const stringCharIterator = new SourceMap.StringCharIterator(map.mappings);
342
- let sourceURL = sources && sources[sourceIndex];
380
+ const tokenIter = new TokenIterator(map.mappings);
381
+ let sourceURL = this.#sourceInfos[sourceIndex].sourceURL;
343
382
  while (true) {
344
- if (stringCharIterator.peek() === ',') {
345
- stringCharIterator.next();
383
+ if (tokenIter.peek() === ',') {
384
+ tokenIter.next();
346
385
  }
347
386
  else {
348
- while (stringCharIterator.peek() === ';') {
387
+ while (tokenIter.peek() === ';') {
349
388
  lineNumber += 1;
350
389
  columnNumber = 0;
351
- stringCharIterator.next();
390
+ tokenIter.next();
352
391
  }
353
- if (!stringCharIterator.hasNext()) {
392
+ if (!tokenIter.hasNext()) {
354
393
  break;
355
394
  }
356
395
  }
357
- columnNumber += this.decodeVLQ(stringCharIterator);
358
- if (!stringCharIterator.hasNext() || this.isSeparator(stringCharIterator.peek())) {
396
+ columnNumber += tokenIter.nextVLQ();
397
+ if (!tokenIter.hasNext() || this.isSeparator(tokenIter.peek())) {
359
398
  this.mappings().push(new SourceMapEntry(lineNumber, columnNumber));
360
399
  continue;
361
400
  }
362
- const sourceIndexDelta = this.decodeVLQ(stringCharIterator);
401
+ const sourceIndexDelta = tokenIter.nextVLQ();
363
402
  if (sourceIndexDelta) {
364
403
  sourceIndex += sourceIndexDelta;
365
- if (sources) {
366
- sourceURL = sources[sourceIndex];
367
- }
404
+ sourceURL = this.#sourceInfos[sourceIndex].sourceURL;
368
405
  }
369
- sourceLineNumber += this.decodeVLQ(stringCharIterator);
370
- sourceColumnNumber += this.decodeVLQ(stringCharIterator);
371
- if (!stringCharIterator.hasNext() || this.isSeparator(stringCharIterator.peek())) {
372
- this.mappings().push(new SourceMapEntry(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber));
406
+ sourceLineNumber += tokenIter.nextVLQ();
407
+ sourceColumnNumber += tokenIter.nextVLQ();
408
+ if (!tokenIter.hasNext() || this.isSeparator(tokenIter.peek())) {
409
+ this.mappings().push(new SourceMapEntry(lineNumber, columnNumber, sourceIndex, sourceURL, sourceLineNumber, sourceColumnNumber));
373
410
  continue;
374
411
  }
375
- nameIndex += this.decodeVLQ(stringCharIterator);
376
- this.mappings().push(new SourceMapEntry(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, names[nameIndex]));
412
+ nameIndex += tokenIter.nextVLQ();
413
+ this.mappings().push(new SourceMapEntry(lineNumber, columnNumber, sourceIndex, sourceURL, sourceLineNumber, sourceColumnNumber, names[nameIndex]));
414
+ }
415
+ if (false) {
416
+ if (!this.#scopesInfo) {
417
+ this.#scopesInfo = new SourceMapScopesInfo_js_1.SourceMapScopesInfo(this, [], []);
418
+ }
419
+ if (map.originalScopes && map.generatedRanges) {
420
+ const { originalScopes, generatedRanges } = (0, SourceMapScopes_js_1.decodeScopes)(map, { line: baseLineNumber, column: baseColumnNumber });
421
+ this.#scopesInfo.addOriginalScopes(originalScopes);
422
+ this.#scopesInfo.addGeneratedRanges(generatedRanges);
423
+ }
424
+ else if (map.x_com_bloomberg_sourcesFunctionMappings) {
425
+ const originalScopes = this.parseBloombergScopes(map);
426
+ this.#scopesInfo.addOriginalScopes(originalScopes);
427
+ }
428
+ else {
429
+ // Keep the OriginalScope[] tree array consistent with sources.
430
+ this.#scopesInfo.addOriginalScopes(new Array(map.sources.length));
431
+ }
377
432
  }
378
433
  }
379
434
  isSeparator(char) {
380
435
  return char === ',' || char === ';';
381
436
  }
382
- decodeVLQ(stringCharIterator) {
383
- // Read unsigned value.
384
- let result = 0;
385
- let shift = 0;
386
- let digit = SourceMap._VLQ_CONTINUATION_MASK;
387
- while (digit & SourceMap._VLQ_CONTINUATION_MASK) {
388
- digit = base64Map.get(stringCharIterator.next()) || 0;
389
- result += (digit & SourceMap._VLQ_BASE_MASK) << shift;
390
- shift += SourceMap._VLQ_BASE_SHIFT;
391
- }
392
- // Fix the sign.
393
- const negative = result & 1;
394
- result >>= 1;
395
- return negative ? -result : result;
396
- }
397
437
  mapsOrigin() {
398
438
  const mappings = this.mappings();
399
439
  if (mappings.length > 0) {
@@ -403,7 +443,7 @@ class SourceMap {
403
443
  return false;
404
444
  }
405
445
  hasIgnoreListHint(sourceURL) {
406
- return this.#sourceInfos.get(sourceURL)?.ignoreListHint ?? false;
446
+ return this.#sourceInfoByURL.get(sourceURL)?.ignoreListHint ?? false;
407
447
  }
408
448
  /**
409
449
  * Returns a list of ranges in the generated script for original sources that
@@ -440,37 +480,89 @@ class SourceMap {
440
480
  }
441
481
  return ranges;
442
482
  }
483
+ expandCallFrame(frame) {
484
+ this.#ensureMappingsProcessed();
485
+ if (this.#scopesInfo === null) {
486
+ return [frame];
487
+ }
488
+ return this.#scopesInfo.expandCallFrame(frame);
489
+ }
490
+ resolveScopeChain(frame) {
491
+ this.#ensureMappingsProcessed();
492
+ if (this.#scopesInfo === null) {
493
+ return null;
494
+ }
495
+ return this.#scopesInfo.resolveMappedScopeChain(frame);
496
+ }
497
+ findOriginalFunctionName(position) {
498
+ this.#ensureMappingsProcessed();
499
+ return this.#scopesInfo?.findOriginalFunctionName(position) ?? null;
500
+ }
443
501
  }
444
502
  exports.SourceMap = SourceMap;
445
- (function (SourceMap) {
446
- // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
447
- // eslint-disable-next-line @typescript-eslint/naming-convention
448
- SourceMap._VLQ_BASE_SHIFT = 5;
449
- // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
450
- // eslint-disable-next-line @typescript-eslint/naming-convention
451
- SourceMap._VLQ_BASE_MASK = (1 << 5) - 1;
452
- // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
453
- // eslint-disable-next-line @typescript-eslint/naming-convention
454
- SourceMap._VLQ_CONTINUATION_MASK = 1 << 5;
455
- class StringCharIterator {
456
- string;
457
- position;
458
- constructor(string) {
459
- this.string = string;
460
- this.position = 0;
461
- }
462
- next() {
463
- return this.string.charAt(this.position++);
464
- }
465
- peek() {
466
- return this.string.charAt(this.position);
467
- }
468
- hasNext() {
469
- return this.position < this.string.length;
470
- }
471
- }
472
- SourceMap.StringCharIterator = StringCharIterator;
473
- })(SourceMap || (exports.SourceMap = SourceMap = {}));
503
+ const VLQ_BASE_SHIFT = 5;
504
+ const VLQ_BASE_MASK = (1 << 5) - 1;
505
+ const VLQ_CONTINUATION_MASK = 1 << 5;
506
+ class TokenIterator {
507
+ #string;
508
+ #position;
509
+ constructor(string) {
510
+ this.#string = string;
511
+ this.#position = 0;
512
+ }
513
+ next() {
514
+ return this.#string.charAt(this.#position++);
515
+ }
516
+ /** Returns the unicode value of the next character and advances the iterator */
517
+ nextCharCode() {
518
+ return this.#string.charCodeAt(this.#position++);
519
+ }
520
+ peek() {
521
+ return this.#string.charAt(this.#position);
522
+ }
523
+ hasNext() {
524
+ return this.#position < this.#string.length;
525
+ }
526
+ nextVLQ() {
527
+ // Read unsigned value.
528
+ let result = 0;
529
+ let shift = 0;
530
+ let digit = VLQ_CONTINUATION_MASK;
531
+ while (digit & VLQ_CONTINUATION_MASK) {
532
+ if (!this.hasNext()) {
533
+ throw new Error('Unexpected end of input while decodling VLQ number!');
534
+ }
535
+ const charCode = this.nextCharCode();
536
+ digit = BASE64_CODES[charCode];
537
+ if (charCode !== 65 /* 'A' */ && digit === 0) {
538
+ throw new Error(`Unexpected char '${String.fromCharCode(charCode)}' encountered while decoding`);
539
+ }
540
+ result += (digit & VLQ_BASE_MASK) << shift;
541
+ shift += VLQ_BASE_SHIFT;
542
+ }
543
+ // Fix the sign.
544
+ const negative = result & 1;
545
+ result >>= 1;
546
+ return negative ? -result : result;
547
+ }
548
+ /**
549
+ * @returns the next VLQ number without iterating further. Or returns null if
550
+ * the iterator is at the end or it's not a valid number.
551
+ */
552
+ peekVLQ() {
553
+ const pos = this.#position;
554
+ try {
555
+ return this.nextVLQ();
556
+ }
557
+ catch {
558
+ return null;
559
+ }
560
+ finally {
561
+ this.#position = pos; // Reset the iterator.
562
+ }
563
+ }
564
+ }
565
+ exports.TokenIterator = TokenIterator;
474
566
 
475
567
 
476
568
  module.exports = SourceMap;