lighthouse 12.4.0-dev.20250311 → 12.4.0-dev.20250313
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.
- package/core/audits/byte-efficiency/legacy-javascript.d.ts +6 -10
- package/core/audits/byte-efficiency/legacy-javascript.js +87 -105
- package/core/audits/byte-efficiency/polyfill-graph-data.json +92 -49
- package/core/audits/byte-efficiency/polyfill-module-data.json +686 -0
- package/core/audits/byte-efficiency/render-blocking-resources.js +2 -1
- package/core/audits/critical-request-chains.js +2 -1
- package/core/audits/insights/insight-audit.js +2 -1
- package/core/audits/layout-shifts.js +2 -1
- package/core/audits/long-tasks.js +2 -1
- package/core/audits/script-treemap-data.js +6 -2
- package/core/audits/uses-rel-preconnect.js +1 -1
- package/core/audits/uses-rel-preload.js +2 -1
- package/core/computed/critical-request-chains.d.ts +3 -1
- package/core/computed/critical-request-chains.js +2 -2
- package/core/computed/navigation-insights.d.ts +9 -3
- package/core/computed/navigation-insights.js +5 -4
- package/core/computed/page-dependency-graph.d.ts +3 -1
- package/core/computed/page-dependency-graph.js +5 -5
- package/core/computed/trace-engine-result.d.ts +5 -2
- package/core/computed/trace-engine-result.js +27 -5
- package/core/gather/gatherers/trace-elements.js +2 -1
- package/package.json +3 -2
- package/shared/localization/locales/en-US.json +1 -1
- package/shared/localization/locales/en-XL.json +1 -1
|
@@ -2,13 +2,12 @@ export default LegacyJavascript;
|
|
|
2
2
|
export type Pattern = {
|
|
3
3
|
name: string;
|
|
4
4
|
expression: string;
|
|
5
|
-
estimateBytes?: (
|
|
5
|
+
estimateBytes?: (content: string) => number;
|
|
6
6
|
};
|
|
7
7
|
export type PatternMatchResult = {
|
|
8
8
|
name: string;
|
|
9
9
|
line: number;
|
|
10
10
|
column: number;
|
|
11
|
-
count: number;
|
|
12
11
|
};
|
|
13
12
|
export type ByteEfficiencyProduct = import("./byte-efficiency-audit.js").ByteEfficiencyProduct;
|
|
14
13
|
export type Item = LH.Audit.ByteEfficiencyItem & {
|
|
@@ -27,14 +26,9 @@ declare class LegacyJavascript extends ByteEfficiencyAudit {
|
|
|
27
26
|
* @param {string} property
|
|
28
27
|
*/
|
|
29
28
|
static buildPolyfillExpression(object: string | null, property: string): string;
|
|
30
|
-
static
|
|
31
|
-
name: string;
|
|
32
|
-
modules: string[];
|
|
33
|
-
corejs?: boolean;
|
|
34
|
-
}[];
|
|
29
|
+
static getPolyfillModuleData(): import("../../scripts/legacy-javascript/create-polyfill-module-data.js").PolyfillModuleData;
|
|
35
30
|
static getCoreJsPolyfillData(): {
|
|
36
31
|
name: string;
|
|
37
|
-
coreJs2Module: string;
|
|
38
32
|
coreJs3Module: string;
|
|
39
33
|
}[];
|
|
40
34
|
/**
|
|
@@ -55,10 +49,11 @@ declare class LegacyJavascript extends ByteEfficiencyAudit {
|
|
|
55
49
|
*/
|
|
56
50
|
static detectAcrossScripts(matcher: CodePatternMatcher, scripts: LH.Artifacts["Scripts"], bundles: LH.Artifacts.Bundle[]): Map<LH.Artifacts.Script, PatternMatchResult[]>;
|
|
57
51
|
/**
|
|
52
|
+
* @param {LH.Artifacts.Script} script
|
|
58
53
|
* @param {PatternMatchResult[]} matches
|
|
59
54
|
* @return {number}
|
|
60
55
|
*/
|
|
61
|
-
static estimateWastedBytes(matches: PatternMatchResult[]): number;
|
|
56
|
+
static estimateWastedBytes(script: LH.Artifacts.Script, matches: PatternMatchResult[]): number;
|
|
62
57
|
/**
|
|
63
58
|
* @param {LH.Artifacts} artifacts
|
|
64
59
|
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
|
|
@@ -75,7 +70,8 @@ export namespace UIStrings {
|
|
|
75
70
|
import { ByteEfficiencyAudit } from './byte-efficiency-audit.js';
|
|
76
71
|
/**
|
|
77
72
|
* Takes a list of patterns (consisting of a name identifier and a RegExp expression string)
|
|
78
|
-
* and returns match results with line / column information for a given code input.
|
|
73
|
+
* and via `match` returns match results with line / column information for a given code input.
|
|
74
|
+
* Only returns the first match per pattern given.
|
|
79
75
|
*/
|
|
80
76
|
declare class CodePatternMatcher {
|
|
81
77
|
/**
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @fileoverview Identifies polyfills and transforms that should not be present if
|
|
9
|
-
* @see https://docs.google.com/document/d/1ItjJwAd6e0Ts6yMbvh8TN3BBh_sAd58rYE1whnpuxaA/edit Design document
|
|
8
|
+
* @fileoverview Identifies polyfills and transforms that should not be present if needing to support only Baseline browsers.
|
|
9
|
+
* @see https://docs.google.com/document/d/1ItjJwAd6e0Ts6yMbvh8TN3BBh_sAd58rYE1whnpuxaA/edit Design document (old, based on module/nomodule pattern)
|
|
10
10
|
* @see https://docs.google.com/spreadsheets/d/1z28Au8wo8-c2UsM2lDVEOJcI3jOkb2c951xEBqzBKCc/edit?usp=sharing Legacy babel transforms / polyfills
|
|
11
11
|
* ./core/scripts/legacy-javascript - verification tool.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
/** @typedef {{name: string, expression: string, estimateBytes?: (
|
|
15
|
-
/** @typedef {{name: string, line: number, column: number
|
|
14
|
+
/** @typedef {{name: string, expression: string, estimateBytes?: (content: string) => number}} Pattern */
|
|
15
|
+
/** @typedef {{name: string, line: number, column: number}} PatternMatchResult */
|
|
16
16
|
/** @typedef {import('./byte-efficiency-audit.js').ByteEfficiencyProduct} ByteEfficiencyProduct */
|
|
17
17
|
/** @typedef {LH.Audit.ByteEfficiencyItem & {subItems: {type: 'subitems', items: SubItem[]}}} Item */
|
|
18
18
|
/** @typedef {{signal: string, location: LH.Audit.Details.SourceLocationValue}} SubItem */
|
|
@@ -27,6 +27,12 @@ import * as i18n from '../../lib/i18n/i18n.js';
|
|
|
27
27
|
import {estimateCompressionRatioForContent} from '../../lib/script-helpers.js';
|
|
28
28
|
import {LH_ROOT} from '../../../shared/root.js';
|
|
29
29
|
|
|
30
|
+
const polyfillModuleDataJson = fs.readFileSync(
|
|
31
|
+
`${LH_ROOT}/core/audits/byte-efficiency/polyfill-module-data.json`, 'utf-8');
|
|
32
|
+
|
|
33
|
+
/** @type {import('../../scripts/legacy-javascript/create-polyfill-module-data.js').PolyfillModuleData} */
|
|
34
|
+
const polyfillModuleData = JSON.parse(polyfillModuleDataJson);
|
|
35
|
+
|
|
30
36
|
const graphJson = fs.readFileSync(
|
|
31
37
|
`${LH_ROOT}/core/audits/byte-efficiency/polyfill-graph-data.json`, 'utf-8');
|
|
32
38
|
|
|
@@ -39,7 +45,7 @@ const UIStrings = {
|
|
|
39
45
|
// eslint-disable-next-line max-len
|
|
40
46
|
// TODO: developer.chrome.com article. this codelab is good starting place: https://web.dev/articles/codelab-serve-modern-code
|
|
41
47
|
/** Description of a Lighthouse audit that tells the user about old JavaScript that is no longer needed. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
|
|
42
|
-
description: 'Polyfills and transforms enable legacy browsers to use new JavaScript features. However, many aren\'t necessary for modern browsers.
|
|
48
|
+
description: 'Polyfills and transforms enable legacy browsers to use new JavaScript features. However, many aren\'t necessary for modern browsers. Consider modifying your JavaScript build process to not transpile [Baseline](https://web.dev/baseline) features, unless you know you must support legacy browsers. [Learn why most sites can deploy ES6+ code without transpiling](https://philipwalton.com/articles/the-state-of-es5-on-the-web/)',
|
|
43
49
|
/** Warning text that an outdated version of the library "core-js" was found, and the developer should upgrade. */
|
|
44
50
|
// eslint-disable-next-line max-len
|
|
45
51
|
detectedCoreJs2Warning: 'Version 2 of core-js was detected on the page. You should upgrade to version 3 for many performance improvements.',
|
|
@@ -49,7 +55,8 @@ const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
|
|
|
49
55
|
|
|
50
56
|
/**
|
|
51
57
|
* Takes a list of patterns (consisting of a name identifier and a RegExp expression string)
|
|
52
|
-
* and returns match results with line / column information for a given code input.
|
|
58
|
+
* and via `match` returns match results with line / column information for a given code input.
|
|
59
|
+
* Only returns the first match per pattern given.
|
|
53
60
|
*/
|
|
54
61
|
class CodePatternMatcher {
|
|
55
62
|
/**
|
|
@@ -93,8 +100,6 @@ class CodePatternMatcher {
|
|
|
93
100
|
const pattern = this.patterns[patternExpressionMatches.findIndex(Boolean)];
|
|
94
101
|
|
|
95
102
|
if (seen.has(pattern)) {
|
|
96
|
-
const existingMatch = matches.find(m => m.name === pattern.name);
|
|
97
|
-
if (existingMatch) existingMatch.count += 1;
|
|
98
103
|
continue;
|
|
99
104
|
}
|
|
100
105
|
seen.add(pattern);
|
|
@@ -103,7 +108,6 @@ class CodePatternMatcher {
|
|
|
103
108
|
name: pattern.name,
|
|
104
109
|
line,
|
|
105
110
|
column: result.index - lineBeginsAtIndex,
|
|
106
|
-
count: 1,
|
|
107
111
|
});
|
|
108
112
|
}
|
|
109
113
|
|
|
@@ -170,105 +174,31 @@ class LegacyJavascript extends ByteEfficiencyAudit {
|
|
|
170
174
|
// TODO: perhaps this is the wrong place to check for a CDN polyfill. Remove?
|
|
171
175
|
// expression += `|;e\\([^,]+,${qt(objectWithoutPrototype)},{${property}:`;
|
|
172
176
|
|
|
173
|
-
// core-js@2 minified pattern.
|
|
174
|
-
// $export($export.S,"Date",{now:function
|
|
175
|
-
expression += `|\\$export\\([^,]+,${qt(objectWithoutPrototype)},{${property}:`;
|
|
176
|
-
|
|
177
177
|
// core-js@3 minified pattern.
|
|
178
178
|
// {target:"Array",proto:true},{fill:fill
|
|
179
179
|
// {target:"Array",proto:true,forced:!HAS_SPECIES_SUPPORT||!USES_TO_LENGTH},{filter:
|
|
180
180
|
expression += `|{target:${qt(objectWithoutPrototype)}\\S*},{${property}:`;
|
|
181
181
|
} else {
|
|
182
|
-
// WeakSet, etc.
|
|
183
|
-
|
|
182
|
+
// Detect polyfills for new classes: Map, Set, WeakSet, etc.
|
|
183
|
+
// TODO: so far, no class polyfills are enabled for detection.
|
|
184
|
+
// See `modulesToSkip` in create-polyfill-module-data.js
|
|
185
|
+
|
|
186
|
+
// collection("Map",
|
|
187
|
+
// expression += `|collection\\(${qt(property)},`;
|
|
184
188
|
}
|
|
185
189
|
|
|
186
190
|
return expression;
|
|
187
191
|
}
|
|
188
192
|
|
|
189
|
-
static
|
|
190
|
-
|
|
191
|
-
const data = [
|
|
192
|
-
{name: 'focus-visible', modules: ['focus-visible']},
|
|
193
|
-
];
|
|
194
|
-
|
|
195
|
-
const coreJsPolyfills = [
|
|
196
|
-
['Array.prototype.fill', 'es6.array.fill'],
|
|
197
|
-
['Array.prototype.filter', 'es6.array.filter'],
|
|
198
|
-
['Array.prototype.find', 'es6.array.find'],
|
|
199
|
-
['Array.prototype.findIndex', 'es6.array.find-index'],
|
|
200
|
-
['Array.prototype.forEach', 'es6.array.for-each'],
|
|
201
|
-
['Array.from', 'es6.array.from'],
|
|
202
|
-
['Array.isArray', 'es6.array.is-array'],
|
|
203
|
-
['Array.prototype.map', 'es6.array.map'],
|
|
204
|
-
['Array.of', 'es6.array.of'],
|
|
205
|
-
['Array.prototype.some', 'es6.array.some'],
|
|
206
|
-
['Date.now', 'es6.date.now'],
|
|
207
|
-
['Date.prototype.toISOString', 'es6.date.to-iso-string'],
|
|
208
|
-
['Date.prototype.toJSON', 'es6.date.to-json'],
|
|
209
|
-
['Date.prototype.toString', 'es6.date.to-string'],
|
|
210
|
-
['Function.prototype.name', 'es6.function.name'],
|
|
211
|
-
['Number.isInteger', 'es6.number.is-integer'],
|
|
212
|
-
['Number.isSafeInteger', 'es6.number.is-safe-integer'],
|
|
213
|
-
['Object.defineProperties', 'es6.object.define-properties'],
|
|
214
|
-
['Object.defineProperty', 'es6.object.define-property'],
|
|
215
|
-
['Object.freeze', 'es6.object.freeze'],
|
|
216
|
-
['Object.getPrototypeOf', 'es6.object.get-prototype-of'],
|
|
217
|
-
['Object.isExtensible', 'es6.object.is-extensible'],
|
|
218
|
-
['Object.isFrozen', 'es6.object.is-frozen'],
|
|
219
|
-
['Object.isSealed', 'es6.object.is-sealed'],
|
|
220
|
-
['Object.keys', 'es6.object.keys'],
|
|
221
|
-
['Object.preventExtensions', 'es6.object.prevent-extensions'],
|
|
222
|
-
['Object.seal', 'es6.object.seal'],
|
|
223
|
-
['Object.setPrototypeOf', 'es6.object.set-prototype-of'],
|
|
224
|
-
['Reflect.apply', 'es6.reflect.apply'],
|
|
225
|
-
['Reflect.construct', 'es6.reflect.construct'],
|
|
226
|
-
['Reflect.defineProperty', 'es6.reflect.define-property'],
|
|
227
|
-
['Reflect.deleteProperty', 'es6.reflect.delete-property'],
|
|
228
|
-
['Reflect.get', 'es6.reflect.get'],
|
|
229
|
-
['Reflect.getOwnPropertyDescriptor', 'es6.reflect.get-own-property-descriptor'],
|
|
230
|
-
['Reflect.getPrototypeOf', 'es6.reflect.get-prototype-of'],
|
|
231
|
-
['Reflect.has', 'es6.reflect.has'],
|
|
232
|
-
['Reflect.isExtensible', 'es6.reflect.is-extensible'],
|
|
233
|
-
['Reflect.ownKeys', 'es6.reflect.own-keys'],
|
|
234
|
-
['Reflect.preventExtensions', 'es6.reflect.prevent-extensions'],
|
|
235
|
-
['Reflect.setPrototypeOf', 'es6.reflect.set-prototype-of'],
|
|
236
|
-
['String.prototype.codePointAt', 'es6.string.code-point-at'],
|
|
237
|
-
['String.raw', 'es6.string.raw'],
|
|
238
|
-
['String.prototype.repeat', 'es6.string.repeat'],
|
|
239
|
-
['Object.entries', 'es7.object.entries'],
|
|
240
|
-
['Object.getOwnPropertyDescriptors', 'es7.object.get-own-property-descriptors'],
|
|
241
|
-
['Object.values', 'es7.object.values'],
|
|
242
|
-
];
|
|
243
|
-
|
|
244
|
-
for (const [name, coreJs2Module] of coreJsPolyfills) {
|
|
245
|
-
// es-shims follows a pattern for its packages.
|
|
246
|
-
// Tack it onto the corejs size estimation, as it is likely close in size.
|
|
247
|
-
const esShimModule = name.toLowerCase();
|
|
248
|
-
data.push({
|
|
249
|
-
name,
|
|
250
|
-
modules: [
|
|
251
|
-
coreJs2Module,
|
|
252
|
-
// corejs 3 module name
|
|
253
|
-
coreJs2Module
|
|
254
|
-
.replace('es6.', 'es.')
|
|
255
|
-
.replace('es7.', 'es.')
|
|
256
|
-
.replace('typed.', 'typed-array.'),
|
|
257
|
-
esShimModule,
|
|
258
|
-
],
|
|
259
|
-
corejs: true,
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return data;
|
|
193
|
+
static getPolyfillModuleData() {
|
|
194
|
+
return polyfillModuleData;
|
|
264
195
|
}
|
|
265
196
|
|
|
266
197
|
static getCoreJsPolyfillData() {
|
|
267
|
-
return this.
|
|
198
|
+
return this.getPolyfillModuleData().filter(d => d.corejs).map(d => {
|
|
268
199
|
return {
|
|
269
200
|
name: d.name,
|
|
270
|
-
|
|
271
|
-
coreJs3Module: d.modules[1],
|
|
201
|
+
coreJs3Module: d.modules[0],
|
|
272
202
|
};
|
|
273
203
|
});
|
|
274
204
|
}
|
|
@@ -297,23 +227,74 @@ class LegacyJavascript extends ByteEfficiencyAudit {
|
|
|
297
227
|
* @return {Pattern[]}
|
|
298
228
|
*/
|
|
299
229
|
static getTransformPatterns() {
|
|
230
|
+
/**
|
|
231
|
+
* @param {string} content
|
|
232
|
+
* @param {RegExp|string} pattern
|
|
233
|
+
* @return {number}
|
|
234
|
+
*/
|
|
235
|
+
const count = (content, pattern) => {
|
|
236
|
+
// Split is slightly faster than match.
|
|
237
|
+
if (typeof pattern === 'string') {
|
|
238
|
+
return content.split(pattern).length - 1;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return (content.match(pattern) ?? []).length;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// For expression: prefer a string that is found in the transform runtime support code (those won't ever be minified).
|
|
245
|
+
|
|
300
246
|
return [
|
|
247
|
+
// @babel/plugin-transform-classes
|
|
248
|
+
//
|
|
249
|
+
// input:
|
|
250
|
+
//
|
|
251
|
+
// class MyTestClass {
|
|
252
|
+
// log() {
|
|
253
|
+
// console.log(1);
|
|
254
|
+
// }
|
|
255
|
+
// };
|
|
256
|
+
//
|
|
257
|
+
// output:
|
|
258
|
+
//
|
|
259
|
+
// function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
260
|
+
// function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
261
|
+
// function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
262
|
+
// function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
263
|
+
// function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
264
|
+
// let MyTestClass = function () {
|
|
265
|
+
// function MyTestClass() {
|
|
266
|
+
// _classCallCheck(this, MyTestClass);
|
|
267
|
+
// }
|
|
268
|
+
// return _createClass(MyTestClass, [{
|
|
269
|
+
// key: "log",
|
|
270
|
+
// value: function log() {
|
|
271
|
+
// console.log(1);
|
|
272
|
+
// }
|
|
273
|
+
// }]);
|
|
274
|
+
// }();
|
|
301
275
|
{
|
|
302
276
|
name: '@babel/plugin-transform-classes',
|
|
303
277
|
expression: 'Cannot call a class as a function',
|
|
304
|
-
estimateBytes:
|
|
278
|
+
estimateBytes: content => {
|
|
279
|
+
return 1000 + (count(content, '_classCallCheck') - 1) * '_classCallCheck()'.length;
|
|
280
|
+
},
|
|
305
281
|
},
|
|
306
282
|
{
|
|
307
283
|
name: '@babel/plugin-transform-regenerator',
|
|
308
|
-
expression:
|
|
284
|
+
expression: 'Generator is already running|regeneratorRuntime',
|
|
309
285
|
// Example of this transform: https://gist.github.com/connorjclark/af8bccfff377ac44efc104a79bc75da2
|
|
310
286
|
// `regeneratorRuntime.awrap` is generated for every usage of `await`, and adds ~80 bytes each.
|
|
311
|
-
estimateBytes:
|
|
287
|
+
estimateBytes: content => {
|
|
288
|
+
return count(content, /regeneratorRuntime\(?\)?\.a?wrap/g) * 80;
|
|
289
|
+
},
|
|
312
290
|
},
|
|
313
291
|
{
|
|
314
292
|
name: '@babel/plugin-transform-spread',
|
|
315
|
-
expression:
|
|
316
|
-
estimateBytes:
|
|
293
|
+
expression: 'Invalid attempt to spread non-iterable instance',
|
|
294
|
+
estimateBytes: content => {
|
|
295
|
+
const per = '_toConsumableArray()'.length;
|
|
296
|
+
return 1169 + count(content, /\.apply\(void 0,\s?_toConsumableArray/g) * per;
|
|
297
|
+
},
|
|
317
298
|
},
|
|
318
299
|
];
|
|
319
300
|
}
|
|
@@ -329,7 +310,7 @@ class LegacyJavascript extends ByteEfficiencyAudit {
|
|
|
329
310
|
static detectAcrossScripts(matcher, scripts, bundles) {
|
|
330
311
|
/** @type {Map<LH.Artifacts.Script, PatternMatchResult[]>} */
|
|
331
312
|
const scriptToMatchResults = new Map();
|
|
332
|
-
const polyfillData = this.
|
|
313
|
+
const polyfillData = this.getPolyfillModuleData();
|
|
333
314
|
|
|
334
315
|
for (const script of Object.values(scripts)) {
|
|
335
316
|
if (!script.content) continue;
|
|
@@ -351,9 +332,9 @@ class LegacyJavascript extends ByteEfficiencyAudit {
|
|
|
351
332
|
|
|
352
333
|
const mapping = bundle.map.mappings().find(m => m.sourceURL === source);
|
|
353
334
|
if (mapping) {
|
|
354
|
-
matches.push({name, line: mapping.lineNumber, column: mapping.columnNumber
|
|
335
|
+
matches.push({name, line: mapping.lineNumber, column: mapping.columnNumber});
|
|
355
336
|
} else {
|
|
356
|
-
matches.push({name, line: 0, column: 0
|
|
337
|
+
matches.push({name, line: 0, column: 0});
|
|
357
338
|
}
|
|
358
339
|
}
|
|
359
340
|
}
|
|
@@ -366,10 +347,11 @@ class LegacyJavascript extends ByteEfficiencyAudit {
|
|
|
366
347
|
}
|
|
367
348
|
|
|
368
349
|
/**
|
|
350
|
+
* @param {LH.Artifacts.Script} script
|
|
369
351
|
* @param {PatternMatchResult[]} matches
|
|
370
352
|
* @return {number}
|
|
371
353
|
*/
|
|
372
|
-
static estimateWastedBytes(matches) {
|
|
354
|
+
static estimateWastedBytes(script, matches) {
|
|
373
355
|
// Split up results based on polyfill / transform. Only transforms start with @.
|
|
374
356
|
const polyfillResults = matches.filter(m => !m.name.startsWith('@'));
|
|
375
357
|
const transformResults = matches.filter(m => m.name.startsWith('@'));
|
|
@@ -393,8 +375,8 @@ class LegacyJavascript extends ByteEfficiencyAudit {
|
|
|
393
375
|
|
|
394
376
|
for (const result of transformResults) {
|
|
395
377
|
const pattern = this.getTransformPatterns().find(p => p.name === result.name);
|
|
396
|
-
if (!pattern || !pattern.estimateBytes) continue;
|
|
397
|
-
estimatedWastedBytesFromTransforms += pattern.estimateBytes(
|
|
378
|
+
if (!pattern || !pattern.estimateBytes || !script.content) continue;
|
|
379
|
+
estimatedWastedBytesFromTransforms += pattern.estimateBytes(script.content);
|
|
398
380
|
}
|
|
399
381
|
|
|
400
382
|
const estimatedWastedBytes =
|
|
@@ -431,7 +413,7 @@ class LegacyJavascript extends ByteEfficiencyAudit {
|
|
|
431
413
|
for (const [script, matches] of scriptToMatchResults.entries()) {
|
|
432
414
|
const compressionRatio = estimateCompressionRatioForContent(
|
|
433
415
|
compressionRatioByUrl, script.url, artifacts, networkRecords);
|
|
434
|
-
const wastedBytes = Math.round(this.estimateWastedBytes(matches) * compressionRatio);
|
|
416
|
+
const wastedBytes = Math.round(this.estimateWastedBytes(script, matches) * compressionRatio);
|
|
435
417
|
/** @type {typeof items[number]} */
|
|
436
418
|
const item = {
|
|
437
419
|
url: script.url,
|
|
@@ -1,53 +1,96 @@
|
|
|
1
1
|
{
|
|
2
|
-
"moduleSizes": [
|
|
2
|
+
"moduleSizes": [26070, 498, 282, 294, 281, 467, 161, 236, 229, 765, 546, 339, 1608, 723, 729, 1545, 438, 214, 657, 111, 759, 537, 209, 281, 685, 217, 757, 631, 293, 182, 475, 79, 407, 140, 366, 792, 269, 222, 158, 280, 188, 137, 158, 105, 189, 543, 160, 742, 1436, 88, 904, 146, 314, 375, 183, 1083, 195, 503, 269, 208, 334, 350, 460, 568, 229, 1155, 334, 266, 30, 120, 309, 370, 358, 1952, 1638, 304, 153, 274, 1288, 192, 543, 74, 144, 137, 33, 336, 457, 2122, 535, 711, 1323, 117, 1961, 244, 557, 318, 119, 124, 108, 144, 96, 133, 441, 210, 1627, 1956, 693, 1426, 863, 637, 301, 51, 708, 583, 119, 600, 221, 370, 728, 1085, 552, 629, 125, 1746, 97, 441, 543, 2756, 371, 447, 548, 243, 266, 217, 99, 440, 183, 546, 137, 464, 207, 983, 171, 992, 503, 237, 382, 249, 675, 402, 254, 223, 164, 214, 191, 831, 218, 202, 232, 124, 249, 160, 251, 217, 717, 78, 561, 1627, 256, 386, 225, 432, 499, 394, 364, 445, 634, 667, 177, 346, 470, 663, 142, 588, 414, 617, 1559, 380, 2520, 1040, 417, 289, 238, 220, 214, 303, 163, 141, 510, 397, 137, 137, 133, 133, 390, 266, 137, 183, 215, 191, 485, 328, 575, 799, 533, 148, 215, 589, 589, 130, 362, 562, 471, 179, 186, 1266, 1456, 521, 1536, 427, 444, 406, 912, 150, 283, 144, 485, 470, 1787, 205, 1268, 796, 658, 306, 3751, 321, 331, 814, 146, 2328, 1226, 922, 237, 206, 198, 250, 283, 46, 59, 53, 52, 60, 49, 54, 56, 3000],
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"Array.prototype.
|
|
5
|
-
"Array.prototype.
|
|
6
|
-
"Array.prototype.
|
|
7
|
-
"Array.prototype.
|
|
8
|
-
"Array.prototype.
|
|
9
|
-
"Array.
|
|
10
|
-
"Array.
|
|
11
|
-
"Array.prototype.
|
|
12
|
-
"Array.
|
|
13
|
-
"Array.prototype.
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"Object.entries": [0,
|
|
48
|
-
"Object.
|
|
49
|
-
"Object.
|
|
50
|
-
"
|
|
4
|
+
"Array.prototype.at": [0, 5, 69, 105, 106, 116, 166, 257],
|
|
5
|
+
"Array.prototype.concat": [0, 16, 21, 22, 26, 34, 40, 76, 78, 157, 167],
|
|
6
|
+
"Array.prototype.copyWithin": [0, 5, 9, 37, 69, 105, 106, 116, 168],
|
|
7
|
+
"Array.prototype.every": [0, 15, 17, 21, 22, 26, 53, 59, 76, 78, 157, 169],
|
|
8
|
+
"Array.prototype.fill": [0, 5, 10, 69, 105, 106, 116, 170],
|
|
9
|
+
"Array.prototype.filter": [0, 15, 16, 21, 22, 26, 53, 59, 76, 78, 157, 171],
|
|
10
|
+
"Array.prototype.find": [0, 5, 15, 21, 22, 26, 53, 59, 69, 76, 78, 105, 106, 116, 157, 175],
|
|
11
|
+
"Array.prototype.findIndex": [0, 5, 15, 21, 22, 26, 53, 59, 69, 76, 78, 105, 106, 116, 157, 172],
|
|
12
|
+
"Array.prototype.findLast": [0, 5, 14, 53, 59, 69, 105, 106, 116, 174, 259],
|
|
13
|
+
"Array.prototype.findLastIndex": [0, 5, 14, 53, 59, 69, 105, 106, 116, 173, 258],
|
|
14
|
+
"Array.prototype.flat": [0, 21, 22, 26, 40, 50, 53, 59, 76, 78, 157, 177],
|
|
15
|
+
"Array.prototype.flatMap": [0, 21, 22, 26, 40, 50, 53, 59, 76, 78, 157, 176],
|
|
16
|
+
"Array.prototype.forEach": [0, 11, 15, 17, 21, 22, 26, 53, 59, 76, 78, 157, 178],
|
|
17
|
+
"Array.from": [0, 12, 23, 24, 26, 34, 53, 59, 62, 63, 75, 78, 88, 157, 179],
|
|
18
|
+
"Array.prototype.includes": [0, 5, 69, 105, 106, 116, 180],
|
|
19
|
+
"Array.prototype.indexOf": [0, 17, 59, 181],
|
|
20
|
+
"Array.isArray": [0, 76, 182],
|
|
21
|
+
"Array.prototype.join": [0, 17, 183],
|
|
22
|
+
"Array.prototype.map": [0, 15, 16, 21, 22, 26, 53, 59, 76, 78, 157, 184],
|
|
23
|
+
"Array.of": [0, 26, 34, 78, 157, 185],
|
|
24
|
+
"Array.prototype.slice": [0, 16, 19, 26, 34, 76, 78, 157, 186],
|
|
25
|
+
"Array.prototype.some": [0, 15, 17, 21, 22, 26, 53, 59, 76, 78, 157, 187],
|
|
26
|
+
"Array.prototype.sort": [0, 17, 19, 20, 26, 37, 42, 43, 46, 157, 158, 188],
|
|
27
|
+
"Array.prototype.unshift": [0, 18, 37, 40, 76, 189],
|
|
28
|
+
"Math.acosh": [0, 97, 190],
|
|
29
|
+
"Math.asinh": [0, 191],
|
|
30
|
+
"Math.atanh": [0, 192],
|
|
31
|
+
"Math.cbrt": [0, 100, 193],
|
|
32
|
+
"Math.clz32": [0, 194],
|
|
33
|
+
"Math.cosh": [0, 93, 195],
|
|
34
|
+
"Math.expm1": [0, 93, 196],
|
|
35
|
+
"Math.fround": [0, 94, 95, 99, 100, 197],
|
|
36
|
+
"Math.hypot": [0, 198],
|
|
37
|
+
"Math.imul": [0, 199],
|
|
38
|
+
"Math.log10": [0, 96, 200],
|
|
39
|
+
"Math.log1p": [0, 97, 201],
|
|
40
|
+
"Math.log2": [0, 98, 202],
|
|
41
|
+
"Math.sign": [0, 100, 203],
|
|
42
|
+
"Math.sinh": [0, 93, 204],
|
|
43
|
+
"Math.tanh": [0, 93, 205],
|
|
44
|
+
"Math.trunc": [0, 206],
|
|
45
|
+
"Object.assign": [0, 104, 116, 207],
|
|
46
|
+
"Object.create": [0, 69, 105, 106, 116, 208],
|
|
47
|
+
"Object.entries": [0, 29, 112, 116, 119, 209],
|
|
48
|
+
"Object.freeze": [0, 8, 19, 51, 73, 109, 113, 210],
|
|
49
|
+
"Object.fromEntries": [0, 26, 34, 53, 59, 62, 63, 75, 87, 88, 157, 211],
|
|
50
|
+
"Object.getOwnPropertyDescriptor": [0, 212],
|
|
51
|
+
"Object.getOwnPropertyDescriptors": [0, 34, 213],
|
|
52
|
+
"Object.getPrototypeOf": [0, 29, 112, 214],
|
|
53
|
+
"Object.hasOwn": [0, 215, 260],
|
|
54
|
+
"Object.is": [0, 134, 219],
|
|
55
|
+
"Object.isExtensible": [0, 8, 113, 216],
|
|
56
|
+
"Object.isFrozen": [0, 8, 217],
|
|
57
|
+
"Object.isSealed": [0, 8, 218],
|
|
58
|
+
"Object.keys": [0, 116, 220],
|
|
59
|
+
"Object.preventExtensions": [0, 8, 19, 51, 73, 109, 113, 221],
|
|
60
|
+
"Object.seal": [0, 8, 19, 51, 73, 109, 113, 222],
|
|
61
|
+
"Object.setPrototypeOf": [0, 4, 58, 83, 118, 223],
|
|
62
|
+
"Object.values": [0, 29, 112, 116, 119, 224],
|
|
63
|
+
"Promise.any": [0, 24, 26, 47, 53, 59, 62, 63, 75, 87, 88, 102, 122, 123, 124, 125, 157, 226, 262],
|
|
64
|
+
"Reflect.apply": [0, 52, 227],
|
|
65
|
+
"Reflect.construct": [0, 3, 19, 26, 52, 55, 69, 78, 105, 106, 116, 157, 228],
|
|
66
|
+
"Reflect.deleteProperty": [0, 229],
|
|
67
|
+
"Reflect.get": [0, 29, 79, 112, 232],
|
|
68
|
+
"Reflect.getOwnPropertyDescriptor": [0, 230],
|
|
69
|
+
"Reflect.getPrototypeOf": [0, 29, 112, 231],
|
|
70
|
+
"Reflect.has": [0, 233],
|
|
71
|
+
"Reflect.isExtensible": [0, 8, 113, 234],
|
|
72
|
+
"Reflect.ownKeys": [0, 235],
|
|
73
|
+
"Reflect.preventExtensions": [0, 51, 236],
|
|
74
|
+
"Reflect.set": [0, 29, 79, 112, 238],
|
|
75
|
+
"Reflect.setPrototypeOf": [0, 4, 58, 83, 118, 237],
|
|
76
|
+
"String.prototype.codePointAt": [0, 26, 141, 157, 158, 239],
|
|
77
|
+
"String.prototype.endsWith": [0, 26, 28, 59, 85, 103, 157, 158, 240],
|
|
78
|
+
"String.fromCodePoint": [0, 241],
|
|
79
|
+
"String.prototype.includes": [0, 26, 28, 85, 103, 157, 158, 242],
|
|
80
|
+
"String.prototype.matchAll": [0, 3, 6, 26, 29, 31, 59, 69, 78, 85, 89, 90, 105, 106, 112, 116, 126, 127, 128, 129, 130, 131, 132, 135, 139, 141, 157, 158, 244, 263],
|
|
81
|
+
"String.prototype.padEnd": [0, 26, 142, 143, 144, 157, 158, 245],
|
|
82
|
+
"String.prototype.padStart": [0, 26, 142, 143, 144, 157, 158, 246],
|
|
83
|
+
"String.raw": [0, 26, 157, 158, 247],
|
|
84
|
+
"String.prototype.repeat": [0, 26, 144, 157, 158, 248],
|
|
85
|
+
"String.prototype.replaceAll": [0, 26, 65, 85, 128, 129, 157, 158, 249, 264],
|
|
86
|
+
"String.prototype.startsWith": [0, 26, 28, 59, 85, 103, 157, 158, 250],
|
|
87
|
+
"String.prototype.substr": [0, 26, 157, 158, 251],
|
|
88
|
+
"String.prototype.trim": [0, 26, 146, 148, 157, 158, 165, 256],
|
|
89
|
+
"String.prototype.trimEnd": [0, 26, 145, 146, 148, 157, 158, 165, 252, 254],
|
|
90
|
+
"String.prototype.trimStart": [0, 26, 146, 147, 148, 157, 158, 165, 253, 255],
|
|
91
|
+
"String.prototype.link": [0, 26, 30, 140, 157, 158, 243],
|
|
92
|
+
"Promise.allSettled": [0, 24, 26, 47, 53, 59, 62, 63, 75, 87, 88, 102, 122, 123, 124, 125, 157, 225, 261],
|
|
93
|
+
"focus-visible": [265]
|
|
51
94
|
},
|
|
52
|
-
"maxSize":
|
|
95
|
+
"maxSize": 159806
|
|
53
96
|
}
|