-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathhelpers.ts
More file actions
40 lines (31 loc) · 774 Bytes
/
helpers.ts
File metadata and controls
40 lines (31 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import tBabelTypes, { type CallExpression } from "@babel/types";
export type BabelTypes = typeof tBabelTypes;
export interface PluginOpts {
target?: string;
runtime?: string;
commonjs?: boolean;
}
export interface PluginState {
opts?: PluginOpts;
filename: string;
}
export function getInteropRequireDefaultSource(
init: CallExpression,
t: BabelTypes,
) {
if (!t.isIdentifier(init.callee, { name: "_interopRequireDefault" })) {
return;
}
const interopArg = init.arguments.at(0);
if (
!t.isCallExpression(interopArg) ||
!t.isIdentifier(interopArg.callee, { name: "require" })
) {
return;
}
const requireArg = interopArg.arguments.at(0);
if (!t.isStringLiteral(requireArg)) {
return;
}
return requireArg.value;
}