Files
test-repo/parser.js
T
Jon Wong e33d6773d6 Adding support for graphql (#1982)
* Initial GraphQL implementation

This is the bare minimum amount of code to make graphql work. Turns out it's pretty easy to add support for other languages :)

* Fixing support for `graphql` parsing

There was a few structural changes with the addition of CSS and Typescript that we had to take into account.

* Fixing file glob, adding `graphql` to yarn.lock

* Removing extraneous file

* Adding `graphql` parser, style changes

* Splitting out graphql printer

* Removing merge conflict

* Fixing yarn.lock

* Addressing code review, using `createError`

* Adding release config

* Using exact version

* Removing destructuring
2017-06-05 12:34:08 -07:00

37 lines
937 B
JavaScript

"use strict";
function parse(text, opts) {
let parseFunction;
if (opts.parser === "flow") {
parseFunction = eval("require")("./src/parser-flow");
} else if (opts.parser === "graphql") {
parseFunction = eval("require")("./src/parser-graphql");
} else if (opts.parser === "typescript") {
parseFunction = eval("require")("./src/parser-typescript");
} else if (opts.parser === "postcss") {
parseFunction = eval("require")("./src/parser-postcss");
} else {
parseFunction = eval("require")("./src/parser-babylon");
}
try {
return parseFunction(text);
} catch (error) {
const loc = error.loc;
if (loc) {
const codeFrame = require("babel-code-frame");
error.codeFrame = codeFrame.codeFrameColumns(text, loc, {
highlightCode: true
});
error.message += "\n" + error.codeFrame;
throw error;
}
throw error.stack;
}
}
module.exports = { parse };