Debian Codegraph @

packages/babel-preset-env/src/polyfills/utils.ts

raw symbols SCIP
1 import {
2 isCallExpression,
3 isExpressionStatement,
4 isIdentifier,
5 isStringLiteral,
6 } from "@babel/types";
7 import type * as t from "@babel/types";
8 import type { NodePath } from "@babel/traverse";
9
10 export function getImportSource({ node }: NodePath<t.ImportDeclaration>) {
11 if (node.specifiers.length === 0) return node.source.value;
12 }
13
14 export function getRequireSource({ node }: NodePath) {
15 if (!isExpressionStatement(node)) return;
16 const { expression } = node;
17 if (
18 isCallExpression(expression) &&
19 isIdentifier(expression.callee) &&
20 expression.callee.name === "require" &&
21 expression.arguments.length === 1 &&
22 isStringLiteral(expression.arguments[0])
23 ) {
24 return expression.arguments[0].value;
25 }
26 }
27
28 export function isPolyfillSource(source?: string | null): boolean {
29 return source === "@babel/polyfill" || source === "core-js";
30 }