aoc/node_modules/@babel/helper-plugin-utils/lib/index.js.map

1 line
7.1 KiB
Plaintext
Raw Normal View History

2022-12-03 22:11:42 +00:00
{"version":3,"names":["apiPolyfills","assertVersion","api","range","throwVersionError","version","targets","assumption","undefined","declare","builder","options","dirname","clonedApi","name","Object","keys","copyApiObject","declarePreset","proto","test","getPrototypeOf","has","obj","key","prototype","hasOwnProperty","call","Number","isInteger","Error","limit","stackTraceLimit","err","slice","assign","code"],"sources":["../src/index.ts"],"sourcesContent":["import type {\n PluginAPI,\n PluginObject,\n PluginPass,\n PresetAPI,\n PresetObject,\n} from \"@babel/core\";\n\ntype APIPolyfillFactory<T extends keyof PluginAPI> = (\n api: PluginAPI,\n) => PluginAPI[T];\n\ntype APIPolyfills = {\n assertVersion: APIPolyfillFactory<\"assertVersion\">;\n targets: APIPolyfillFactory<\"targets\">;\n assumption: APIPolyfillFactory<\"assumption\">;\n};\n\nconst apiPolyfills: APIPolyfills = {\n // Not supported by Babel 7 and early versions of Babel 7 beta.\n // It's important that this is polyfilled for older Babel versions\n // since it's needed to report the version mismatch.\n assertVersion: (api: PluginAPI) => (range: number | string) => {\n throwVersionError(range, api.version);\n },\n // This is supported starting from Babel 7.13\n // TODO(Babel 8): Remove this polyfill\n targets: () => () => {\n return {};\n },\n // This is supported starting from Babel 7.13\n // TODO(Babel 8): Remove this polyfill\n assumption: () => () => {\n return undefined;\n },\n};\n\nexport function declare<State = {}, Option = {}>(\n builder: (\n api: PluginAPI,\n options: Option,\n dirname: string,\n ) => PluginObject<State & PluginPass>,\n): (\n api: PluginAPI,\n options: Option,\n dirname: string,\n) => PluginObject<State & PluginPass> {\n return (api, options: Option, dirname: string) => {\n let clonedApi: PluginAPI;\n\n for (const name of Object.keys(\n apiPolyfills,\n ) as (keyof typeof apiPolyfills)[]) {\n if (api[name]) continue;\n\n // TODO: Use ??= when flow lets us to do so\n clonedApi = clonedApi ?? copyApiObject(api);\n // @ts-expect-error The shape of API polyfill is guaranteed by APIPolyfillFactory\n clonedApi[name] = apiPolyfills[name](clonedApi);\n }\n\n // @ts-expect-error options || {} may not be assigned to Options\n return builder(clonedApi ?? api, options || {}, dirname);\n };\n}\n\nexport const declarePreset = declare as <Option = {}>(\n builder: (api: PresetAPI, options: Option, dirname: string) => PresetObject,\n) => (api: PresetAPI, options: Option, dirname: string) => PresetObject;\n\nfunction copyApiObject(api: PluginAPI): PluginAPI {\n // Babel >= 7 <= beta.41 passed the API as a new object that had\n // babel/core as the prototype. While slightly faster, it also\n // means that the Object.assign copy below fails. Rather than\n // keep complexity, the Babel 6 behavior has been reverted and this\n // normalizes all that for Babel 7.\n let proto = null;\n if (typeof api.version === \"string\" && /^7\\./.test(api.version)) {\n proto = Object.getPrototypeOf(api);\n if (\n proto &&\n (!has(proto, \"version\") ||\n !has(proto, \"transform\") ||\n !has(proto, \"template\") ||\n !has(proto, \"types\"))\n ) {\n proto = null;\n }\n }\n\n return {\n ...proto,\n ...api,\n };\n}\n\nfunction has(obj: {}, key: string) {\n return Object.prototype.hasOwnProperty.call(obj, key);\n}\n\nfunction throwVersionError(range: string | number, version: string) {\n if (typeof range === \"number\") {\n if (!Number.isInteger(range)) {\n throw new Error(\"Expected string or integer value.\");\n }\n range = `^${range}.0.0-0`;\n }\n if (typeof range !== \"string\") {\n throw new Error(\"Expected string or integer value.\");\n }\n\n const limit = Error.stackTraceLimit;\n\n if (typeof limit === \"number\" && limit < 25) {\n // Bump up the limit if needed so that users are more likely\n // to be able to see what is calling Babel.\n Error.stackTraceLimit = 25;\n }\n\n let e