Rename @babel/core files to .ts (#12929)

This commit is contained in:
Bogdan Savluk
2021-03-27 02:03:14 +01:00
committed by Nicolò Ribaudo
parent 8efbac4a5d
commit c8a91d9eef
50 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
// @flow
import gensync from "gensync";
import loadConfig, { 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,
};
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,
};
const parseRunner = gensync<[string, ?InputOptions], ParseResult | null>(
function* parse(code, opts) {
const config = yield* loadConfig(opts);
if (config === null) {
return null;
}
return yield* parser(config.passes, normalizeOptions(config), code);
},
);
export const parse: Parse = (function parse(code, opts, callback) {
if (typeof opts === "function") {
callback = opts;
opts = undefined;
}
// For backward-compat with Babel 7's early betas, we allow sync parsing when
// no callback is given. Will be dropped in some future Babel major version.
if (callback === undefined) return parseRunner.sync(code, opts);
parseRunner.errback(code, opts, callback);
}: Function);
export const parseSync = parseRunner.sync;
export const parseAsync = parseRunner.async;