lighthouse 8.5.1-dev.20211012 → 8.5.1

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