diff --git a/lib/BrowserSelection.js b/lib/BrowserSelection.js index 5ee2a84..16d8953 100644 --- a/lib/BrowserSelection.js +++ b/lib/BrowserSelection.js @@ -139,6 +139,11 @@ export default class BrowserSelection { * `feature-name` is a caniuse-db slug. */ compileBrowserSupport() { + const cacheKey = JSON.stringify(this.#list); + if (BrowserSelection.#browserSupportCache.has(cacheKey)) { + return BrowserSelection.#browserSupportCache.get(cacheKey); + } + /** @type {Partial>} */ const result = {}; @@ -164,11 +169,12 @@ export default class BrowserSelection { } } + BrowserSelection.#browserSupportCache.set(cacheKey, result); return result; } - /** @type {Map} @readonly */ - static #missingSupportCache = new Map(); + /** @type {Map} */ + static #browserSupportCache = new Map(); /** * @see BrowserSelection.compileBrowserSupport @@ -177,19 +183,10 @@ export default class BrowserSelection { */ static missingSupport(...constructorParameters) { const [query, path] = constructorParameters; - // browserslist only uses `path` if `query` is not provided. - const key = query ? JSON.stringify(query) : path; - - if (key && this.#missingSupportCache.has(key)) { - return this.#missingSupportCache.get(key); - } - const selection = new BrowserSelection(query, path); - const result = { + return { browsers: selection.list(), features: selection.compileBrowserSupport(), }; - if (key) this.#missingSupportCache.set(key, result); - return result; } }