lighthouse 8.5.1 → 8.6.0-dev.20211013

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 (172) hide show
  1. package/changelog.md +5490 -0
  2. package/flow-report/.eslintrc.cjs +49 -0
  3. package/flow-report/assets/styles.css +272 -9
  4. package/flow-report/jest.config.js +1 -1
  5. package/flow-report/package.json +4 -0
  6. package/flow-report/src/app.tsx +31 -9
  7. package/flow-report/src/common.tsx +86 -7
  8. package/flow-report/src/header.tsx +88 -0
  9. package/flow-report/src/help-dialog.tsx +120 -0
  10. package/flow-report/src/i18n/i18n.tsx +44 -0
  11. package/flow-report/src/i18n/localized-strings.js +11 -0
  12. package/flow-report/src/i18n/ui-strings.js +86 -0
  13. package/flow-report/src/icons.tsx +20 -3
  14. package/flow-report/src/sidebar/sidebar.tsx +11 -16
  15. package/flow-report/src/summary/category.tsx +42 -24
  16. package/flow-report/src/summary/summary.tsx +32 -29
  17. package/flow-report/src/topbar.tsx +54 -4
  18. package/flow-report/src/util.ts +26 -1
  19. package/flow-report/src/wrappers/report-renderer.tsx +1 -1
  20. package/flow-report/src/wrappers/report.tsx +6 -21
  21. package/flow-report/test/app-test.tsx +17 -13
  22. package/flow-report/test/common-test.tsx +89 -0
  23. package/flow-report/test/header-test.tsx +55 -0
  24. package/flow-report/test/sample-flow.ts +17 -0
  25. package/flow-report/test/setup/env-setup.ts +1 -0
  26. package/flow-report/test/sidebar/flow-test.tsx +6 -12
  27. package/flow-report/test/sidebar/sidebar-test.tsx +7 -13
  28. package/flow-report/test/summary/category-test.tsx +79 -34
  29. package/flow-report/test/summary/summary-test.tsx +11 -17
  30. package/flow-report/test/topbar-test.tsx +68 -0
  31. package/flow-report/test/util-test.tsx +1 -12
  32. package/flow-report/tsconfig.json +1 -0
  33. package/flow-report/types/flow-report.d.ts +2 -1
  34. package/jest.config.js +1 -15
  35. package/lighthouse-cli/bin.js +5 -0
  36. package/lighthouse-cli/cli-flags.js +10 -3
  37. package/lighthouse-cli/commands/commands.js +1 -0
  38. package/lighthouse-cli/commands/list-locales.js +16 -0
  39. package/lighthouse-cli/run.js +2 -2
  40. package/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +0 -0
  41. package/lighthouse-cli/test/smokehouse/report-assert.js +20 -4
  42. package/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +2 -1
  43. package/lighthouse-core/audits/byte-efficiency/unused-javascript.js +1 -1
  44. package/lighthouse-core/audits/seo/crawlable-anchors.js +10 -12
  45. package/lighthouse-core/computed/js-bundles.js +1 -2
  46. package/lighthouse-core/computed/unused-javascript-summary.js +3 -3
  47. package/lighthouse-core/config/config.js +2 -2
  48. package/lighthouse-core/config/default-config.js +5 -0
  49. package/lighthouse-core/fraggle-rock/api.js +10 -0
  50. package/lighthouse-core/fraggle-rock/config/filters.js +22 -3
  51. package/lighthouse-core/fraggle-rock/gather/driver.js +4 -0
  52. package/lighthouse-core/fraggle-rock/gather/navigation-runner.js +2 -2
  53. package/lighthouse-core/fraggle-rock/user-flow.js +35 -6
  54. package/lighthouse-core/gather/driver/navigation.js +5 -0
  55. package/lighthouse-core/gather/driver/prepare.js +14 -0
  56. package/lighthouse-core/gather/driver/storage.js +5 -0
  57. package/lighthouse-core/gather/gather-runner.js +2 -2
  58. package/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js +5 -1
  59. package/lighthouse-core/gather/gatherers/full-page-screenshot.js +30 -24
  60. package/lighthouse-core/lib/cdt/Platform.js +55 -0
  61. package/lighthouse-core/lib/cdt/SDK.js +3 -123
  62. package/lighthouse-core/lib/cdt/generated/SourceMap.js +148 -312
  63. package/lighthouse-core/lib/csp-evaluator.js +2 -1
  64. package/lighthouse-core/lib/i18n/README.md +6 -6
  65. package/lighthouse-core/lib/i18n/i18n.js +9 -342
  66. package/lighthouse-core/lib/page-functions.js +4 -4
  67. package/lighthouse-core/lib/stack-packs.js +1 -13
  68. package/lighthouse-core/runner.js +6 -6
  69. package/lighthouse-core/scripts/manual-chrome-launcher.js +4 -1
  70. package/lighthouse-core/scripts/package.json +4 -0
  71. package/lighthouse-core/util-commonjs.js +20 -4
  72. package/package.json +19 -16
  73. package/readme.md +1 -1
  74. package/report/assets/standalone-template.html +0 -1
  75. package/report/assets/styles.css +16 -41
  76. package/report/assets/templates.html +42 -4
  77. package/report/clients/psi.js +1 -0
  78. package/report/clients/standalone.js +1 -2
  79. package/report/generator/file-namer.js +17 -8
  80. package/report/generator/report-generator.js +0 -1
  81. package/report/renderer/category-renderer.js +4 -16
  82. package/report/renderer/components.js +107 -71
  83. package/report/renderer/dom.js +19 -0
  84. package/report/renderer/logger.js +35 -2
  85. package/report/renderer/performance-category-renderer.js +23 -21
  86. package/report/renderer/pwa-category-renderer.js +1 -2
  87. package/report/renderer/report-renderer.js +21 -0
  88. package/report/renderer/report-ui-features.js +7 -19
  89. package/report/renderer/swap-locale-feature.js +82 -0
  90. package/report/renderer/util.js +20 -4
  91. package/report/test/clients/psi-test.js +0 -4
  92. package/report/test/generator/file-namer-test.js +2 -2
  93. package/report/test/renderer/category-renderer-test.js +1 -1
  94. package/report/test/renderer/performance-category-renderer-test.js +12 -0
  95. package/report/test/renderer/report-renderer-axe-test.js +86 -0
  96. package/report/test/renderer/report-renderer-test.js +0 -55
  97. package/report/test/renderer/util-test.js +68 -8
  98. package/report/test-assets/faux-psi-template.html +0 -1
  99. package/report/tsconfig.json +2 -1
  100. package/report/types/html-renderer.d.ts +2 -1
  101. package/root.js +18 -0
  102. package/shared/localization/format.js +422 -0
  103. package/{lighthouse-core/lib/cdt/Common.js → shared/localization/i18n-module.js} +3 -8
  104. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ar-XB.json +139 -4
  105. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ar.json +141 -6
  106. package/{lighthouse-core/lib/i18n → shared/localization}/locales/bg.json +139 -4
  107. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ca.json +140 -5
  108. package/{lighthouse-core/lib/i18n → shared/localization}/locales/cs.json +139 -4
  109. package/{lighthouse-core/lib/i18n → shared/localization}/locales/da.json +139 -4
  110. package/{lighthouse-core/lib/i18n → shared/localization}/locales/de.json +139 -4
  111. package/{lighthouse-core/lib/i18n → shared/localization}/locales/el.json +141 -6
  112. package/{lighthouse-core/lib/i18n → shared/localization}/locales/en-GB.json +139 -4
  113. package/{lighthouse-core/lib/i18n → shared/localization}/locales/en-US.json +111 -0
  114. package/{lighthouse-core/lib/i18n → shared/localization}/locales/en-XA.json +139 -4
  115. package/{lighthouse-core/lib/i18n → shared/localization}/locales/en-XL.json +111 -0
  116. package/{lighthouse-core/lib/i18n → shared/localization}/locales/es-419.json +139 -4
  117. package/{lighthouse-core/lib/i18n → shared/localization}/locales/es.json +139 -4
  118. package/{lighthouse-core/lib/i18n → shared/localization}/locales/fi.json +139 -4
  119. package/{lighthouse-core/lib/i18n → shared/localization}/locales/fil.json +139 -4
  120. package/{lighthouse-core/lib/i18n → shared/localization}/locales/fr.json +139 -4
  121. package/{lighthouse-core/lib/i18n → shared/localization}/locales/he.json +139 -4
  122. package/{lighthouse-core/lib/i18n → shared/localization}/locales/hi.json +142 -7
  123. package/{lighthouse-core/lib/i18n → shared/localization}/locales/hr.json +139 -4
  124. package/{lighthouse-core/lib/i18n → shared/localization}/locales/hu.json +139 -4
  125. package/{lighthouse-core/lib/i18n → shared/localization}/locales/id.json +139 -4
  126. package/{lighthouse-core/lib/i18n → shared/localization}/locales/it.json +139 -4
  127. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ja.json +139 -4
  128. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ko.json +139 -4
  129. package/{lighthouse-core/lib/i18n → shared/localization}/locales/lt.json +139 -4
  130. package/{lighthouse-core/lib/i18n → shared/localization}/locales/lv.json +139 -4
  131. package/{lighthouse-core/lib/i18n → shared/localization}/locales/nl.json +139 -4
  132. package/{lighthouse-core/lib/i18n → shared/localization}/locales/no.json +139 -4
  133. package/{lighthouse-core/lib/i18n → shared/localization}/locales/pl.json +139 -4
  134. package/{lighthouse-core/lib/i18n → shared/localization}/locales/pt-PT.json +139 -4
  135. package/{lighthouse-core/lib/i18n → shared/localization}/locales/pt.json +139 -4
  136. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ro.json +139 -4
  137. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ru.json +139 -4
  138. package/{lighthouse-core/lib/i18n → shared/localization}/locales/sk.json +139 -4
  139. package/{lighthouse-core/lib/i18n → shared/localization}/locales/sl.json +139 -4
  140. package/{lighthouse-core/lib/i18n → shared/localization}/locales/sr-Latn.json +139 -4
  141. package/{lighthouse-core/lib/i18n → shared/localization}/locales/sr.json +139 -4
  142. package/{lighthouse-core/lib/i18n → shared/localization}/locales/sv.json +139 -4
  143. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ta.json +146 -11
  144. package/{lighthouse-core/lib/i18n → shared/localization}/locales/te.json +179 -44
  145. package/{lighthouse-core/lib/i18n → shared/localization}/locales/th.json +139 -4
  146. package/{lighthouse-core/lib/i18n → shared/localization}/locales/tr.json +139 -4
  147. package/{lighthouse-core/lib/i18n → shared/localization}/locales/uk.json +139 -4
  148. package/{lighthouse-core/lib/i18n → shared/localization}/locales/vi.json +139 -4
  149. package/{lighthouse-core/lib/i18n → shared/localization}/locales/zh-HK.json +139 -4
  150. package/{lighthouse-core/lib/i18n → shared/localization}/locales/zh-TW.json +139 -4
  151. package/{lighthouse-core/lib/i18n → shared/localization}/locales/zh.json +139 -4
  152. package/{lighthouse-core/lib/i18n → shared/localization}/locales.js +2 -1
  153. package/shared/localization/swap-flow-locale.js +20 -0
  154. package/{lighthouse-core/lib/i18n → shared/localization}/swap-locale.js +9 -7
  155. package/shared/test/localization/format-test.js +377 -0
  156. package/shared/test/localization/locales-test.js +47 -0
  157. package/shared/test/localization/swap-locale-test.js +140 -0
  158. package/shared/tsconfig.json +22 -0
  159. package/{lighthouse-core/lib → shared}/type-verifiers.js +0 -0
  160. package/shared/types/shared.d.ts +24 -0
  161. package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +5 -3
  162. package/third-party/chromium-synchronization/installability-errors-test.js +2 -1
  163. package/tsconfig-all.json +1 -0
  164. package/tsconfig-base.json +1 -1
  165. package/tsconfig.json +2 -3
  166. package/types/config.d.ts +1 -0
  167. package/types/es-main.d.ts +18 -0
  168. package/types/externs.d.ts +2 -0
  169. package/types/lhr/flow.d.ts +7 -0
  170. package/types/lhr/i18n.d.ts +0 -3
  171. package/dist/report/flow.js +0 -149
  172. package/dist/report/standalone.js +0 -228
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck
2
2
  // generated by yarn build-cdt-lib
3
- const Common = require('../Common.js')
3
+ const Platform = require('../Platform.js');
4
4
  "use strict";
5
5
  /*
6
6
  * Copyright (C) 2012 Google Inc. All rights reserved.
@@ -32,100 +32,32 @@ const Common = require('../Common.js')
32
32
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
33
  */
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
-
36
- /**
37
- * @interface
38
- */
39
- class SourceMap {
40
- /**
41
- * @return {string}
42
- */
43
- compiledURL() {
44
- }
45
- /**
46
- * @return {string}
47
- */
48
- url() {
49
- }
50
- /**
51
- * @return {!Array<string>}
52
- */
53
- sourceURLs() {
54
- }
55
- /**
56
- * @param {string} sourceURL
57
- * @return {?string}
58
- */
59
- embeddedContentByURL(sourceURL) {
60
- }
61
- /**
62
- * @param {number} lineNumber in compiled resource
63
- * @param {number} columnNumber in compiled resource
64
- * @return {?SourceMapEntry}
65
- */
66
- findEntry(lineNumber, columnNumber) {
67
- }
68
- /**
69
- * @param {string} sourceURL
70
- * @param {number} lineNumber
71
- * @param {number} columnNumber
72
- * @return {?SourceMapEntry}
73
- */
74
- sourceLineMapping(sourceURL, lineNumber, columnNumber) {
75
- }
76
- /**
77
- * @return {!Array<!SourceMapEntry>}
78
- */
79
- mappings() {
80
- }
81
- dispose() {
82
- }
83
- }
84
-
85
- /**
86
- * @unrestricted
87
- */
35
+ exports.TextSourceMap = exports.SourceMapEntry = exports.Offset = exports.Section = exports.SourceMapV3 = void 0;
36
+ ;
37
+ ;
38
+ ;
39
+ ;
40
+ ;
41
+ ;
42
+ ;
43
+ ;
44
+ ;
88
45
  class SourceMapV3 {
89
46
  constructor() {
90
- /** @type {number} */ this.version;
91
- /** @type {string|undefined} */ this.file;
92
- /** @type {!Array.<string>} */ this.sources;
93
- /** @type {!Array.<!SourceMapV3.Section>|undefined} */ this.sections;
94
- /** @type {string} */ this.mappings;
95
- /** @type {string|undefined} */ this.sourceRoot;
96
- /** @type {!Array.<string>|undefined} */ this.names;
97
47
  }
98
48
  }
99
- /**
100
- * @unrestricted
101
- */
102
- SourceMapV3.Section = class {
49
+ exports.SourceMapV3 = SourceMapV3;
50
+ class Section {
103
51
  constructor() {
104
- /** @type {!SourceMapV3} */ this.map;
105
- /** @type {!SourceMapV3.Offset} */ this.offset;
106
52
  }
107
- };
108
- /**
109
- * @unrestricted
110
- */
111
- SourceMapV3.Offset = class {
53
+ }
54
+ exports.Section = Section;
55
+ class Offset {
112
56
  constructor() {
113
- /** @type {number} */ this.line;
114
- /** @type {number} */ this.column;
115
57
  }
116
- };
117
- /**
118
- * @unrestricted
119
- */
58
+ }
59
+ exports.Offset = Offset;
120
60
  class SourceMapEntry {
121
- /**
122
- * @param {number} lineNumber
123
- * @param {number} columnNumber
124
- * @param {string=} sourceURL
125
- * @param {number=} sourceLineNumber
126
- * @param {number=} sourceColumnNumber
127
- * @param {string=} name
128
- */
129
61
  constructor(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, name) {
130
62
  this.lineNumber = lineNumber;
131
63
  this.columnNumber = columnNumber;
@@ -134,11 +66,6 @@ class SourceMapEntry {
134
66
  this.sourceColumnNumber = sourceColumnNumber;
135
67
  this.name = name;
136
68
  }
137
- /**
138
- * @param {!SourceMapEntry} entry1
139
- * @param {!SourceMapEntry} entry2
140
- * @return {number}
141
- */
142
69
  static compare(entry1, entry2) {
143
70
  if (entry1.lineNumber !== entry2.lineNumber) {
144
71
  return entry1.lineNumber - entry2.lineNumber;
@@ -146,99 +73,59 @@ class SourceMapEntry {
146
73
  return entry1.columnNumber - entry2.columnNumber;
147
74
  }
148
75
  }
149
-
150
-
151
-
152
- /**
153
- * @implements {SourceMap}
154
- * @unrestricted
155
- */
76
+ exports.SourceMapEntry = SourceMapEntry;
77
+ const base64Digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
78
+ const base64Map = new Map();
79
+ for (let i = 0; i < base64Digits.length; ++i) {
80
+ base64Map.set(base64Digits.charAt(i), i);
81
+ }
82
+ const sourceMapToSourceList = new WeakMap();
156
83
  class TextSourceMap {
157
84
  /**
158
85
  * Implements Source Map V3 model. See https://github.com/google/closure-compiler/wiki/Source-Maps
159
86
  * for format description.
160
- * @param {string} compiledURL
161
- * @param {string} sourceMappingURL
162
- * @param {!SourceMapV3} payload
163
87
  */
164
- constructor(compiledURL, sourceMappingURL, payload) {
165
- if (!TextSourceMap._base64Map) {
166
- const base64Digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
167
- TextSourceMap._base64Map = {};
168
- for (let i = 0; i < base64Digits.length; ++i) {
169
- TextSourceMap._base64Map[base64Digits.charAt(i)] = i;
170
- }
171
- }
172
- this._json = payload;
173
- this._compiledURL = compiledURL;
174
- this._sourceMappingURL = sourceMappingURL;
175
- this._baseURL = sourceMappingURL.startsWith('data:') ? compiledURL : sourceMappingURL;
176
- /** @type {?Array<!SourceMapEntry>} */
177
- this._mappings = null;
178
- /** @type {!Map<string, !TextSourceMap.SourceInfo>} */
179
- this._sourceInfos = new Map();
180
- if (this._json.sections) {
181
- const sectionWithURL = !!this._json.sections.find(section => !!section.url);
88
+ constructor(compiledURL, sourceMappingURL, payload, initiator) {
89
+ this.initiator = initiator;
90
+ this.json = payload;
91
+ this.compiledURLInternal = compiledURL;
92
+ this.sourceMappingURL = sourceMappingURL;
93
+ this.baseURL = sourceMappingURL.startsWith('data:') ? compiledURL : sourceMappingURL;
94
+ this.mappingsInternal = null;
95
+ this.sourceInfos = new Map();
96
+ if (this.json.sections) {
97
+ const sectionWithURL = Boolean(this.json.sections.find(section => Boolean(section.url)));
182
98
  if (sectionWithURL) {
183
- Common.console.warn(`SourceMap "${sourceMappingURL}" contains unsupported "URL" field in one of its sections.`);
99
+ console.warn(`SourceMap "${sourceMappingURL}" contains unsupported "URL" field in one of its sections.`);
184
100
  }
185
101
  }
186
- this._eachSection(this._parseSources.bind(this));
102
+ this.eachSection(this.parseSources.bind(this));
187
103
  }
188
- /**
189
- * @override
190
- * @return {string}
191
- */
192
104
  compiledURL() {
193
- return this._compiledURL;
105
+ return this.compiledURLInternal;
194
106
  }
195
- /**
196
- * @override
197
- * @return {string}
198
- */
199
107
  url() {
200
- return this._sourceMappingURL;
108
+ return this.sourceMappingURL;
201
109
  }
202
- /**
203
- * @override
204
- * @return {!Array.<string>}
205
- */
206
110
  sourceURLs() {
207
- return this._sourceInfos.keysArray();
111
+ return [...this.sourceInfos.keys()];
208
112
  }
209
- /**
210
- * @override
211
- * @param {string} sourceURL
212
- * @return {?string}
213
- */
214
113
  embeddedContentByURL(sourceURL) {
215
- if (!this._sourceInfos.has(sourceURL)) {
114
+ const entry = this.sourceInfos.get(sourceURL);
115
+ if (!entry) {
216
116
  return null;
217
117
  }
218
- return this._sourceInfos.get(sourceURL).content;
118
+ return entry.content;
219
119
  }
220
- /**
221
- * @override
222
- * @param {number} lineNumber in compiled resource
223
- * @param {number} columnNumber in compiled resource
224
- * @return {?SourceMapEntry}
225
- */
226
120
  findEntry(lineNumber, columnNumber) {
227
121
  const mappings = this.mappings();
228
- const index = mappings.upperBound(undefined, (unused, entry) => lineNumber - entry.lineNumber || columnNumber - entry.columnNumber);
122
+ const index = Platform.ArrayUtilities.upperBound(mappings, undefined, (unused, entry) => lineNumber - entry.lineNumber || columnNumber - entry.columnNumber);
229
123
  return index ? mappings[index - 1] : null;
230
124
  }
231
- /**
232
- * @override
233
- * @param {string} sourceURL
234
- * @param {number} lineNumber
235
- * @param {number} columnNumber
236
- * @return {?SourceMapEntry}
237
- */
238
125
  sourceLineMapping(sourceURL, lineNumber, columnNumber) {
239
- const mappings = this._reversedMappings(sourceURL);
240
- const first = mappings.lowerBound(lineNumber, lineComparator);
241
- const last = mappings.upperBound(lineNumber, lineComparator);
126
+ const mappings = this.reversedMappings(sourceURL);
127
+ const first = Platform.ArrayUtilities.lowerBound(mappings, lineNumber, lineComparator);
128
+ const last = Platform.ArrayUtilities.upperBound(mappings, lineNumber, lineComparator);
242
129
  if (first >= mappings.length || mappings[first].sourceLineNumber !== lineNumber) {
243
130
  return null;
244
131
  }
@@ -246,26 +133,15 @@ class TextSourceMap {
246
133
  if (!columnMappings.length) {
247
134
  return null;
248
135
  }
249
- const index = columnMappings.lowerBound(columnNumber, (columnNumber, mapping) => columnNumber - mapping.sourceColumnNumber);
136
+ const index = Platform.ArrayUtilities.lowerBound(columnMappings, columnNumber, (columnNumber, mapping) => columnNumber - mapping.sourceColumnNumber);
250
137
  return index >= columnMappings.length ? columnMappings[columnMappings.length - 1] : columnMappings[index];
251
- /**
252
- * @param {number} lineNumber
253
- * @param {!SourceMapEntry} mapping
254
- * @return {number}
255
- */
256
138
  function lineComparator(lineNumber, mapping) {
257
139
  return lineNumber - mapping.sourceLineNumber;
258
140
  }
259
141
  }
260
- /**
261
- * @param {string} sourceURL
262
- * @param {number} lineNumber
263
- * @param {number} columnNumber
264
- * @return {!Array<!SourceMapEntry>}
265
- */
266
142
  findReverseEntries(sourceURL, lineNumber, columnNumber) {
267
- const mappings = this._reversedMappings(sourceURL);
268
- const endIndex = mappings.upperBound(undefined, (unused, entry) => lineNumber - entry.sourceLineNumber || columnNumber - entry.sourceColumnNumber);
143
+ const mappings = this.reversedMappings(sourceURL);
144
+ const endIndex = Platform.ArrayUtilities.upperBound(mappings, undefined, (unused, entry) => lineNumber - entry.sourceLineNumber || columnNumber - entry.sourceColumnNumber);
269
145
  let startIndex = endIndex;
270
146
  while (startIndex > 0 && mappings[startIndex - 1].sourceLineNumber === mappings[endIndex - 1].sourceLineNumber &&
271
147
  mappings[startIndex - 1].sourceColumnNumber === mappings[endIndex - 1].sourceColumnNumber) {
@@ -273,37 +149,25 @@ class TextSourceMap {
273
149
  }
274
150
  return mappings.slice(startIndex, endIndex);
275
151
  }
276
- /**
277
- * @override
278
- * @return {!Array<!SourceMapEntry>}
279
- */
280
- mappings() {
281
- if (this._mappings === null) {
282
- this._mappings = [];
283
- this._eachSection(this._parseMap.bind(this));
284
- this._json = null;
152
+ /** @return {Array<{lineNumber: number, columnNumber: number, sourceURL?: string, sourceLineNumber, sourceColumnNumber: number, name?: string, lastColumnNumber?: number}>} */
153
+ mappings() {
154
+ if (this.mappingsInternal === null) {
155
+ this.mappingsInternal = [];
156
+ this.eachSection(this.parseMap.bind(this));
157
+ this.json = null;
285
158
  }
286
- return /** @type {!Array<!SourceMapEntry>} */ (this._mappings);
159
+ return /** @type {!Array<!SourceMapEntry>} */ this.mappingsInternal;
287
160
  }
288
- /**
289
- * @param {string} sourceURL
290
- * @return {!Array.<!SourceMapEntry>}
291
- */
292
- _reversedMappings(sourceURL) {
293
- if (!this._sourceInfos.has(sourceURL)) {
161
+ reversedMappings(sourceURL) {
162
+ const info = this.sourceInfos.get(sourceURL);
163
+ if (!info) {
294
164
  return [];
295
165
  }
296
166
  const mappings = this.mappings();
297
- const info = this._sourceInfos.get(sourceURL);
298
167
  if (info.reverseMappings === null) {
299
168
  info.reverseMappings = mappings.filter(mapping => mapping.sourceURL === sourceURL).sort(sourceMappingComparator);
300
169
  }
301
170
  return info.reverseMappings;
302
- /**
303
- * @param {!SourceMapEntry} a
304
- * @param {!SourceMapEntry} b
305
- * @return {number}
306
- */
307
171
  function sourceMappingComparator(a, b) {
308
172
  if (a.sourceLineNumber !== b.sourceLineNumber) {
309
173
  return a.sourceLineNumber - b.sourceLineNumber;
@@ -317,22 +181,19 @@ class TextSourceMap {
317
181
  return a.columnNumber - b.columnNumber;
318
182
  }
319
183
  }
320
- /**
321
- * @param {function(!SourceMapV3, number, number)} callback
322
- */
323
- _eachSection(callback) {
324
- if (!this._json.sections) {
325
- callback(this._json, 0, 0);
184
+ eachSection(callback) {
185
+ if (!this.json) {
186
+ return;
187
+ }
188
+ if (!this.json.sections) {
189
+ callback(this.json, 0, 0);
326
190
  return;
327
191
  }
328
- for (const section of this._json.sections) {
192
+ for (const section of this.json.sections) {
329
193
  callback(section.map, section.offset.line, section.offset.column);
330
194
  }
331
195
  }
332
- /**
333
- * @param {!SourceMapV3} sourceMap
334
- */
335
- _parseSources(sourceMap) {
196
+ parseSources(sourceMap) {
336
197
  const sourcesList = [];
337
198
  let sourceRoot = sourceMap.sourceRoot || '';
338
199
  if (sourceRoot && !sourceRoot.endsWith('/')) {
@@ -342,27 +203,28 @@ class TextSourceMap {
342
203
  const href = sourceRoot + sourceMap.sources[i];
343
204
  let url = '' || href;
344
205
  const source = sourceMap.sourcesContent && sourceMap.sourcesContent[i];
345
- if (url === this._compiledURL && source) {
206
+ if (url === this.compiledURLInternal && source) {
346
207
  }
347
- this._sourceInfos.set(url, new TextSourceMap.SourceInfo(source, null));
208
+ this.sourceInfos.set(url, new TextSourceMap.SourceInfo(source || null, null));
348
209
  sourcesList.push(url);
349
210
  }
350
- sourceMap[TextSourceMap._sourcesListSymbol] = sourcesList;
211
+ sourceMapToSourceList.set(sourceMap, sourcesList);
351
212
  }
352
- /**
353
- * @param {!SourceMapV3} map
354
- * @param {number} lineNumber
355
- * @param {number} columnNumber
356
- */
357
- _parseMap(map, lineNumber, columnNumber) {
213
+ parseMap(map, lineNumber, columnNumber) {
358
214
  let sourceIndex = 0;
359
215
  let sourceLineNumber = 0;
360
216
  let sourceColumnNumber = 0;
361
217
  let nameIndex = 0;
362
- const sources = map[TextSourceMap._sourcesListSymbol];
218
+ // TODO(crbug.com/1011811): refactor away map.
219
+ // `sources` can be undefined if it wasn't previously
220
+ // processed and added to the list. However, that
221
+ // is not WAI and we should make sure that we can
222
+ // only reach this point when we are certain
223
+ // we have the list available.
224
+ const sources = sourceMapToSourceList.get(map);
363
225
  const names = map.names || [];
364
226
  const stringCharIterator = new TextSourceMap.StringCharIterator(map.mappings);
365
- let sourceURL = sources[sourceIndex];
227
+ let sourceURL = sources && sources[sourceIndex];
366
228
  while (true) {
367
229
  if (stringCharIterator.peek() === ',') {
368
230
  stringCharIterator.next();
@@ -377,134 +239,108 @@ class TextSourceMap {
377
239
  break;
378
240
  }
379
241
  }
380
- columnNumber += this._decodeVLQ(stringCharIterator);
381
- if (!stringCharIterator.hasNext() || this._isSeparator(stringCharIterator.peek())) {
382
- this._mappings.push(new SourceMapEntry(lineNumber, columnNumber));
242
+ columnNumber += this.decodeVLQ(stringCharIterator);
243
+ if (!stringCharIterator.hasNext() || this.isSeparator(stringCharIterator.peek())) {
244
+ this.mappings().push(new SourceMapEntry(lineNumber, columnNumber));
383
245
  continue;
384
246
  }
385
- const sourceIndexDelta = this._decodeVLQ(stringCharIterator);
247
+ const sourceIndexDelta = this.decodeVLQ(stringCharIterator);
386
248
  if (sourceIndexDelta) {
387
249
  sourceIndex += sourceIndexDelta;
388
- sourceURL = sources[sourceIndex];
250
+ if (sources) {
251
+ sourceURL = sources[sourceIndex];
252
+ }
389
253
  }
390
- sourceLineNumber += this._decodeVLQ(stringCharIterator);
391
- sourceColumnNumber += this._decodeVLQ(stringCharIterator);
392
- if (!stringCharIterator.hasNext() || this._isSeparator(stringCharIterator.peek())) {
393
- this._mappings.push(new SourceMapEntry(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber));
254
+ sourceLineNumber += this.decodeVLQ(stringCharIterator);
255
+ sourceColumnNumber += this.decodeVLQ(stringCharIterator);
256
+ if (!stringCharIterator.hasNext() || this.isSeparator(stringCharIterator.peek())) {
257
+ this.mappings().push(new SourceMapEntry(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber));
394
258
  continue;
395
259
  }
396
- nameIndex += this._decodeVLQ(stringCharIterator);
397
- this._mappings.push(new SourceMapEntry(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, names[nameIndex]));
260
+ nameIndex += this.decodeVLQ(stringCharIterator);
261
+ this.mappings().push(new SourceMapEntry(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, names[nameIndex]));
398
262
  }
399
263
  // As per spec, mappings are not necessarily sorted.
400
- this._mappings.sort(SourceMapEntry.compare);
264
+ this.mappings().sort(SourceMapEntry.compare);
401
265
  }
402
- /**
403
- * @param {string} char
404
- * @return {boolean}
405
- */
406
- _isSeparator(char) {
266
+ isSeparator(char) {
407
267
  return char === ',' || char === ';';
408
268
  }
409
- /**
410
- * @param {!TextSourceMap.StringCharIterator} stringCharIterator
411
- * @return {number}
412
- */
413
- _decodeVLQ(stringCharIterator) {
269
+ decodeVLQ(stringCharIterator) {
414
270
  // Read unsigned value.
415
271
  let result = 0;
416
272
  let shift = 0;
417
- let digit;
418
- do {
419
- digit = TextSourceMap._base64Map[stringCharIterator.next()];
273
+ let digit = TextSourceMap._VLQ_CONTINUATION_MASK;
274
+ while (digit & TextSourceMap._VLQ_CONTINUATION_MASK) {
275
+ digit = base64Map.get(stringCharIterator.next()) || 0;
420
276
  result += (digit & TextSourceMap._VLQ_BASE_MASK) << shift;
421
277
  shift += TextSourceMap._VLQ_BASE_SHIFT;
422
- } while (digit & TextSourceMap._VLQ_CONTINUATION_MASK);
278
+ }
423
279
  // Fix the sign.
424
280
  const negative = result & 1;
425
281
  result >>= 1;
426
282
  return negative ? -result : result;
427
283
  }
428
- /**
429
- * @param {string} url
430
- * @param {!TextUtils.TextRange} textRange
431
- * @return {!TextUtils.TextRange}
432
- */
433
284
  reverseMapTextRange(url, textRange) {
434
- /**
435
- * @param {!{lineNumber: number, columnNumber: number}} position
436
- * @param {!SourceMapEntry} mapping
437
- * @return {number}
438
- */
439
285
  function comparator(position, mapping) {
440
286
  if (position.lineNumber !== mapping.sourceLineNumber) {
441
287
  return position.lineNumber - mapping.sourceLineNumber;
442
288
  }
443
289
  return position.columnNumber - mapping.sourceColumnNumber;
444
290
  }
445
- const mappings = this._reversedMappings(url);
446
- const startIndex = mappings.lowerBound({ lineNumber: textRange.startLine, columnNumber: textRange.startColumn }, comparator);
447
- const endIndex = mappings.upperBound({ lineNumber: textRange.endLine, columnNumber: textRange.endColumn }, comparator);
291
+ const mappings = this.reversedMappings(url);
292
+ if (!mappings.length) {
293
+ return null;
294
+ }
295
+ const startIndex = Platform.ArrayUtilities.lowerBound(mappings, { lineNumber: textRange.startLine, columnNumber: textRange.startColumn }, comparator);
296
+ const endIndex = Platform.ArrayUtilities.upperBound(mappings, { lineNumber: textRange.endLine, columnNumber: textRange.endColumn }, comparator);
448
297
  const startMapping = mappings[startIndex];
449
298
  const endMapping = mappings[endIndex];
450
- return new TextUtils.TextRange(startMapping.lineNumber, startMapping.columnNumber, endMapping.lineNumber, endMapping.columnNumber);
299
+ return new TextUtils.TextRange.TextRange(startMapping.lineNumber, startMapping.columnNumber, endMapping.lineNumber, endMapping.columnNumber);
451
300
  }
452
- /**
453
- * @override
454
- */
455
- dispose() {
301
+ mapsOrigin() {
302
+ const mappings = this.mappings();
303
+ if (mappings.length > 0) {
304
+ const firstEntry = mappings[0];
305
+ return (firstEntry === null || firstEntry === void 0 ? void 0 : firstEntry.lineNumber) === 0 || firstEntry.columnNumber === 0;
306
+ }
307
+ return false;
456
308
  }
457
309
  }
458
-
459
- TextSourceMap._VLQ_BASE_SHIFT = 5;
460
- TextSourceMap._VLQ_BASE_MASK = (1 << 5) - 1;
461
- TextSourceMap._VLQ_CONTINUATION_MASK = 1 << 5;
462
- /**
463
- * @unrestricted
464
- */
465
- TextSourceMap.StringCharIterator = class {
466
- /**
467
- * @param {string} string
468
- */
469
- constructor(string) {
470
- this._string = string;
471
- this._position = 0;
472
- }
473
- /**
474
- * @return {string}
475
- */
476
- next() {
477
- return this._string.charAt(this._position++);
478
- }
479
- /**
480
- * @return {string}
481
- */
482
- peek() {
483
- return this._string.charAt(this._position);
484
- }
485
- /**
486
- * @return {boolean}
487
- */
488
- hasNext() {
489
- return this._position < this._string.length;
310
+ exports.TextSourceMap = TextSourceMap;
311
+ (function (TextSourceMap) {
312
+ // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
313
+ // eslint-disable-next-line @typescript-eslint/naming-convention
314
+ TextSourceMap._VLQ_BASE_SHIFT = 5;
315
+ // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
316
+ // eslint-disable-next-line @typescript-eslint/naming-convention
317
+ TextSourceMap._VLQ_BASE_MASK = (1 << 5) - 1;
318
+ // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
319
+ // eslint-disable-next-line @typescript-eslint/naming-convention
320
+ TextSourceMap._VLQ_CONTINUATION_MASK = 1 << 5;
321
+ class StringCharIterator {
322
+ constructor(string) {
323
+ this.string = string;
324
+ this.position = 0;
325
+ }
326
+ next() {
327
+ return this.string.charAt(this.position++);
328
+ }
329
+ peek() {
330
+ return this.string.charAt(this.position);
331
+ }
332
+ hasNext() {
333
+ return this.position < this.string.length;
334
+ }
490
335
  }
491
- };
492
- /**
493
- * @unrestricted
494
- */
495
- TextSourceMap.SourceInfo = class {
496
- /**
497
- * @param {?string} content
498
- * @param {?Array<!SourceMapEntry>} reverseMappings
499
- */
500
- constructor(content, reverseMappings) {
501
- this.content = content;
502
- this.reverseMappings = reverseMappings;
336
+ TextSourceMap.StringCharIterator = StringCharIterator;
337
+ class SourceInfo {
338
+ constructor(content, reverseMappings) {
339
+ this.content = content;
340
+ this.reverseMappings = reverseMappings;
341
+ }
503
342
  }
504
- };
505
- TextSourceMap._sourcesListSymbol = Symbol('sourcesList');
506
-
507
-
508
-
343
+ TextSourceMap.SourceInfo = SourceInfo;
344
+ })(TextSourceMap = exports.TextSourceMap || (exports.TextSourceMap = {}));
509
345
 
510
- module.exports = TextSourceMap
346
+ module.exports = TextSourceMap;
@@ -18,6 +18,7 @@ const {Directive} = require('csp_evaluator/dist/csp.js');
18
18
 
19
19
  const log = require('lighthouse-logger');
20
20
  const i18n = require('../lib/i18n/i18n.js');
21
+ const {isIcuMessage} = require('../../shared/localization/format.js');
21
22
 
22
23
  const UIStrings = {
23
24
  /** Message shown when a CSP does not have a base-uri directive. Shown in a table with a list of other CSP vulnerabilities and suggestions. "CSP" stands for "Content Security Policy". "base-uri", "'none'", and "'self'" do not need to be translated. */
@@ -130,7 +131,7 @@ function getTranslatedDescription(finding) {
130
131
  }
131
132
 
132
133
  // Return if translated result found.
133
- if (i18n.isIcuMessage(result)) return result;
134
+ if (isIcuMessage(result)) return result;
134
135
 
135
136
  // If result was not translated, that means `finding.value` is included in the UI string.
136
137
  if (typeof result === 'string') return str_(result, {keyword: finding.value || ''});