import { ParserOptions, ParserPlugin } from "@babel/parser";
import { getOption } from "../lib/util";
export type Overrides = Partial<{
sourceType: ParserOptions["sourceType"];
strictMode: ParserOptions["strictMode"];
}>;
export default function getBabelOptions(
options?: Overrides,
): ParserOptions & { plugins: ParserPlugin[] } {
return {
sourceType: getOption(options, "sourceType", "module"),
strictMode: getOption(options, "strictMode", false),
allowImportExportEverywhere: true,
allowReturnOutsideFunction: true,
startLine: 1,
tokens: true,
plugins: [
"asyncGenerators",
"bigInt",
"classPrivateMethods",
"classPrivateProperties",
"classProperties",
"classStaticBlock",
"decimal",
"decorators-legacy",
"doExpressions",
"dynamicImport",
"exportDefaultFrom",
"exportExtensions" as any as ParserPlugin,
"exportNamespaceFrom",
"functionBind",
"functionSent",
"importAssertions",
"importMeta",
"nullishCoalescingOperator",
"numericSeparator",
"objectRestSpread",
"optionalCatchBinding",
"optionalChaining",
[
"pipelineOperator",
{
proposal: "minimal",
},
] as any as ParserPlugin,
[
"recordAndTuple",
{
syntaxType: "hash",
},
],
"throwExpressions",
"topLevelAwait",
"v8intrinsic",
],
};
}