lighthouse 9.5.0-dev.20220325 → 9.5.0-dev.20220328

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.
@@ -158,7 +158,6 @@ class UnusedBytes extends Audit {
158
158
 
159
159
  const simulationBeforeChanges = simulator.simulate(graph, {label: beforeLabel});
160
160
 
161
- // TODO: change this to wastedBytesByScriptId
162
161
  const wastedBytesByUrl = options.providedWastedBytesByUrl || new Map();
163
162
  if (!options.providedWastedBytesByUrl) {
164
163
  for (const {url, wastedBytes} of results) {
@@ -164,7 +164,7 @@ class DuplicatedJavascript extends ByteEfficiencyAudit {
164
164
  let transferRatio = transferRatioByUrl.get(url);
165
165
  if (transferRatio === undefined) {
166
166
  if (!script || script.length === undefined) {
167
- // This should never happen because we found the wasted bytes from bundles, which required contents in a ScriptElement.
167
+ // This should never happen because we found the wasted bytes from bundles, which required contents in a Script.
168
168
  continue;
169
169
  }
170
170
 
@@ -277,21 +277,21 @@ class LegacyJavascript extends ByteEfficiencyAudit {
277
277
  * @param {LH.Artifacts['Scripts']} scripts
278
278
  * @param {LH.Artifacts.NetworkRequest[]} networkRecords
279
279
  * @param {LH.Artifacts.Bundle[]} bundles
280
- * @return {Map<string, PatternMatchResult[]>}
280
+ * @return {Map<LH.Artifacts.Script, PatternMatchResult[]>}
281
281
  */
282
282
  static detectAcrossScripts(matcher, scripts, networkRecords, bundles) {
283
- /** @type {Map<string, PatternMatchResult[]>} */
284
- const urlToMatchResults = new Map();
283
+ /** @type {Map<LH.Artifacts.Script, PatternMatchResult[]>} */
284
+ const scriptToMatchResults = new Map();
285
285
  const polyfillData = this.getPolyfillData();
286
286
 
287
- for (const {scriptId, url, content} of Object.values(scripts)) {
288
- if (!content) continue;
287
+ for (const script of Object.values(scripts)) {
288
+ if (!script.content) continue;
289
289
 
290
290
  // Start with pattern matching against the downloaded script.
291
- const matches = matcher.match(content);
291
+ const matches = matcher.match(script.content);
292
292
 
293
293
  // If it's a bundle with source maps, add in the polyfill modules by name too.
294
- const bundle = bundles.find(b => b.script.scriptId === scriptId);
294
+ const bundle = bundles.find(b => b.script.scriptId === script.scriptId);
295
295
  if (bundle) {
296
296
  for (const {coreJs2Module, coreJs3Module, name} of polyfillData) {
297
297
  // Skip if the pattern matching found a match for this polyfill.
@@ -311,11 +311,10 @@ class LegacyJavascript extends ByteEfficiencyAudit {
311
311
  }
312
312
 
313
313
  if (!matches.length) continue;
314
- // TODO: scriptId
315
- urlToMatchResults.set(url, matches);
314
+ scriptToMatchResults.set(script, matches);
316
315
  }
317
316
 
318
- return urlToMatchResults;
317
+ return scriptToMatchResults;
319
318
  }
320
319
 
321
320
  /**
@@ -410,15 +409,15 @@ class LegacyJavascript extends ByteEfficiencyAudit {
410
409
  /** @type {Map<string, number>} */
411
410
  const transferRatioByUrl = new Map();
412
411
 
413
- const urlToMatchResults =
412
+ const scriptToMatchResults =
414
413
  this.detectAcrossScripts(matcher, artifacts.Scripts, networkRecords, bundles);
415
- for (const [url, matches] of urlToMatchResults.entries()) {
414
+ for (const [script, matches] of scriptToMatchResults.entries()) {
416
415
  const transferRatio = await this.estimateTransferRatioForScript(
417
- transferRatioByUrl, url, artifacts, networkRecords);
416
+ transferRatioByUrl, script.url, artifacts, networkRecords);
418
417
  const wastedBytes = Math.round(this.estimateWastedBytes(matches) * transferRatio);
419
418
  /** @type {typeof items[number]} */
420
419
  const item = {
421
- url,
420
+ url: script.url,
422
421
  wastedBytes,
423
422
  subItems: {
424
423
  type: 'subitems',
@@ -428,13 +427,13 @@ class LegacyJavascript extends ByteEfficiencyAudit {
428
427
  totalBytes: 0,
429
428
  };
430
429
 
431
- const bundle = bundles.find(bundle => bundle.script.url === url); // TODO: scriptId
430
+ const bundle = bundles.find(bundle => bundle.script.scriptId === script.scriptId);
432
431
  for (const match of matches) {
433
432
  const {name, line, column} = match;
434
433
  /** @type {SubItem} */
435
434
  const subItem = {
436
435
  signal: name,
437
- location: ByteEfficiencyAudit.makeSourceLocation(url, line, column, bundle),
436
+ location: ByteEfficiencyAudit.makeSourceLocation(script.url, line, column, bundle),
438
437
  };
439
438
  item.subItems.items.push(subItem);
440
439
  }
@@ -268,7 +268,7 @@ class RenderBlockingResources extends Audit {
268
268
  for (const item of unusedCssItems) {
269
269
  wastedBytesByUrl.set(item.url, item.wastedBytes);
270
270
  }
271
- } catch (_) {}
271
+ } catch {}
272
272
 
273
273
  return wastedBytesByUrl;
274
274
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse",
3
- "version": "9.5.0-dev.20220325",
3
+ "version": "9.5.0-dev.20220328",
4
4
  "description": "Automated auditing, performance metrics, and best practices for the web.",
5
5
  "main": "./lighthouse-core/index.js",
6
6
  "bin": {