UNPKG

@babel/helper-define-polyfill-provider

Version:

Babel helper to create your own polyfill provider

1 lines 83.4 kB
{"version":3,"file":"index.browser.mjs","sources":["../src/utils.ts","../src/imports-injector.ts","../src/debug-utils.ts","../src/normalize-options.ts","../src/visitors/usage.ts","../src/visitors/entry.ts","../src/browser/dependencies.ts","../src/meta-resolver.ts","../src/index.ts"],"sourcesContent":["import { types as t, template } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\nimport type { Utils } from \"./types\";\nimport type ImportsCachedInjector from \"./imports-injector\";\n\nexport const PossibleGlobalObjects = new Set<string>([\n \"global\",\n \"globalThis\",\n \"self\",\n \"window\",\n]);\n\nexport function intersection<T>(a: Set<T>, b: Set<T>): Set<T> {\n const result = new Set<T>();\n a.forEach(v => b.has(v) && result.add(v));\n return result;\n}\n\nexport function has(object: any, key: string) {\n return Object.prototype.hasOwnProperty.call(object, key);\n}\n\nfunction resolve(\n path: NodePath,\n seen: Set<NodePath> = new Set(),\n): NodePath | undefined {\n if (seen.has(path)) return;\n seen.add(path);\n\n if (path.isVariableDeclarator()) {\n if (path.get(\"id\").isIdentifier()) {\n return resolve(path.get(\"init\"), seen);\n }\n } else if (path.isReferencedIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n if (!binding) return path;\n if (!binding.constant) return;\n return resolve(binding.path, seen);\n }\n return path;\n}\n\nfunction resolveId(path: NodePath): string {\n if (\n path.isIdentifier() &&\n !path.scope.hasBinding(path.node.name, /* noGlobals */ true)\n ) {\n return path.node.name;\n }\n\n // globalThis.Object / window.Array / self.Map / global.Set -> resolve to\n // the property name, because accessing a built-in through a global object\n // reference is equivalent to accessing it directly.\n if (path.isMemberExpression() && !path.node.computed) {\n const object = path.get(\"object\");\n const property = path.get(\"property\");\n if (\n object.isIdentifier() &&\n !object.scope.hasBinding(object.node.name, /* noGlobals */ true) &&\n PossibleGlobalObjects.has(object.node.name) &&\n property.isIdentifier()\n ) {\n return property.node.name;\n }\n }\n\n const resolved = resolve(path);\n if (resolved?.isIdentifier()) {\n return resolved.node.name;\n }\n}\n\nexport function resolveKey(\n path: NodePath<t.Expression | t.PrivateName>,\n computed: boolean = false,\n) {\n const { scope } = path;\n if (path.isStringLiteral()) return path.node.value;\n const isIdentifier = path.isIdentifier();\n if (\n isIdentifier &&\n !(computed || (path.parent as t.MemberExpression).computed)\n ) {\n return path.node.name;\n }\n\n if (\n computed &&\n path.isMemberExpression() &&\n path.get(\"object\").isIdentifier({ name: \"Symbol\" }) &&\n !scope.hasBinding(\"Symbol\", /* noGlobals */ true)\n ) {\n const sym = resolveKey(path.get(\"property\"), path.node.computed);\n if (sym) return \"Symbol.\" + sym;\n }\n\n if (\n isIdentifier\n ? scope.hasBinding(path.node.name, /* noGlobals */ true)\n : path.isPure()\n ) {\n const { value } = path.evaluate();\n if (typeof value === \"string\") return value;\n }\n}\n\nfunction resolveInstance(obj: NodePath, seen: Set<NodePath>): string | null {\n const source = resolveSource(obj, seen);\n return source.placement === \"prototype\" ? source.id : null;\n}\n\nexport function resolveSource(\n obj: NodePath,\n seen: Set<NodePath>,\n): {\n id: string | null;\n placement: \"prototype\" | \"static\" | null;\n} {\n if (seen.has(obj)) {\n return { id: null, placement: null };\n }\n seen.add(obj);\n\n if (\n obj.isMemberExpression() &&\n obj.get(\"property\").isIdentifier({ name: \"prototype\" })\n ) {\n const id = resolveId(obj.get(\"object\"));\n\n if (id) {\n return { id, placement: \"prototype\" };\n }\n return { id: null, placement: null };\n }\n\n const id = resolveId(obj);\n if (id) {\n return { id, placement: \"static\" };\n }\n\n const path = resolve(obj);\n\n switch (path?.type) {\n case \"NullLiteral\":\n return { id: null, placement: null };\n case \"RegExpLiteral\":\n return { id: \"RegExp\", placement: \"prototype\" };\n case \"StringLiteral\":\n case \"TemplateLiteral\":\n return { id: \"String\", placement: \"prototype\" };\n case \"NumericLiteral\":\n return { id: \"Number\", placement: \"prototype\" };\n case \"BooleanLiteral\":\n return { id: \"Boolean\", placement: \"prototype\" };\n case \"BigIntLiteral\":\n return { id: \"BigInt\", placement: \"prototype\" };\n case \"ObjectExpression\":\n return { id: \"Object\", placement: \"prototype\" };\n case \"ArrayExpression\":\n return { id: \"Array\", placement: \"prototype\" };\n case \"FunctionExpression\":\n case \"ArrowFunctionExpression\":\n case \"ClassExpression\":\n return { id: \"Function\", placement: \"prototype\" };\n // new Constructor() -> resolve the constructor name\n case \"NewExpression\": {\n const calleeId = resolveId(\n (path as NodePath<t.NewExpression>).get(\"callee\"),\n );\n if (calleeId) return { id: calleeId, placement: \"prototype\" };\n return { id: null, placement: null };\n }\n // Unary expressions -> result type depends on operator\n case \"UnaryExpression\": {\n const { operator } = path.node as t.UnaryExpression;\n if (operator === \"typeof\")\n return { id: \"String\", placement: \"prototype\" };\n if (operator === \"!\" || operator === \"delete\")\n return { id: \"Boolean\", placement: \"prototype\" };\n // Unary + always produces Number (throws on BigInt)\n if (operator === \"+\") return { id: \"Number\", placement: \"prototype\" };\n // Unary - and ~ can produce Number or BigInt depending on operand\n if (operator === \"-\" || operator === \"~\") {\n const arg = resolveInstance(\n (path as NodePath<t.UnaryExpression>).get(\"argument\"),\n seen,\n );\n if (arg === \"BigInt\") return { id: \"BigInt\", placement: \"prototype\" };\n if (arg !== null) return { id: \"Number\", placement: \"prototype\" };\n return { id: null, placement: null };\n }\n return { id: null, placement: null };\n }\n // ++i, i++ produce Number or BigInt depending on the argument\n case \"UpdateExpression\": {\n const arg = resolveInstance(\n (path as NodePath<t.UpdateExpression>).get(\"argument\"),\n seen,\n );\n if (arg === \"BigInt\") return { id: \"BigInt\", placement: \"prototype\" };\n if (arg !== null) return { id: \"Number\", placement: \"prototype\" };\n return { id: null, placement: null };\n }\n // Binary expressions -> result type depends on operator\n case \"BinaryExpression\": {\n const { operator } = path.node as t.BinaryExpression;\n if (\n operator === \"==\" ||\n operator === \"!=\" ||\n operator === \"===\" ||\n operator === \"!==\" ||\n operator === \"<\" ||\n operator === \">\" ||\n operator === \"<=\" ||\n operator === \">=\" ||\n operator === \"instanceof\" ||\n operator === \"in\"\n ) {\n return { id: \"Boolean\", placement: \"prototype\" };\n }\n // >>> always produces Number\n if (operator === \">>>\") {\n return { id: \"Number\", placement: \"prototype\" };\n }\n // Arithmetic and bitwise operators can produce Number or BigInt\n if (\n operator === \"-\" ||\n operator === \"*\" ||\n operator === \"/\" ||\n operator === \"%\" ||\n operator === \"**\" ||\n operator === \"&\" ||\n operator === \"|\" ||\n operator === \"^\" ||\n operator === \"<<\" ||\n operator === \">>\"\n ) {\n const left = resolveInstance(\n (path as NodePath<t.BinaryExpression>).get(\"left\"),\n seen,\n );\n const right = resolveInstance(\n (path as NodePath<t.BinaryExpression>).get(\"right\"),\n seen,\n );\n if (left === \"BigInt\" && right === \"BigInt\") {\n return { id: \"BigInt\", placement: \"prototype\" };\n }\n if (left !== null && right !== null) {\n return { id: \"Number\", placement: \"prototype\" };\n }\n return { id: null, placement: null };\n }\n // + depends on operand types: string wins, otherwise number or bigint\n if (operator === \"+\") {\n const left = resolveInstance(\n (path as NodePath<t.BinaryExpression>).get(\"left\"),\n seen,\n );\n const right = resolveInstance(\n (path as NodePath<t.BinaryExpression>).get(\"right\"),\n seen,\n );\n if (left === \"String\" || right === \"String\") {\n return { id: \"String\", placement: \"prototype\" };\n }\n if (left === \"Number\" && right === \"Number\") {\n return { id: \"Number\", placement: \"prototype\" };\n }\n if (left === \"BigInt\" && right === \"BigInt\") {\n return { id: \"BigInt\", placement: \"prototype\" };\n }\n }\n return { id: null, placement: null };\n }\n // (a, b, c) -> the result is the last expression\n case \"SequenceExpression\": {\n const expressions = (path as NodePath<t.SequenceExpression>).get(\n \"expressions\",\n );\n return resolveSource(expressions[expressions.length - 1], seen);\n }\n // a = b -> the result is the right side\n case \"AssignmentExpression\": {\n if ((path.node as t.AssignmentExpression).operator === \"=\") {\n return resolveSource(\n (path as NodePath<t.AssignmentExpression>).get(\"right\"),\n seen,\n );\n }\n return { id: null, placement: null };\n }\n // a ? b : c -> if both branches resolve to the same type, use it\n case \"ConditionalExpression\": {\n const consequent = resolveSource(\n (path as NodePath<t.ConditionalExpression>).get(\"consequent\"),\n seen,\n );\n const alternate = resolveSource(\n (path as NodePath<t.ConditionalExpression>).get(\"alternate\"),\n seen,\n );\n if (consequent.id && consequent.id === alternate.id) {\n return consequent;\n }\n return { id: null, placement: null };\n }\n // (expr) -> unwrap parenthesized expressions\n case \"ParenthesizedExpression\":\n return resolveSource(\n (path as NodePath<t.ParenthesizedExpression>).get(\"expression\"),\n seen,\n );\n // TypeScript / Flow type wrappers -> unwrap to the inner expression\n case \"TSAsExpression\":\n case \"TSSatisfiesExpression\":\n case \"TSNonNullExpression\":\n case \"TSInstantiationExpression\":\n case \"TSTypeAssertion\":\n case \"TypeCastExpression\":\n return resolveSource(path.get(\"expression\") as NodePath, seen);\n }\n\n return { id: null, placement: null };\n}\n\nexport function getImportSource({ node }: NodePath<t.ImportDeclaration>) {\n if (node.specifiers.length === 0) return node.source.value;\n}\n\nexport function getRequireSource({ node }: NodePath<t.Statement>) {\n if (!t.isExpressionStatement(node)) return;\n const { expression } = node;\n if (\n t.isCallExpression(expression) &&\n t.isIdentifier(expression.callee) &&\n expression.callee.name === \"require\" &&\n expression.arguments.length === 1 &&\n t.isStringLiteral(expression.arguments[0])\n ) {\n return expression.arguments[0].value;\n }\n}\n\nfunction hoist<T extends t.Node>(node: T): T {\n // @ts-expect-error\n node._blockHoist = 3;\n return node;\n}\n\nexport function createUtilsGetter(cache: ImportsCachedInjector) {\n return (path: NodePath): Utils => {\n const prog = path.findParent(p => p.isProgram()) as NodePath<t.Program>;\n\n return {\n injectGlobalImport(url, moduleName) {\n cache.storeAnonymous(prog, url, moduleName, (isScript, source) => {\n return isScript\n ? template.statement.ast`require(${source})`\n : t.importDeclaration([], source);\n });\n },\n injectNamedImport(url, name, hint = name, moduleName) {\n return cache.storeNamed(\n prog,\n url,\n name,\n moduleName,\n (isScript, source, name) => {\n const id = prog.scope.generateUidIdentifier(hint);\n return {\n node: isScript\n ? hoist(template.statement.ast`\n var ${id} = require(${source}).${name}\n `)\n : t.importDeclaration([t.importSpecifier(id, name)], source),\n name: id.name,\n };\n },\n );\n },\n injectDefaultImport(url, hint = url, moduleName) {\n return cache.storeNamed(\n prog,\n url,\n \"default\",\n moduleName,\n (isScript, source) => {\n const id = prog.scope.generateUidIdentifier(hint);\n return {\n node: isScript\n ? hoist(template.statement.ast`var ${id} = require(${source})`)\n : t.importDeclaration([t.importDefaultSpecifier(id)], source),\n name: id.name,\n };\n },\n );\n },\n };\n };\n}\n","import type { NodePath } from \"@babel/traverse\";\nimport { types as t } from \"@babel/core\";\n\ntype StrMap<K> = Map<string, K>;\n\nexport default class ImportsCachedInjector {\n _imports: WeakMap<NodePath<t.Program>, StrMap<string>>;\n _anonymousImports: WeakMap<NodePath<t.Program>, Set<string>>;\n _lastImports: WeakMap<\n NodePath<t.Program>,\n Array<{ path: NodePath<t.Node>; index: number }>\n >;\n _resolver: (url: string) => string;\n _getPreferredIndex: (url: string) => number;\n\n constructor(\n resolver: (url: string) => string,\n getPreferredIndex: (url: string) => number,\n ) {\n this._imports = new WeakMap();\n this._anonymousImports = new WeakMap();\n this._lastImports = new WeakMap();\n this._resolver = resolver;\n this._getPreferredIndex = getPreferredIndex;\n }\n\n storeAnonymous(\n programPath: NodePath<t.Program>,\n url: string,\n moduleName: string,\n getVal: (\n isScript: boolean,\n source: t.StringLiteral,\n ) => t.Statement | t.Declaration,\n ) {\n const key = this._normalizeKey(programPath, url);\n const imports = this._ensure<Set<string>>(\n this._anonymousImports,\n programPath,\n Set,\n );\n\n if (imports.has(key)) return;\n\n const node = getVal(\n programPath.node.sourceType === \"script\",\n t.stringLiteral(this._resolver(url)),\n );\n imports.add(key);\n this._injectImport(programPath, node, moduleName);\n }\n\n storeNamed(\n programPath: NodePath<t.Program>,\n url: string,\n name: string,\n moduleName: string,\n getVal: (\n isScript: boolean,\n // eslint-disable-next-line no-undef\n source: t.StringLiteral,\n // eslint-disable-next-line no-undef\n name: t.Identifier,\n ) => { node: t.Statement | t.Declaration; name: string },\n ) {\n const key = this._normalizeKey(programPath, url, name);\n const imports = this._ensure<Map<string, any>>(\n this._imports,\n programPath,\n Map,\n );\n\n if (!imports.has(key)) {\n const { node, name: id } = getVal(\n programPath.node.sourceType === \"script\",\n t.stringLiteral(this._resolver(url)),\n t.identifier(name),\n );\n imports.set(key, id);\n this._injectImport(programPath, node, moduleName);\n }\n\n return t.identifier(imports.get(key));\n }\n\n _injectImport(\n programPath: NodePath<t.Program>,\n node: t.Statement | t.Declaration,\n moduleName: string,\n ) {\n const newIndex = this._getPreferredIndex(moduleName);\n const lastImports = this._lastImports.get(programPath) ?? [];\n\n const isPathStillValid = (path: NodePath) =>\n path.node &&\n // Sometimes the AST is modified and the \"last import\"\n // we have has been replaced\n path.parent === programPath.node &&\n path.container === programPath.node.body;\n\n let last: NodePath;\n\n if (newIndex === Infinity) {\n // Fast path: we can always just insert at the end if newIndex is `Infinity`\n if (lastImports.length > 0) {\n last = lastImports[lastImports.length - 1].path;\n if (!isPathStillValid(last)) last = undefined;\n }\n } else {\n for (const [i, data] of lastImports.entries()) {\n const { path, index } = data;\n if (isPathStillValid(path)) {\n if (newIndex < index) {\n const [newPath] = path.insertBefore(node);\n lastImports.splice(i, 0, { path: newPath, index: newIndex });\n return;\n }\n last = path;\n }\n }\n }\n\n if (last) {\n const [newPath] = last.insertAfter(node);\n lastImports.push({ path: newPath, index: newIndex });\n } else {\n const [newPath] = programPath.unshiftContainer(\"body\", [node]);\n this._lastImports.set(programPath, [{ path: newPath, index: newIndex }]);\n }\n }\n\n _ensure<C extends Map<string, any> | Set<string>>(\n map: WeakMap<NodePath<t.Program>, C>,\n programPath: NodePath<t.Program>,\n Collection: { new (...args: any): C },\n ): C {\n let collection = map.get(programPath);\n if (!collection) {\n collection = new Collection();\n map.set(programPath, collection);\n }\n return collection;\n }\n\n _normalizeKey(\n programPath: NodePath<t.Program>,\n url: string,\n name: string = \"\",\n ): string {\n const { sourceType } = programPath.node;\n\n // If we rely on the imported binding (the \"name\" parameter), we also need to cache\n // based on the sourceType. This is because the module transforms change the names\n // of the import variables.\n return `${name && sourceType}::${url}::${name}`;\n }\n}\n","import { prettifyTargets } from \"@babel/helper-compilation-targets\";\n\nimport type { Targets } from \"./types\";\n\nexport const presetEnvSilentDebugHeader =\n \"#__secret_key__@babel/preset-env__don't_log_debug_header_and_resolved_targets\";\n\nexport function stringifyTargetsMultiline(targets: Targets): string {\n return JSON.stringify(prettifyTargets(targets), null, 2);\n}\n\nexport function stringifyTargets(targets: Targets): string {\n return JSON.stringify(targets)\n .replace(/,/g, \", \")\n .replace(/^\\{\"/, '{ \"')\n .replace(/\"\\}$/, '\" }');\n}\n","import { intersection } from \"./utils\";\nimport type {\n Pattern,\n PluginOptions,\n MissingDependenciesOption,\n} from \"./types\";\n\nfunction patternToRegExp(pattern: Pattern): RegExp | null {\n if (pattern instanceof RegExp) return pattern;\n\n try {\n return new RegExp(`^${pattern}$`);\n } catch {\n return null;\n }\n}\n\nfunction buildUnusedError(label, unused) {\n if (!unused.length) return \"\";\n return (\n ` - The following \"${label}\" patterns didn't match any polyfill:\\n` +\n unused.map(original => ` ${String(original)}\\n`).join(\"\")\n );\n}\n\nfunction buldDuplicatesError(duplicates) {\n if (!duplicates.size) return \"\";\n return (\n ` - The following polyfills were matched both by \"include\" and \"exclude\" patterns:\\n` +\n Array.from(duplicates, name => ` ${name}\\n`).join(\"\")\n );\n}\n\nexport function validateIncludeExclude(\n provider: string,\n polyfills: Map<string, unknown>,\n includePatterns: Pattern[],\n excludePatterns: Pattern[],\n) {\n let current;\n const filter = pattern => {\n const regexp = patternToRegExp(pattern);\n if (!regexp) return false;\n\n let matched = false;\n for (const polyfill of polyfills.keys()) {\n if (regexp.test(polyfill)) {\n matched = true;\n current.add(polyfill);\n }\n }\n return !matched;\n };\n\n // prettier-ignore\n const include = current = new Set<string> ();\n const unusedInclude = Array.from(includePatterns).filter(filter);\n\n // prettier-ignore\n const exclude = current = new Set<string> ();\n const unusedExclude = Array.from(excludePatterns).filter(filter);\n\n const duplicates = intersection(include, exclude);\n\n if (\n duplicates.size > 0 ||\n unusedInclude.length > 0 ||\n unusedExclude.length > 0\n ) {\n throw new Error(\n `Error while validating the \"${provider}\" provider options:\\n` +\n buildUnusedError(\"include\", unusedInclude) +\n buildUnusedError(\"exclude\", unusedExclude) +\n buldDuplicatesError(duplicates),\n );\n }\n\n return { include, exclude };\n}\n\nexport function applyMissingDependenciesDefaults(\n options: PluginOptions,\n babelApi: any,\n): MissingDependenciesOption {\n const { missingDependencies = {} } = options;\n if (missingDependencies === false) return false;\n\n const caller = babelApi.caller(caller => caller?.name);\n\n const {\n log = \"deferred\",\n inject = caller === \"rollup-plugin-babel\" ? \"throw\" : \"import\",\n all = false,\n } = missingDependencies;\n\n return { log, inject, all };\n}\n","import type { NodePath } from \"@babel/traverse\";\nimport { types as t } from \"@babel/core\";\nimport type { CallProvider } from \"./index\";\n\nimport { resolveKey, resolveSource, PossibleGlobalObjects } from \"../utils\";\n\nfunction isRemoved(path: NodePath) {\n if (path.removed) return true;\n if (!path.parentPath) return false;\n if (path.listKey) {\n if (!path.parentPath.node?.[path.listKey]?.includes(path.node)) return true;\n } else {\n if (path.parentPath.node?.[path.key] !== path.node) return true;\n }\n return isRemoved(path.parentPath);\n}\n\nexport default (callProvider: CallProvider) => {\n function property(object, key, placement, path) {\n return callProvider({ kind: \"property\", object, key, placement }, path);\n }\n\n function handleReferencedIdentifier(path) {\n const {\n node: { name },\n scope,\n } = path;\n if (scope.getBindingIdentifier(name)) return;\n\n callProvider({ kind: \"global\", name }, path);\n }\n\n function analyzeMemberExpression(\n path: NodePath<t.MemberExpression | t.OptionalMemberExpression>,\n ) {\n const key = resolveKey(path.get(\"property\"), path.node.computed);\n return { key, handleAsMemberExpression: !!key && key !== \"prototype\" };\n }\n\n return {\n // Symbol(), new Promise\n ReferencedIdentifier(path: NodePath<t.Identifier>) {\n const { parentPath } = path;\n if (\n parentPath.isMemberExpression({ object: path.node }) &&\n analyzeMemberExpression(parentPath).handleAsMemberExpression\n ) {\n return;\n }\n handleReferencedIdentifier(path);\n },\n\n \"MemberExpression|OptionalMemberExpression\"(\n path: NodePath<t.MemberExpression | t.OptionalMemberExpression>,\n ) {\n const { key, handleAsMemberExpression } = analyzeMemberExpression(path);\n if (!handleAsMemberExpression) return;\n\n const object = path.get(\"object\");\n let objectIsGlobalIdentifier = object.isIdentifier();\n if (objectIsGlobalIdentifier) {\n const binding = object.scope.getBinding(\n (object.node as t.Identifier).name,\n );\n if (binding) {\n if (binding.path.isImportNamespaceSpecifier()) return;\n objectIsGlobalIdentifier = false;\n }\n }\n\n const source = resolveSource(object, new Set());\n const skipObject = property(source.id, key, source.placement, path);\n const canHandleObject =\n objectIsGlobalIdentifier &&\n !path.shouldSkip &&\n !object.shouldSkip &&\n !isRemoved(object);\n\n if (\n canHandleObject &&\n (!skipObject || PossibleGlobalObjects.has(source.id))\n ) {\n handleReferencedIdentifier(object);\n }\n },\n\n ObjectPattern(path: NodePath<t.ObjectPattern>) {\n const { parentPath, parent } = path;\n let obj;\n\n // const { keys, values } = Object\n if (parentPath.isVariableDeclarator()) {\n obj = parentPath.get(\"init\");\n // ({ keys, values } = Object)\n } else if (parentPath.isAssignmentExpression()) {\n obj = parentPath.get(\"right\");\n // !function ({ keys, values }) {...} (Object)\n // resolution does not work after properties transform :-(\n } else if (parentPath.isFunction()) {\n const grand = parentPath.parentPath;\n if (grand.isCallExpression() || grand.isNewExpression()) {\n if (grand.node.callee === parent) {\n obj = grand.get(\"arguments\")[path.key];\n }\n }\n }\n\n let id = null;\n let placement = null;\n if (obj) ({ id, placement } = resolveSource(obj, new Set()));\n\n for (const prop of path.get(\"properties\")) {\n if (prop.isObjectProperty()) {\n const key = resolveKey(prop.get(\"key\"));\n if (key) property(id, key, placement, prop);\n }\n }\n },\n\n BinaryExpression(path: NodePath<t.BinaryExpression>) {\n if (path.node.operator !== \"in\") return;\n\n const source = resolveSource(path.get(\"right\"), new Set());\n const key = resolveKey(path.get(\"left\"), true);\n\n if (!key) return;\n\n callProvider(\n {\n kind: \"in\",\n object: source.id,\n key,\n placement: source.placement,\n },\n path,\n );\n },\n };\n};\n","import type { NodePath } from \"@babel/traverse\";\nimport { types as t } from \"@babel/core\";\nimport type { CallProvider } from \"./index\";\n\nimport { getImportSource, getRequireSource } from \"../utils\";\n\nexport default (callProvider: CallProvider) => ({\n ImportDeclaration(path: NodePath<t.ImportDeclaration>) {\n const source = getImportSource(path);\n if (!source) return;\n callProvider({ kind: \"import\", source }, path);\n },\n Program(path: NodePath<t.Program>) {\n path.get(\"body\").forEach(bodyPath => {\n const source = getRequireSource(bodyPath);\n if (!source) return;\n callProvider({ kind: \"import\", source }, bodyPath);\n });\n },\n});\n","export function resolve(\n dirname: string,\n moduleName: string,\n absoluteImports: boolean | string,\n): string {\n if (absoluteImports === false) return moduleName;\n\n throw new Error(\n `\"absoluteImports\" is not supported in bundles prepared for the browser.`,\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function has(basedir: string, name: string) {\n return true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function logMissing(missingDeps: Set<string>) {}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function laterLogMissing(missingDeps: Set<string>) {}\n","import type {\n MetaDescriptor,\n ResolverPolyfills,\n ResolvedPolyfill,\n} from \"./types\";\n\nimport { has, PossibleGlobalObjects } from \"./utils\";\n\ntype ResolverFn<T> = (meta: MetaDescriptor) => void | ResolvedPolyfill<T>;\n\nexport default function createMetaResolver<T>(\n polyfills: ResolverPolyfills<T>,\n): ResolverFn<T> {\n const { static: staticP, instance: instanceP, global: globalP } = polyfills;\n\n return meta => {\n if (meta.kind === \"global\" && globalP && has(globalP, meta.name)) {\n return { kind: \"global\", desc: globalP[meta.name], name: meta.name };\n }\n\n if (meta.kind === \"property\" || meta.kind === \"in\") {\n const { placement, object, key } = meta;\n\n if (object && placement === \"static\") {\n if (globalP && PossibleGlobalObjects.has(object) && has(globalP, key)) {\n return { kind: \"global\", desc: globalP[key], name: key };\n }\n\n if (staticP && has(staticP, object) && has(staticP[object], key)) {\n return {\n kind: \"static\",\n desc: staticP[object][key],\n name: `${object}$${key}`,\n };\n }\n }\n\n if (instanceP && has(instanceP, key)) {\n return { kind: \"instance\", desc: instanceP[key], name: `${key}` };\n }\n }\n };\n}\n","import { declare } from \"@babel/helper-plugin-utils\";\nimport type { NodePath } from \"@babel/traverse\";\n\nimport _getTargets, {\n isRequired,\n getInclusionReasons,\n} from \"@babel/helper-compilation-targets\";\nconst getTargets = _getTargets.default || _getTargets;\n\nimport { createUtilsGetter } from \"./utils\";\nimport ImportsCachedInjector from \"./imports-injector\";\nimport {\n stringifyTargetsMultiline,\n presetEnvSilentDebugHeader,\n} from \"./debug-utils\";\nimport {\n validateIncludeExclude,\n applyMissingDependenciesDefaults,\n} from \"./normalize-options\";\n\nimport type {\n ProviderApi,\n MethodString,\n Targets,\n MetaDescriptor,\n PolyfillProvider,\n PluginOptions,\n ProviderOptions,\n} from \"./types\";\n\nimport * as v from \"./visitors\";\nimport * as deps from \"./node/dependencies\";\n\nimport createMetaResolver from \"./meta-resolver\";\n\nexport type { PolyfillProvider, MetaDescriptor, Utils, Targets } from \"./types\";\n\nfunction resolveOptions<Options>(\n options: PluginOptions,\n babelApi,\n): {\n method: MethodString;\n methodName: \"usageGlobal\" | \"entryGlobal\" | \"usagePure\";\n targets: Targets;\n debug: boolean | typeof presetEnvSilentDebugHeader;\n shouldInjectPolyfill:\n | ((name: string, shouldInject: boolean) => boolean)\n | undefined;\n providerOptions: ProviderOptions<Options>;\n absoluteImports: string | boolean;\n} {\n const {\n method,\n targets: targetsOption,\n ignoreBrowserslistConfig,\n configPath,\n debug,\n shouldInjectPolyfill,\n absoluteImports,\n ...providerOptions\n } = options;\n\n if (isEmpty(options)) {\n throw new Error(\n `\\\nThis plugin requires options, for example:\n {\n \"plugins\": [\n [\"<plugin name>\", { method: \"usage-pure\" }]\n ]\n }\n\nSee more options at https://github.com/babel/babel-polyfills/blob/main/docs/usage.md`,\n );\n }\n\n let methodName;\n if (method === \"usage-global\") methodName = \"usageGlobal\";\n else if (method === \"entry-global\") methodName = \"entryGlobal\";\n else if (method === \"usage-pure\") methodName = \"usagePure\";\n else if (typeof method !== \"string\") {\n throw new Error(\".method must be a string\");\n } else {\n throw new Error(\n `.method must be one of \"entry-global\", \"usage-global\"` +\n ` or \"usage-pure\" (received ${JSON.stringify(method)})`,\n );\n }\n\n if (typeof shouldInjectPolyfill === \"function\") {\n if (options.include || options.exclude) {\n throw new Error(\n `.include and .exclude are not supported when using the` +\n ` .shouldInjectPolyfill function.`,\n );\n }\n } else if (shouldInjectPolyfill != null) {\n throw new Error(\n `.shouldInjectPolyfill must be a function, or undefined` +\n ` (received ${JSON.stringify(shouldInjectPolyfill)})`,\n );\n }\n\n if (\n absoluteImports != null &&\n typeof absoluteImports !== \"boolean\" &&\n typeof absoluteImports !== \"string\"\n ) {\n throw new Error(\n `.absoluteImports must be a boolean, a string, or undefined` +\n ` (received ${JSON.stringify(absoluteImports)})`,\n );\n }\n\n let targets;\n\n if (\n // If any browserslist-related option is specified, fallback to the old\n // behavior of not using the targets specified in the top-level options.\n targetsOption ||\n configPath ||\n ignoreBrowserslistConfig\n ) {\n const targetsObj =\n typeof targetsOption === \"string\" || Array.isArray(targetsOption)\n ? { browsers: targetsOption }\n : targetsOption;\n\n targets = getTargets(targetsObj, {\n ignoreBrowserslistConfig,\n configPath,\n });\n } else {\n targets = babelApi.targets();\n }\n\n return {\n method,\n methodName,\n targets,\n absoluteImports: absoluteImports ?? false,\n shouldInjectPolyfill,\n debug: !!debug,\n providerOptions: providerOptions as any as ProviderOptions<Options>,\n };\n}\n\nfunction instantiateProvider<Options>(\n factory: PolyfillProvider<Options>,\n options: PluginOptions,\n missingDependencies,\n dirname,\n debugLog,\n babelApi,\n) {\n const {\n method,\n methodName,\n targets,\n debug,\n shouldInjectPolyfill,\n providerOptions,\n absoluteImports,\n } = resolveOptions<Options>(options, babelApi);\n\n // eslint-disable-next-line prefer-const\n let include, exclude;\n let polyfillsSupport;\n let polyfillsNames: Map<string, number> | undefined;\n let filterPolyfills;\n\n const getUtils = createUtilsGetter(\n new ImportsCachedInjector(\n moduleName => deps.resolve(dirname, moduleName, absoluteImports),\n (name: string) => polyfillsNames?.get(name) ?? Infinity,\n ),\n );\n\n const depsCache = new Map();\n\n const api: ProviderApi = {\n babel: babelApi,\n getUtils,\n method: options.method,\n targets,\n createMetaResolver,\n shouldInjectPolyfill(name) {\n if (polyfillsNames === undefined) {\n throw new Error(\n `Internal error in the ${factory.name} provider: ` +\n `shouldInjectPolyfill() can't be called during initialization.`,\n );\n }\n if (!polyfillsNames.has(name)) {\n console.warn(\n `Internal error in the ${providerName} provider: ` +\n `unknown polyfill \"${name}\".`,\n );\n }\n\n if (filterPolyfills && !filterPolyfills(name)) return false;\n\n let shouldInject = isRequired(name, targets, {\n compatData: polyfillsSupport,\n includes: include,\n excludes: exclude,\n });\n\n if (shouldInjectPolyfill) {\n shouldInject = shouldInjectPolyfill(name, shouldInject);\n if (typeof shouldInject !== \"boolean\") {\n throw new Error(`.shouldInjectPolyfill must return a boolean.`);\n }\n }\n\n return shouldInject;\n },\n debug(name) {\n debugLog().found = true;\n\n if (!debug || !name) return;\n\n if (debugLog().polyfills.has(providerName)) return;\n debugLog().polyfills.add(name);\n debugLog().polyfillsSupport ??= polyfillsSupport;\n },\n assertDependency(name, version = \"*\") {\n if (missingDependencies === false) return;\n if (absoluteImports) {\n // If absoluteImports is not false, we will try resolving\n // the dependency and throw if it's not possible. We can\n // skip the check here.\n return;\n }\n\n const dep = version === \"*\" ? name : `${name}@^${version}`;\n\n const found = missingDependencies.all\n ? false\n : mapGetOr(depsCache, `${name} :: ${dirname}`, () =>\n deps.has(dirname, name),\n );\n\n if (!found) {\n debugLog().missingDeps.add(dep);\n }\n },\n };\n\n const provider = factory(api, providerOptions, dirname);\n const providerName = provider.name || factory.name;\n\n if (typeof provider[methodName] !== \"function\") {\n throw new Error(\n `The \"${providerName}\" provider doesn't support the \"${method}\" polyfilling method.`,\n );\n }\n\n if (Array.isArray(provider.polyfills)) {\n polyfillsNames = new Map(\n provider.polyfills.map((name, index) => [name, index]),\n );\n filterPolyfills = provider.filterPolyfills;\n } else if (provider.polyfills) {\n polyfillsNames = new Map(\n Object.keys(provider.polyfills).map((name, index) => [name, index]),\n );\n polyfillsSupport = provider.polyfills;\n filterPolyfills = provider.filterPolyfills;\n } else {\n polyfillsNames = new Map();\n }\n\n ({ include, exclude } = validateIncludeExclude(\n providerName,\n polyfillsNames,\n providerOptions.include || [],\n providerOptions.exclude || [],\n ));\n\n let callProvider: (payload: MetaDescriptor, path: NodePath) => boolean;\n if (methodName === \"usageGlobal\") {\n callProvider = (payload, path) => {\n const utils = getUtils(path);\n return (\n (provider[methodName](payload, utils, path) satisfies boolean) ?? false\n );\n };\n } else {\n callProvider = (payload, path) => {\n const utils = getUtils(path);\n provider[methodName](payload, utils, path) satisfies void;\n return false;\n };\n }\n\n return {\n debug,\n method,\n targets,\n provider,\n providerName,\n callProvider,\n };\n}\n\nexport default function definePolyfillProvider<Options>(\n factory: PolyfillProvider<Options>,\n) {\n return declare((babelApi, options: PluginOptions, dirname: string) => {\n babelApi.assertVersion(\"^7.0.0 || ^8.0.0-alpha.0\");\n const { traverse } = babelApi;\n\n let debugLog;\n\n const missingDependencies = applyMissingDependenciesDefaults(\n options,\n babelApi,\n );\n\n const { debug, method, targets, provider, providerName, callProvider } =\n instantiateProvider<Options>(\n factory,\n options,\n missingDependencies,\n dirname,\n () => debugLog,\n babelApi,\n );\n\n const createVisitor = method === \"entry-global\" ? v.entry : v.usage;\n\n const visitor = provider.visitor\n ? traverse.visitors.merge([createVisitor(callProvider), provider.visitor])\n : createVisitor(callProvider);\n\n if (debug && debug !== presetEnvSilentDebugHeader) {\n console.log(`${providerName}: \\`DEBUG\\` option`);\n console.log(`\\nUsing targets: ${stringifyTargetsMultiline(targets)}`);\n console.log(`\\nUsing polyfills with \\`${method}\\` method:`);\n }\n\n const { runtimeName } = provider;\n\n return {\n name: \"inject-polyfills\",\n visitor,\n\n pre(file) {\n if (runtimeName) {\n if (\n file.get(\"runtimeHelpersModuleName\") &&\n file.get(\"runtimeHelpersModuleName\") !== runtimeName\n ) {\n console.warn(\n `Two different polyfill providers` +\n ` (${file.get(\"runtimeHelpersModuleProvider\")}` +\n ` and ${providerName}) are trying to define two` +\n ` conflicting @babel/runtime alternatives:` +\n ` ${file.get(\"runtimeHelpersModuleName\")} and ${runtimeName}.` +\n ` The second one will be ignored.`,\n );\n } else {\n file.set(\"runtimeHelpersModuleName\", runtimeName);\n file.set(\"runtimeHelpersModuleProvider\", providerName);\n }\n }\n\n debugLog = {\n polyfills: new Set(),\n polyfillsSupport: undefined,\n found: false,\n providers: new Set(),\n missingDeps: new Set(),\n };\n\n provider.pre?.apply(this, arguments);\n },\n post() {\n provider.post?.apply(this, arguments);\n\n if (missingDependencies !== false) {\n if (missingDependencies.log === \"per-file\") {\n deps.logMissing(debugLog.missingDeps);\n } else {\n deps.laterLogMissing(debugLog.missingDeps);\n }\n }\n\n if (!debug) return;\n\n if (this.filename) console.log(`\\n[${this.filename}]`);\n\n if (debugLog.polyfills.size === 0) {\n console.log(\n method === \"entry-global\"\n ? debugLog.found\n ? `Based on your targets, the ${providerName} polyfill did not add any polyfill.`\n : `The entry point for the ${providerName} polyfill has not been found.`\n : `Based on your code and targets, the ${providerName} polyfill did not add any polyfill.`,\n );\n\n return;\n }\n\n if (method === \"entry-global\") {\n console.log(\n `The ${providerName} polyfill entry has been replaced with ` +\n `the following polyfills:`,\n );\n } else {\n console.log(\n `The ${providerName} polyfill added the following polyfills:`,\n );\n }\n\n for (const name of debugLog.polyfills) {\n if (debugLog.polyfillsSupport?.[name]) {\n const filteredTargets = getInclusionReasons(\n name,\n targets,\n debugLog.polyfillsSupport,\n );\n\n const formattedTargets = JSON.stringify(filteredTargets)\n .replace(/,/g, \", \")\n .replace(/^\\{\"/, '{ \"')\n .replace(/\"\\}$/, '\" }');\n\n console.log(` ${name} ${formattedTargets}`);\n } else {\n console.log(` ${name}`);\n }\n }\n },\n };\n });\n}\n\nfunction mapGetOr(map, key, getDefault) {\n let val = map.get(key);\n if (val === undefined) {\n val = getDefault();\n map.set(key, val);\n }\n return val;\n}\n\nfunction isEmpty(obj) {\n return Object.keys(obj).length === 0;\n}\n"],"names":["types","t","template","_babel","default","PossibleGlobalObjects","Set","intersection","a","b","result","forEach","v","has","add","object","key","Object","prototype","hasOwnProperty","call","resolve","path","seen","isVariableDeclarator","get","isIdentifier","isReferencedIdentifier","binding","scope","getBinding","node","name","constant","resolveId","hasBinding","isMemberExpression","computed","property","resolved","resolveKey","isStringLiteral","value","parent","sym","isPure","evaluate","resolveInstance","obj","source","resolveSource","placement","id","type","calleeId","operator","arg","left","right","expressions","length","consequent","alternate","getImportSource","specifiers","getRequireSource","isExpressionStatement","expression","isCallExpression","callee","arguments","hoist","_blockHoist","createUtilsGetter","cache","prog","findParent","p","isProgram","injectGlobalImport","url","moduleName","storeAnonymous","isScript","statement","ast","importDeclaration","injectNamedImport","hint","storeNamed","generateUidIdentifier","importSpecifier","injectDefaultImport","importDefaultSpecifier","ImportsCachedInjector","constructor","resolver","getPreferredIndex","_imports","WeakMap","_anonymousImports","_lastImports","_resolver","_getPreferredIndex","programPath","getVal","_normalizeKey","imports","_ensure","sourceType","stringLiteral","_injectImport","Map","identifier","set","_this$_lastImports$ge","newIndex","lastImports","isPathStillValid","container","body","last","Infinity","undefined","i","data","entries","index","newPath","insertBefore","splice","insertAfter","push","unshiftContainer","map","Collection","collection","presetEnvSilentDebugHeader","stringifyTargetsMultiline","targets","JSON","stringify","prettifyTargets","patternToRegExp","pattern","RegExp","buildUnusedError","label","unused","original","String","join","buldDuplicatesError","duplicates","size","Array","from","validateIncludeExclude","provider","polyfills","includePatterns","excludePatterns","current","filter","regexp","matched","polyfill","keys","test","include","unusedInclude","exclude","unusedExclude","Error","applyMissingDependenciesDefaults","options","babelApi","missingDependencies","caller","log","inject","all","isRemoved","removed","parentPath","listKey","_path$parentPath$node","includes","_path$parentPath$node2","callProvider","kind","handleReferencedIdentifier","getBindingIdentifier","analyzeMemberExpression","handleAsMemberExpression","ReferencedIdentifier","MemberExpression|OptionalMemberExpression","objectIsGlobalIdentifier","isImportNamespaceSpecifier","skipObject","canHandleObject","shouldSkip","ObjectPattern","isAssignmentExpression","isFunction","grand","isNewExpression","prop","isObjectProperty","BinaryExpression","ImportDeclaration","Program","bodyPath","dirname","absoluteImports","basedir","logMissing","missingDeps","laterLogMissing","createMetaResolver","static","staticP","instance","instanceP","global","globalP","meta","desc","getTargets","_getTargets","resolveOptions","method","targetsOption","ignoreBrowserslistConfig","configPath","debug","shouldInjectPolyfill","providerOptions","isEmpty","methodName","targetsObj","isArray","browsers","instantiateProvider","factory","debugLog","polyfillsSupport","polyfillsNames","filterPolyfills","getUtils","deps","_polyfillsNames$get","_polyfillsNames","depsCache","api","babel","console","warn","providerName","shouldInject","isRequired","compatData","excludes","_debugLog","_debugLog$polyfillsSu","found","assertDependency","version","dep","mapGetOr","payload","_ref","utils","definePolyfillProvider","declare","assertVersion","traverse","createVisitor","visitor","visitors","merge","runtimeName","pre","file","_provider$pre","providers","apply","post","_provider$post","filename","_debugLog$polyfillsSu2","filteredTargets","getInclusionReasons","formattedTargets","replace","getDefault","val"],"mappings":";;;;;AAASA,EAAAA,KAAK,EAAIC,GAAC;AAAEC,EAAAA,QAAQ,EAARA,QAAAA;AAAQ,CAAA,GAAAC,MAAA,CAAAC,OAAA,IAAAD,MAAA,CAAA;AAKtB,MAAME,qBAAqB,GAAG,IAAIC,GAAG,CAAS,CACnD,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,QAAQ,CACT,CAAC,CAAA;AAEK,SAASC,YAAYA,CAAIC,CAAS,EAAEC,CAAS,EAAU;AAC5D,EAAA,MAAMC,MAAM,GAAG,IAAIJ,GAAG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