-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
plugin-pass.ts
61 lines (50 loc) 路 1.38 KB
/
plugin-pass.ts
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import type File from "./file/file";
import type { NodeLocation } from "./file/file";
export default class PluginPass {
_map: Map<unknown, unknown> = new Map();
key: string | undefined | null;
file: File;
opts: any;
// The working directory that Babel's programmatic options are loaded
// relative to.
cwd: string;
// The absolute path of the file being compiled.
filename: string | void;
constructor(file: File, key?: string | null, options?: any | null) {
this.key = key;
this.file = file;
this.opts = options || {};
this.cwd = file.opts.cwd;
this.filename = file.opts.filename;
}
set(key: unknown, val: unknown) {
this._map.set(key, val);
}
get(key: unknown): any {
return this._map.get(key);
}
availableHelper(name: string, versionRange?: string | null) {
return this.file.availableHelper(name, versionRange);
}
addHelper(name: string) {
return this.file.addHelper(name);
}
// TODO: Remove this in Babel 8
addImport() {
this.file.addImport();
}
buildCodeFrameError(
node: NodeLocation | undefined | null,
msg: string,
_Error?: typeof Error,
) {
return this.file.buildCodeFrameError(node, msg, _Error);
}
}
if (!process.env.BABEL_8_BREAKING) {
(PluginPass as any).prototype.getModuleName = function getModuleName():
| string
| undefined {
return this.file.getModuleName();
};
}