Skip to content

Commit 73623f1

Browse files
authored
Refine typing for parserOverride in babel plugins (#17322)
1 parent 80c9a3a commit 73623f1

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

packages/babel-core/src/config/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default class Plugin {
99
pre?: PluginObject["pre"];
1010
visitor: PluginObject["visitor"];
1111

12-
parserOverride?: Function;
12+
parserOverride?: PluginObject["parserOverride"];
1313
generatorOverride?: Function;
1414

1515
options: object;

packages/babel-core/src/config/validation/plugins.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
OptionPath,
1212
RootPath,
1313
} from "./option-assertions.ts";
14-
import type { ParserOptions } from "@babel/parser";
14+
import type { parse, ParserOptions } from "@babel/parser";
1515
import type { Visitor } from "@babel/traverse";
1616
import type { ValidatedOptions } from "./options.ts";
1717
import type { File, PluginAPI, PluginPass } from "../../index.ts";
@@ -93,7 +93,9 @@ export type PluginObject<S extends PluginPass = PluginPass> = {
9393
dirname: string,
9494
) => PluginObject;
9595
visitor?: Visitor<S>;
96-
parserOverride?: Function;
96+
parserOverride?: (
97+
...args: [...Parameters<typeof parse>, typeof parse]
98+
) => ReturnType<typeof parse>;
9799
generatorOverride?: Function;
98100
};
99101

packages/babel-core/src/parser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function* parser(
2929
} else if (results.length === 1) {
3030
// If we want to allow async parsers
3131
yield* [];
32-
if (typeof results[0].then === "function") {
32+
if (typeof (results[0] as any).then === "function") {
3333
throw new Error(
3434
`You appear to be using an async parser plugin, ` +
3535
`which your current version of Babel does not support. ` +

0 commit comments

Comments
 (0)