Debian Codegraph @

packages/babel-helper-module-imports/src/index.ts

raw symbols SCIP
1 import ImportInjector, { type ImportOptions } from "./import-injector";
2 import type { NodePath } from "@babel/traverse";
3 import type * as t from "@babel/types";
4
5 export { ImportInjector };
6
7 export { default as isModule } from "./is-module";
8
9 export function addDefault(
10 path: NodePath,
11 importedSource: string,
12 opts?: Partial<ImportOptions>,
13 ) {
14 return new ImportInjector(path).addDefault(importedSource, opts);
15 }
16
17 function addNamed(
18 path: NodePath,
19 name: string,
20 importedSource: string,
21 opts?: Omit<
22 Partial<ImportOptions>,
23 "ensureLiveReference" | "ensureNoContext"
24 >,
25 ): t.Identifier;
26 function addNamed(
27 path: NodePath,
28 name: string,
29 importedSource: string,
30 opts?: Omit<Partial<ImportOptions>, "ensureLiveReference"> & {
31 ensureLiveReference: true;
32 },
33 ): t.MemberExpression;
34 function addNamed(
35 path: NodePath,
36 name: string,
37 importedSource: string,
38 opts?: Omit<Partial<ImportOptions>, "ensureNoContext"> & {
39 ensureNoContext: true;
40 },
41 ): t.SequenceExpression;
42 /**
43 * add a named import to the program path of given path
44 *
45 * @export
46 * @param {NodePath} path The starting path to find a program path
47 * @param {string} name The name of the generated binding. Babel will prefix it with `_`
48 * @param {string} importedSource The source of the import
49 * @param {Partial<ImportOptions>} [opts]
50 * @returns {t.Identifier | t.MemberExpression | t.SequenceExpression} If opts.ensureNoContext is true, returns a SequenceExpression,
51 * else if opts.ensureLiveReference is true, returns a MemberExpression, else returns an Identifier
52 */
53 function addNamed(
54 path: NodePath,
55 name: string,
56 importedSource: string,
57 opts?: Partial<ImportOptions>,
58 ) {
59 return new ImportInjector(path).addNamed(name, importedSource, opts);
60 }
61 export { addNamed };
62
63 export function addNamespace(
64 path: NodePath,
65 importedSource: string,
66 opts?: Partial<ImportOptions>,
67 ) {
68 return new ImportInjector(path).addNamespace(importedSource, opts);
69 }
70
71 export function addSideEffect(
72 path: NodePath,
73 importedSource: string,
74 opts?: Partial<ImportOptions>,
75 ) {
76 return new ImportInjector(path).addSideEffect(importedSource, opts);
77 }