Debian Codegraph @

packages/babel-core/src/transformation/plugin-pass.ts

raw
1 import type File from "./file/file";
2 import type { NodeLocation } from "./file/file";
3
4 export default class PluginPass {
5 _map: Map<unknown, unknown> = new Map();
6 key: string | undefined | null;
7 file: File;
8 opts: any;
9
10 // The working directory that Babel's programmatic options are loaded
11 // relative to.
12 cwd: string;
13
14 // The absolute path of the file being compiled.
15 filename: string | void;
16
17 constructor(file: File, key?: string | null, options?: any | null) {
18 this.key = key;
19 this.file = file;
20 this.opts = options || {};
21 this.cwd = file.opts.cwd;
22 this.filename = file.opts.filename;
23 }
24
25 set(key: unknown, val: unknown) {
26 this._map.set(key, val);
27 }
28
29 get(key: unknown): any {
30 return this._map.get(key);
31 }
32
33 availableHelper(name: string, versionRange?: string | null) {
34 return this.file.availableHelper(name, versionRange);
35 }
36
37 addHelper(name: string) {
38 return this.file.addHelper(name);
39 }
40
41 addImport() {
42 return this.file.addImport();
43 }
44
45 buildCodeFrameError(
46 node: NodeLocation | undefined | null,
47 msg: string,
48 _Error?: typeof Error,
49 ) {
50 return this.file.buildCodeFrameError(node, msg, _Error);
51 }
52 }
53
54 if (!process.env.BABEL_8_BREAKING) {
55 (PluginPass as any).prototype.getModuleName = function getModuleName():
56 | string
57 | undefined {
58 return this.file.getModuleName();
59 };
60 }