/
index.ts
100 lines (88 loc) 路 2.61 KB
/
index.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
declare const PACKAGE_JSON: { name: string; version: string };
declare const USE_ESM: boolean, IS_STANDALONE: boolean;
export const version = PACKAGE_JSON.version;
export { default as File } from "./transformation/file/file";
export type { default as PluginPass } from "./transformation/plugin-pass";
export { default as buildExternalHelpers } from "./tools/build-external-helpers";
export { resolvePlugin, resolvePreset } from "./config/files";
export { getEnv } from "./config/helpers/environment";
// NOTE: Lazy re-exports aren't detected by the Node.js CJS-ESM interop.
// These are handled by pluginInjectNodeReexportsHints in our babel.config.js
// so that they can work well.
export * as types from "@babel/types";
export { tokTypes } from "@babel/parser";
export { default as traverse } from "@babel/traverse";
export { default as template } from "@babel/template";
export {
createConfigItem,
createConfigItemSync,
createConfigItemAsync,
} from "./config";
export {
loadPartialConfig,
loadPartialConfigSync,
loadPartialConfigAsync,
loadOptions,
loadOptionsSync,
loadOptionsAsync,
} from "./config";
export type {
CallerMetadata,
InputOptions,
PluginAPI,
PluginObject,
PresetAPI,
PresetObject,
} from "./config";
export {
transform,
transformSync,
transformAsync,
type FileResult,
} from "./transform";
export {
transformFile,
transformFileSync,
transformFileAsync,
} from "./transform-file";
export {
transformFromAst,
transformFromAstSync,
transformFromAstAsync,
} from "./transform-ast";
export { parse, parseSync, parseAsync } from "./parse";
/**
* Recommended set of compilable extensions. Not used in @babel/core directly, but meant as
* as an easy source for tooling making use of @babel/core.
*/
export const DEFAULT_EXTENSIONS = Object.freeze([
".js",
".jsx",
".es6",
".es",
".mjs",
".cjs",
] as const);
// For easier backward-compatibility, provide an API like the one we exposed in Babel 6.
// TODO(Babel 8): Remove this.
import { loadOptionsSync } from "./config";
export class OptionManager {
init(opts: {}) {
return loadOptionsSync(opts);
}
}
// TODO(Babel 8): Remove this.
export function Plugin(alias: string) {
throw new Error(
`The (${alias}) Babel 5 plugin is being run with an unsupported Babel version.`,
);
}
import Module from "module";
import * as thisFile from "./index";
if (USE_ESM) {
if (!IS_STANDALONE) {
// Pass this module to the CJS proxy, so that it can be synchronously accessed.
const cjsProxy = Module.createRequire(import.meta.url)("../cjs-proxy.cjs");
cjsProxy["__ initialize @babel/core cjs proxy __"] = thisFile;
}
}