Convert @babel/core to TypeScript (#12929)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
committed by
Nicolò Ribaudo
parent
c8a91d9eef
commit
a647b9ea6b
@@ -1,39 +1,39 @@
|
||||
// @flow
|
||||
|
||||
import gensync from "gensync";
|
||||
|
||||
import loadConfig, { type InputOptions } from "./config";
|
||||
import loadConfig from "./config";
|
||||
import type { InputOptions } from "./config";
|
||||
import parser from "./parser";
|
||||
import type { ParseResult } from "./parser";
|
||||
import normalizeOptions from "./transformation/normalize-opts";
|
||||
|
||||
type FileParseCallback = {
|
||||
(Error, null): any,
|
||||
(null, ParseResult | null): any,
|
||||
(err: Error, ast: null): any;
|
||||
(err: null, ast: ParseResult | null): any;
|
||||
};
|
||||
|
||||
type Parse = {
|
||||
(code: string, callback: FileParseCallback): void,
|
||||
(code: string, opts: ?InputOptions, callback: FileParseCallback): void,
|
||||
|
||||
// Here for backward-compatibility. Ideally use ".parseSync" if you want
|
||||
// a synchronous API.
|
||||
(code: string, opts: ?InputOptions): ParseResult | null,
|
||||
(code: string, callback: FileParseCallback): void;
|
||||
(
|
||||
code: string,
|
||||
opts: InputOptions | undefined | null,
|
||||
callback: FileParseCallback,
|
||||
): void;
|
||||
(code: string, opts?: InputOptions | null): ParseResult | null;
|
||||
};
|
||||
|
||||
const parseRunner = gensync<[string, ?InputOptions], ParseResult | null>(
|
||||
function* parse(code, opts) {
|
||||
const config = yield* loadConfig(opts);
|
||||
const parseRunner = gensync<
|
||||
(code: string, opts: InputOptions | undefined | null) => ParseResult | null
|
||||
>(function* parse(code, opts) {
|
||||
const config = yield* loadConfig(opts);
|
||||
|
||||
if (config === null) {
|
||||
return null;
|
||||
}
|
||||
if (config === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return yield* parser(config.passes, normalizeOptions(config), code);
|
||||
},
|
||||
);
|
||||
return yield* parser(config.passes, normalizeOptions(config), code);
|
||||
});
|
||||
|
||||
export const parse: Parse = (function parse(code, opts, callback) {
|
||||
export const parse: Parse = function parse(code, opts?, callback?) {
|
||||
if (typeof opts === "function") {
|
||||
callback = opts;
|
||||
opts = undefined;
|
||||
@@ -44,7 +44,7 @@ export const parse: Parse = (function parse(code, opts, callback) {
|
||||
if (callback === undefined) return parseRunner.sync(code, opts);
|
||||
|
||||
parseRunner.errback(code, opts, callback);
|
||||
}: Function);
|
||||
};
|
||||
|
||||
export const parseSync = parseRunner.sync;
|
||||
export const parseAsync = parseRunner.async;
|
||||
|
||||
Reference in New Issue
Block a user