Use prettier (#600)
This commit is contained in:
30
src/index.js
30
src/index.js
@@ -37,46 +37,54 @@ export function parseExpression(input: string, options?: Options): Expression {
|
||||
return parser.getExpression();
|
||||
}
|
||||
|
||||
|
||||
export { tokTypes };
|
||||
|
||||
function getParser(options: ?Options, input: string): Parser {
|
||||
const cls = options && options.plugins ? getParserClass(options.plugins) : Parser;
|
||||
const cls =
|
||||
options && options.plugins ? getParserClass(options.plugins) : Parser;
|
||||
return new cls(options, input);
|
||||
}
|
||||
|
||||
const parserClassCache: { [key: string]: Class<Parser> } = {};
|
||||
|
||||
/** Get a Parser class with plugins applied. */
|
||||
function getParserClass(pluginsFromOptions: $ReadOnlyArray<string>): Class<Parser> {
|
||||
|
||||
if (pluginsFromOptions.indexOf("decorators") >= 0 && pluginsFromOptions.indexOf("decorators2") >= 0) {
|
||||
function getParserClass(
|
||||
pluginsFromOptions: $ReadOnlyArray<string>,
|
||||
): Class<Parser> {
|
||||
if (
|
||||
pluginsFromOptions.indexOf("decorators") >= 0 &&
|
||||
pluginsFromOptions.indexOf("decorators2") >= 0
|
||||
) {
|
||||
throw new Error("Cannot use decorators and decorators2 plugin together");
|
||||
}
|
||||
|
||||
// Filter out just the plugins that have an actual mixin associated with them.
|
||||
let pluginList = pluginsFromOptions.filter((p) =>
|
||||
p === "estree" || p === "flow" || p === "jsx" || p === "typescript");
|
||||
let pluginList = pluginsFromOptions.filter(
|
||||
p => p === "estree" || p === "flow" || p === "jsx" || p === "typescript",
|
||||
);
|
||||
|
||||
if (pluginList.indexOf("flow") >= 0) {
|
||||
// ensure flow plugin loads last
|
||||
pluginList = pluginList.filter((plugin) => plugin !== "flow");
|
||||
pluginList = pluginList.filter(plugin => plugin !== "flow");
|
||||
pluginList.push("flow");
|
||||
}
|
||||
|
||||
if (pluginList.indexOf("flow") >= 0 && pluginList.indexOf("typescript") >= 0) {
|
||||
if (
|
||||
pluginList.indexOf("flow") >= 0 &&
|
||||
pluginList.indexOf("typescript") >= 0
|
||||
) {
|
||||
throw new Error("Cannot combine flow and typescript plugins.");
|
||||
}
|
||||
|
||||
if (pluginList.indexOf("typescript") >= 0) {
|
||||
// ensure typescript plugin loads last
|
||||
pluginList = pluginList.filter((plugin) => plugin !== "typescript");
|
||||
pluginList = pluginList.filter(plugin => plugin !== "typescript");
|
||||
pluginList.push("typescript");
|
||||
}
|
||||
|
||||
if (pluginList.indexOf("estree") >= 0) {
|
||||
// ensure estree plugin loads first
|
||||
pluginList = pluginList.filter((plugin) => plugin !== "estree");
|
||||
pluginList = pluginList.filter(plugin => plugin !== "estree");
|
||||
pluginList.unshift("estree");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user