Rename "babylon" to "@babel/parser" (#7937) 🎉

This commit is contained in:
Chaitanya Kumar Kamatham
2018-05-18 21:03:05 -07:00
committed by Henry Zhu
parent 0200a3e510
commit daf0ca8680
7587 changed files with 146 additions and 129 deletions

View File

@@ -0,0 +1,50 @@
// @flow
import type { Options } from "../options";
import type { File } from "../types";
import { getOptions } from "../options";
import StatementParser from "./statement";
export const plugins: {
[name: string]: (superClass: Class<Parser>) => Class<Parser>,
} = {};
export default class Parser extends StatementParser {
constructor(options: ?Options, input: string) {
options = getOptions(options);
super(options, input);
this.options = options;
this.inModule = this.options.sourceType === "module";
this.input = input;
this.plugins = pluginsMap(this.options.plugins);
this.filename = options.sourceFilename;
// If enabled, skip leading hashbang line.
if (
this.state.pos === 0 &&
this.input[0] === "#" &&
this.input[1] === "!"
) {
this.skipLineComment(2);
}
}
parse(): File {
const file = this.startNode();
const program = this.startNode();
this.nextToken();
return this.parseTopLevel(file, program);
}
}
function pluginsMap(
pluginList: $ReadOnlyArray<string>,
): { [key: string]: boolean } {
const pluginMap = Object.create(null);
for (const plugin of pluginList) {
const [name, options = {}] = Array.isArray(plugin) ? plugin : [plugin];
pluginMap[name] = options;
}
return pluginMap;
}