diff --git a/core/audits/byte-efficiency/legacy-javascript.js b/core/audits/byte-efficiency/legacy-javascript.js index d93e953f5ad6..f0ddaeb96e9d 100644 --- a/core/audits/byte-efficiency/legacy-javascript.js +++ b/core/audits/byte-efficiency/legacy-javascript.js @@ -177,7 +177,12 @@ class LegacyJavascript extends ByteEfficiencyAudit { } static getPolyfillData() { - return [ + /** @type {Array<{name: string, modules: string[], corejs?: boolean}>} */ + const data = [ + {name: 'focus-visible', modules: ['focus-visible']}, + ]; + + const coreJsPolyfills = [ ['Array.prototype.fill', 'es6.array.fill'], ['Array.prototype.filter', 'es6.array.filter'], ['Array.prototype.find', 'es6.array.find'], @@ -225,15 +230,32 @@ class LegacyJavascript extends ByteEfficiencyAudit { ['Object.entries', 'es7.object.entries'], ['Object.getOwnPropertyDescriptors', 'es7.object.get-own-property-descriptors'], ['Object.values', 'es7.object.values'], - ].map(data => { - const [name, coreJs2Module] = data; - return { + ]; + + for (const [name, coreJs2Module] of coreJsPolyfills) { + data.push({ name, - coreJs2Module, - coreJs3Module: coreJs2Module - .replace('es6.', 'es.') - .replace('es7.', 'es.') - .replace('typed.', 'typed-array.'), + modules: [ + coreJs2Module, + // corejs 3 module name + coreJs2Module + .replace('es6.', 'es.') + .replace('es7.', 'es.') + .replace('typed.', 'typed-array.'), + ], + corejs: true, + }); + } + + return data; + } + + static getCoreJsPolyfillData() { + return this.getPolyfillData().filter(d => d.corejs).map(d => { + return { + name: d.name, + coreJs2Module: d.modules[0], + coreJs3Module: d.modules[1], }; }); } @@ -242,15 +264,20 @@ class LegacyJavascript extends ByteEfficiencyAudit { * @return {Pattern[]} */ static getPolyfillPatterns() { - return this.getPolyfillData().map(({name}) => { + /** @type {Pattern[]} */ + const patterns = []; + + for (const {name} of this.getCoreJsPolyfillData()) { const parts = name.split('.'); const object = parts.length > 1 ? parts.slice(0, parts.length - 1).join('.') : null; const property = parts[parts.length - 1]; - return { + patterns.push({ name, expression: this.buildPolyfillExpression(object, property), - }; - }); + }); + } + + return patterns; } /** @@ -301,12 +328,12 @@ class LegacyJavascript extends ByteEfficiencyAudit { // If it's a bundle with source maps, add in the polyfill modules by name too. const bundle = bundles.find(b => b.script.scriptId === script.scriptId); if (bundle) { - for (const {coreJs2Module, coreJs3Module, name} of polyfillData) { + for (const {name, modules} of polyfillData) { // Skip if the pattern matching found a match for this polyfill. if (matches.some(m => m.name === name)) continue; const source = bundle.rawMap.sources.find(source => - source.endsWith(`${coreJs2Module}.js`) || source.endsWith(`${coreJs3Module}.js`)); + modules.some(module => source.endsWith(`${module}.js`))); if (!source) continue; const mapping = bundle.map.mappings().find(m => m.sourceURL === source); @@ -344,7 +371,6 @@ class LegacyJavascript extends ByteEfficiencyAudit { } } - if (polyfillResults.length > 0) estimatedWastedBytesFromPolyfills += graph.baseSize; estimatedWastedBytesFromPolyfills += [...modulesSeen].reduce((acc, moduleIndex) => { return acc + graph.moduleSizes[moduleIndex]; }, 0); diff --git a/core/audits/byte-efficiency/polyfill-graph-data.json b/core/audits/byte-efficiency/polyfill-graph-data.json index 4e2ee54ef69a..26573ad7e980 100644 --- a/core/audits/byte-efficiency/polyfill-graph-data.json +++ b/core/audits/byte-efficiency/polyfill-graph-data.json @@ -1,54 +1,54 @@ { - "moduleSizes": [498, 265, 277, 263, 453, 219, 216, 546, 339, 1608, 671, 1525, 420, 214, 504, 98, 524, 196, 268, 642, 204, 742, 618, 169, 394, 127, 433, 1473, 779, 239, 144, 182, 254, 77, 508, 124, 1388, 75, 133, 301, 362, 170, 1078, 182, 490, 195, 321, 316, 447, 551, 216, 284, 253, 17, 107, 295, 356, 345, 1939, 1596, 291, 139, 259, 1291, 179, 528, 174, 61, 326, 20, 444, 522, 104, 1945, 120, 1943, 680, 1409, 850, 630, 288, 38, 695, 569, 106, 587, 208, 370, 606, 766, 535, 616, 200, 170, 224, 422, 970, 978, 498, 284, 241, 210, 151, 194, 178, 814, 205, 189, 215, 111, 236, 147, 237, 191, 691, 212, 432, 499, 445, 176, 333, 129, 414, 617, 380, 251, 199, 524, 515, 681, 160, 259, 295, 283, 178, 472, 786, 520, 202, 575, 575, 349, 549, 458, 166, 173, 508, 1522, 743, 414, 431, 393, 899, 137, 270, 131, 472, 457, 205, 778, 801, 133], + "moduleSizes": [11897, 498, 265, 277, 263, 453, 219, 216, 546, 339, 1608, 671, 1525, 420, 214, 504, 98, 524, 196, 268, 642, 204, 742, 618, 169, 394, 127, 433, 1473, 779, 239, 144, 182, 254, 77, 508, 124, 1388, 75, 133, 301, 362, 170, 1078, 182, 490, 195, 321, 316, 447, 551, 216, 284, 253, 17, 107, 295, 356, 345, 1939, 1596, 291, 139, 259, 1291, 179, 528, 174, 61, 326, 20, 444, 522, 104, 1945, 120, 1943, 680, 1409, 850, 630, 288, 38, 695, 569, 106, 587, 208, 370, 606, 766, 535, 616, 200, 170, 224, 422, 970, 978, 498, 284, 241, 210, 151, 194, 178, 814, 205, 189, 215, 111, 236, 147, 237, 191, 691, 212, 432, 499, 445, 176, 333, 129, 414, 617, 380, 251, 199, 524, 515, 681, 160, 259, 295, 283, 178, 472, 786, 520, 202, 575, 575, 349, 549, 458, 166, 173, 508, 1522, 743, 414, 431, 393, 899, 137, 270, 131, 472, 457, 205, 778, 801, 133, 3000], "dependencies": { - "Array.prototype.fill": [4, 7, 10, 20, 22, 24, 25, 28, 35, 36, 53, 54, 56, 57, 59, 65, 72, 73, 74, 75, 76, 78, 80, 81, 85, 86, 87, 91, 93, 100, 101, 102, 103, 113, 115], - "Array.prototype.filter": [10, 11, 12, 16, 17, 20, 21, 22, 24, 25, 28, 35, 36, 40, 45, 53, 56, 57, 59, 61, 63, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 107, 113, 116], - "Array.prototype.find": [4, 10, 11, 16, 17, 20, 21, 22, 24, 25, 28, 35, 36, 40, 45, 53, 54, 56, 57, 59, 61, 63, 65, 72, 73, 74, 75, 76, 78, 80, 81, 85, 86, 87, 91, 93, 100, 101, 102, 103, 107, 113, 118], - "Array.prototype.findIndex": [4, 10, 11, 16, 17, 20, 21, 22, 24, 25, 28, 35, 36, 40, 45, 53, 54, 56, 57, 59, 61, 63, 65, 72, 73, 74, 75, 76, 78, 80, 81, 85, 86, 87, 91, 93, 100, 101, 102, 103, 107, 113, 117], - "Array.prototype.forEach": [8, 10, 11, 13, 16, 17, 20, 21, 22, 24, 25, 28, 35, 36, 40, 45, 53, 56, 57, 59, 61, 63, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 107, 113, 119], - "Array.from": [9, 10, 18, 19, 20, 21, 22, 24, 25, 26, 28, 35, 36, 40, 45, 48, 49, 53, 56, 57, 59, 60, 63, 65, 71, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 107, 113, 120], - "Array.isArray": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 61, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 121], - "Array.prototype.map": [10, 11, 12, 16, 17, 20, 21, 22, 24, 25, 28, 35, 36, 40, 45, 53, 56, 57, 59, 61, 63, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 107, 113, 122], - "Array.of": [10, 20, 21, 22, 24, 25, 26, 28, 35, 36, 53, 56, 57, 59, 63, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 107, 113, 123], - "Array.prototype.some": [10, 11, 13, 16, 17, 20, 21, 22, 24, 25, 28, 35, 36, 40, 45, 53, 56, 57, 59, 61, 63, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 107, 113, 124], - "Date.now": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 125], - "Date.prototype.toISOString": [10, 20, 21, 22, 24, 25, 27, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 97, 98, 100, 101, 102, 103, 107, 108, 113, 126], - "Date.prototype.toJSON": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 127], - "Date.prototype.toString": [24, 25, 28, 53, 57, 59, 73, 93, 113, 128], - "Function.prototype.name": [129], - "Number.isInteger": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 66, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 130], - "Number.isSafeInteger": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 66, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 131], - "Object.defineProperties": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 76, 78, 80, 81, 85, 86, 87, 91, 93, 100, 101, 102, 103, 113, 132], - "Object.defineProperty": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 133], - "Object.freeze": [6, 10, 14, 20, 22, 24, 25, 26, 28, 35, 36, 38, 53, 56, 57, 58, 59, 65, 72, 73, 74, 78, 79, 80, 81, 83, 85, 87, 91, 93, 100, 101, 102, 103, 113, 135], - "Object.getPrototypeOf": [10, 20, 22, 23, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 82, 85, 87, 91, 93, 100, 101, 102, 103, 113, 137], - "Object.isExtensible": [6, 10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 83, 85, 87, 91, 93, 100, 101, 102, 103, 113, 138], - "Object.isFrozen": [6, 10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 139], - "Object.isSealed": [6, 10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 140], - "Object.keys": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 86, 87, 91, 93, 100, 101, 102, 103, 113, 141], - "Object.preventExtensions": [6, 10, 14, 20, 22, 24, 25, 26, 28, 35, 36, 38, 53, 56, 57, 58, 59, 65, 72, 73, 74, 78, 79, 80, 81, 83, 85, 87, 91, 93, 100, 101, 102, 103, 113, 142], - "Object.seal": [6, 10, 14, 20, 22, 24, 25, 26, 28, 35, 36, 38, 53, 56, 57, 58, 59, 65, 72, 73, 74, 78, 79, 80, 81, 83, 85, 87, 91, 93, 100, 101, 102, 103, 113, 143], - "Object.setPrototypeOf": [3, 10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 88, 91, 93, 100, 101, 102, 103, 113, 144], - "Reflect.apply": [10, 20, 22, 24, 25, 28, 35, 36, 39, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 146], - "Reflect.construct": [2, 10, 15, 20, 21, 22, 24, 25, 28, 35, 36, 39, 42, 53, 54, 56, 57, 59, 63, 65, 72, 73, 74, 75, 76, 78, 80, 81, 85, 86, 87, 91, 93, 100, 101, 102, 103, 107, 113, 147], - "Reflect.defineProperty": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 148], - "Reflect.deleteProperty": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 149], - "Reflect.get": [10, 20, 22, 23, 24, 25, 28, 35, 36, 53, 56, 57, 59, 64, 65, 72, 73, 74, 78, 80, 81, 82, 85, 87, 91, 93, 100, 101, 102, 103, 113, 152], - "Reflect.getOwnPropertyDescriptor": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 150], - "Reflect.getPrototypeOf": [10, 20, 22, 23, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 82, 85, 87, 91, 93, 100, 101, 102, 103, 113, 151], - "Reflect.has": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 153], - "Reflect.isExtensible": [6, 10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 83, 85, 87, 91, 93, 100, 101, 102, 103, 113, 154], - "Reflect.ownKeys": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 155], - "Reflect.preventExtensions": [10, 20, 22, 24, 25, 28, 35, 36, 38, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 156], - "Reflect.setPrototypeOf": [3, 10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 88, 91, 93, 100, 101, 102, 103, 113, 157], - "String.prototype.codePointAt": [10, 20, 21, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 96, 100, 101, 102, 103, 107, 108, 113, 158], - "String.fromCodePoint": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 159], - "String.raw": [10, 20, 21, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 107, 108, 113, 160], - "String.prototype.repeat": [10, 20, 21, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 98, 100, 101, 102, 103, 107, 108, 113, 161], - "Object.entries": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 86, 87, 89, 91, 93, 100, 101, 102, 103, 113, 134], - "Object.getOwnPropertyDescriptors": [10, 20, 22, 24, 25, 26, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 87, 91, 93, 100, 101, 102, 103, 113, 136], - "Object.values": [10, 20, 22, 24, 25, 28, 35, 36, 53, 56, 57, 59, 65, 72, 73, 74, 78, 80, 81, 85, 86, 87, 89, 91, 93, 100, 101, 102, 103, 113, 145] + "Array.prototype.fill": [0, 5, 8, 11, 21, 23, 25, 26, 29, 36, 37, 54, 55, 57, 58, 60, 66, 73, 74, 75, 76, 77, 79, 81, 82, 86, 87, 88, 92, 94, 101, 102, 103, 104, 114, 116], + "Array.prototype.filter": [0, 11, 12, 13, 17, 18, 21, 22, 23, 25, 26, 29, 36, 37, 41, 46, 54, 57, 58, 60, 62, 64, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 108, 114, 117], + "Array.prototype.find": [0, 5, 11, 12, 17, 18, 21, 22, 23, 25, 26, 29, 36, 37, 41, 46, 54, 55, 57, 58, 60, 62, 64, 66, 73, 74, 75, 76, 77, 79, 81, 82, 86, 87, 88, 92, 94, 101, 102, 103, 104, 108, 114, 119], + "Array.prototype.findIndex": [0, 5, 11, 12, 17, 18, 21, 22, 23, 25, 26, 29, 36, 37, 41, 46, 54, 55, 57, 58, 60, 62, 64, 66, 73, 74, 75, 76, 77, 79, 81, 82, 86, 87, 88, 92, 94, 101, 102, 103, 104, 108, 114, 118], + "Array.prototype.forEach": [0, 9, 11, 12, 14, 17, 18, 21, 22, 23, 25, 26, 29, 36, 37, 41, 46, 54, 57, 58, 60, 62, 64, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 108, 114, 120], + "Array.from": [0, 10, 11, 19, 20, 21, 22, 23, 25, 26, 27, 29, 36, 37, 41, 46, 49, 50, 54, 57, 58, 60, 61, 64, 66, 72, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 108, 114, 121], + "Array.isArray": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 62, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 122], + "Array.prototype.map": [0, 11, 12, 13, 17, 18, 21, 22, 23, 25, 26, 29, 36, 37, 41, 46, 54, 57, 58, 60, 62, 64, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 108, 114, 123], + "Array.of": [0, 11, 21, 22, 23, 25, 26, 27, 29, 36, 37, 54, 57, 58, 60, 64, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 108, 114, 124], + "Array.prototype.some": [0, 11, 12, 14, 17, 18, 21, 22, 23, 25, 26, 29, 36, 37, 41, 46, 54, 57, 58, 60, 62, 64, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 108, 114, 125], + "Date.now": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 126], + "Date.prototype.toISOString": [0, 11, 21, 22, 23, 25, 26, 28, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 98, 99, 101, 102, 103, 104, 108, 109, 114, 127], + "Date.prototype.toJSON": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 128], + "Date.prototype.toString": [0, 25, 26, 29, 54, 58, 60, 74, 94, 114, 129], + "Function.prototype.name": [0, 130], + "Number.isInteger": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 67, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 131], + "Number.isSafeInteger": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 67, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 132], + "Object.defineProperties": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 77, 79, 81, 82, 86, 87, 88, 92, 94, 101, 102, 103, 104, 114, 133], + "Object.defineProperty": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 134], + "Object.freeze": [0, 7, 11, 15, 21, 23, 25, 26, 27, 29, 36, 37, 39, 54, 57, 58, 59, 60, 66, 73, 74, 75, 79, 80, 81, 82, 84, 86, 88, 92, 94, 101, 102, 103, 104, 114, 136], + "Object.getPrototypeOf": [0, 11, 21, 23, 24, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 83, 86, 88, 92, 94, 101, 102, 103, 104, 114, 138], + "Object.isExtensible": [0, 7, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 84, 86, 88, 92, 94, 101, 102, 103, 104, 114, 139], + "Object.isFrozen": [0, 7, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 140], + "Object.isSealed": [0, 7, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 141], + "Object.keys": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 87, 88, 92, 94, 101, 102, 103, 104, 114, 142], + "Object.preventExtensions": [0, 7, 11, 15, 21, 23, 25, 26, 27, 29, 36, 37, 39, 54, 57, 58, 59, 60, 66, 73, 74, 75, 79, 80, 81, 82, 84, 86, 88, 92, 94, 101, 102, 103, 104, 114, 143], + "Object.seal": [0, 7, 11, 15, 21, 23, 25, 26, 27, 29, 36, 37, 39, 54, 57, 58, 59, 60, 66, 73, 74, 75, 79, 80, 81, 82, 84, 86, 88, 92, 94, 101, 102, 103, 104, 114, 144], + "Object.setPrototypeOf": [0, 4, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 89, 92, 94, 101, 102, 103, 104, 114, 145], + "Reflect.apply": [0, 11, 21, 23, 25, 26, 29, 36, 37, 40, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 147], + "Reflect.construct": [0, 3, 11, 16, 21, 22, 23, 25, 26, 29, 36, 37, 40, 43, 54, 55, 57, 58, 60, 64, 66, 73, 74, 75, 76, 77, 79, 81, 82, 86, 87, 88, 92, 94, 101, 102, 103, 104, 108, 114, 148], + "Reflect.defineProperty": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 149], + "Reflect.deleteProperty": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 150], + "Reflect.get": [0, 11, 21, 23, 24, 25, 26, 29, 36, 37, 54, 57, 58, 60, 65, 66, 73, 74, 75, 79, 81, 82, 83, 86, 88, 92, 94, 101, 102, 103, 104, 114, 153], + "Reflect.getOwnPropertyDescriptor": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 151], + "Reflect.getPrototypeOf": [0, 11, 21, 23, 24, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 83, 86, 88, 92, 94, 101, 102, 103, 104, 114, 152], + "Reflect.has": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 154], + "Reflect.isExtensible": [0, 7, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 84, 86, 88, 92, 94, 101, 102, 103, 104, 114, 155], + "Reflect.ownKeys": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 156], + "Reflect.preventExtensions": [0, 11, 21, 23, 25, 26, 29, 36, 37, 39, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 157], + "Reflect.setPrototypeOf": [0, 4, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 89, 92, 94, 101, 102, 103, 104, 114, 158], + "String.prototype.codePointAt": [0, 11, 21, 22, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 97, 101, 102, 103, 104, 108, 109, 114, 159], + "String.fromCodePoint": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 160], + "String.raw": [0, 11, 21, 22, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 108, 109, 114, 161], + "String.prototype.repeat": [0, 11, 21, 22, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 99, 101, 102, 103, 104, 108, 109, 114, 162], + "Object.entries": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 87, 88, 90, 92, 94, 101, 102, 103, 104, 114, 135], + "Object.getOwnPropertyDescriptors": [0, 11, 21, 23, 25, 26, 27, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 88, 92, 94, 101, 102, 103, 104, 114, 137], + "Object.values": [0, 11, 21, 23, 25, 26, 29, 36, 37, 54, 57, 58, 60, 66, 73, 74, 75, 79, 81, 82, 86, 87, 88, 90, 92, 94, 101, 102, 103, 104, 114, 146], + "focus-visible": [163] }, - "maxSize": 72786, - "baseSize": 11897 + "maxSize": 87683 } \ No newline at end of file diff --git a/core/scripts/legacy-javascript/create-polyfill-size-estimation.js b/core/scripts/legacy-javascript/create-polyfill-size-estimation.js index a0ce37b21d43..3ad87e10fda2 100644 --- a/core/scripts/legacy-javascript/create-polyfill-size-estimation.js +++ b/core/scripts/legacy-javascript/create-polyfill-size-estimation.js @@ -23,8 +23,6 @@ * @property {Record} dependencies indexed by the polyfill name. array of module indices * @property {number[]} moduleSizes indices in the arrays in `.dependencies` are for this array * @property {number} maxSize sum of `.moduleSizes` - * @property {number} baseSize size of using core-js at all. sum of common modules, and does not show up - * in `.dependencies` or `.moduleSizes` */ import fs from 'fs'; @@ -39,6 +37,7 @@ import {LH_ROOT} from '../../../root.js'; const hash = makeHash(); const VARIANT_DIR = `${LH_ROOT}/core/scripts/legacy-javascript/variants/${hash}`; const OUTPUT_PATH = `${LH_ROOT}/core/audits/byte-efficiency/polyfill-graph-data.json`; +const COMMON_MODULE = 'commonCoreJs'; /** * @param {number[]} arr @@ -55,7 +54,7 @@ function getPolyfillDependencies() { /** @type {Map} */ const polyfillDependencies = new Map(); - for (const {name, coreJs3Module} of LegacyJavascript.getPolyfillData()) { + for (const {name, coreJs3Module} of LegacyJavascript.getCoreJsPolyfillData()) { const folder = coreJs3Module.replace(/[^a-zA-Z0-9]+/g, '-'); const bundleMapPath = `${VARIANT_DIR}/core-js-3-only-polyfill/${folder}/main.bundle.min.js.map`; @@ -64,21 +63,24 @@ function getPolyfillDependencies() { polyfillDependencies.set(name, bundleMap.sources.filter(s => s.startsWith('node_modules'))); } - const allPolyfillModules = [...polyfillDependencies.values()]; - const commonModules = allPolyfillModules[0].filter(potentialCommonModule => { - return allPolyfillModules.every(modules => modules.includes(potentialCommonModule)); - }); - for (const [name, modules] of polyfillDependencies.entries()) { - polyfillDependencies.set(name, modules.filter(module => !commonModules.includes(module))); - } - polyfillDependencies.set('common', commonModules); - return polyfillDependencies; } async function main() { const polyfillDependencies = getPolyfillDependencies(); + // Find the common modules amongst all the corejs polyfills, and replace with a singular + // common module to make the graph smaller. + const allCoreJsPolyfillModules = [...polyfillDependencies.values()]; + const commonModules = allCoreJsPolyfillModules[0].filter(potentialCommonModule => { + return allCoreJsPolyfillModules.every(modules => modules.includes(potentialCommonModule)); + }); + for (const [name, modules] of polyfillDependencies.entries()) { + const modulesCommonFlattened = modules.filter(module => !commonModules.includes(module)); + modulesCommonFlattened.unshift(COMMON_MODULE); + polyfillDependencies.set(name, modulesCommonFlattened); + } + const bundlePath = `${VARIANT_DIR}/all-legacy-polyfills/all-legacy-polyfills-core-js-3/main.bundle.min.js`; const bundleContents = fs.readFileSync(bundlePath, 'utf-8'); @@ -97,23 +99,26 @@ async function main() { const moduleSizes = allModules.map(module => { return bundleFileSizes[module]; }); + allModules.unshift(COMMON_MODULE); + moduleSizes.unshift(sum(commonModules.map(m => bundleFileSizes[m]))); /** @type {Record} */ const polyfillDependenciesEncoded = {}; for (const [name, modules] of polyfillDependencies.entries()) { - if (name === 'common') continue; polyfillDependenciesEncoded[name] = modules.map(module => allModules.indexOf(module)); } + // For now, hardcode non-corejs polyfills. + moduleSizes.push(3000); + polyfillDependenciesEncoded['focus-visible'] = [moduleSizes.length - 1]; + const maxSize = sum(moduleSizes); - const baseSize = sum((polyfillDependencies.get('common') || []).map(m => bundleFileSizes[m])); /** @type {PolyfillSizeEstimator} */ const polyfillDependencyGraphData = { moduleSizes, dependencies: polyfillDependenciesEncoded, maxSize, - baseSize, }; const json = prettyJSONStringify(polyfillDependencyGraphData, { diff --git a/core/scripts/legacy-javascript/run.js b/core/scripts/legacy-javascript/run.js index 9484b11eeea2..791990ff956d 100644 --- a/core/scripts/legacy-javascript/run.js +++ b/core/scripts/legacy-javascript/run.js @@ -34,7 +34,7 @@ const STAGE = process.env.STAGE || 'all'; const mainCode = fs.readFileSync(`${scriptDir}/main.js`, 'utf-8'); const plugins = LegacyJavascript.getTransformPatterns().map(pattern => pattern.name); -const polyfills = LegacyJavascript.getPolyfillData(); +const polyfills = LegacyJavascript.getCoreJsPolyfillData(); /** * @param {string} command diff --git a/core/test/audits/byte-efficiency/legacy-javascript-test.js b/core/test/audits/byte-efficiency/legacy-javascript-test.js index bb3758ceb48e..7725059348ba 100644 --- a/core/test/audits/byte-efficiency/legacy-javascript-test.js +++ b/core/test/audits/byte-efficiency/legacy-javascript-test.js @@ -251,6 +251,28 @@ describe('LegacyJavaScript audit', () => { }, ]); }); + + it('detects non-corejs modules from source maps', async () => { + const map = { + sources: ['node_modules/focus-visible/dist/focus-visible.js'], + mappings: 'blah', + }; + const script = { + code: '// blah blah blah', + url: 'https://www.example.com/0.js', + map, + }; + const result = await getResult([script]); + + expect(result.items).toHaveLength(1); + expect(result.items[0].subItems.items).toMatchObject([ + { + signal: 'focus-visible', + location: {line: 0, column: 0}, + }, + ]); + expect(result.items[0].wastedBytes).toBe(3000); + }); }); describe('LegacyJavaScript signals', () => {