Convert @babel/core to TypeScript (#12929)

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
Bogdan Savluk
2021-03-27 02:03:15 +01:00
committed by Nicolò Ribaudo
parent c8a91d9eef
commit a647b9ea6b
53 changed files with 1265 additions and 1200 deletions

View File

@@ -1,15 +1,17 @@
import type { Handler } from "gensync";
import { parse } from "@babel/parser";
import type * as t from "@babel/types";
import { codeFrameColumns } from "@babel/code-frame";
import generateMissingPluginMessage from "./util/missing-plugin-helper";
import type { PluginPasses } from "../config";
type AstRoot = BabelNodeFile | BabelNodeProgram;
type AstRoot = t.File | t.Program;
export type ParseResult = AstRoot;
export default function* parser(
pluginPasses: PluginPasses,
{ parserOpts, highlightCode = true, filename = "unknown" }: Object,
{ parserOpts, highlightCode = true, filename = "unknown" }: any,
code: string,
): Handler<ParseResult> {
try {
@@ -28,7 +30,8 @@ export default function* parser(
if (results.length === 0) {
return parse(code, parserOpts);
} else if (results.length === 1) {
yield* []; // If we want to allow async parsers
// @ts-expect-error - If we want to allow async parsers
yield* [];
if (typeof results[0].then === "function") {
throw new Error(
`You appear to be using an async parser plugin, ` +

View File

@@ -1,5 +1,3 @@
// @flow
const pluginNameMap = {
classProperties: {
syntax: {
@@ -290,7 +288,10 @@ to enable [parsing|transformation].
*/
export default function generateMissingPluginMessage(
missingPluginName: string,
loc: { line: number, column: number },
loc: {
line: number;
column: number;
},
codeFrame: string,
): string {
let helpMessage =