graphql-language-service-server
Version:
Server process backing the GraphQL Language Service
31 lines • 1.01 kB
JavaScript
import { parse } from '@babel/parser';
import { BABEL_PLUGINS, PARSER_OPTIONS } from '../constants';
export const babelParser = (text, plugins) => {
const babelPlugins = [...BABEL_PLUGINS];
if (plugins) {
babelPlugins.push(...plugins);
}
PARSER_OPTIONS.plugins = babelPlugins;
return parse(text, PARSER_OPTIONS);
};
export const ecmaParser = (text, uri, logger) => {
try {
return { asts: [babelParser(text, ['flow', 'flowComments'])] };
}
catch (error) {
logger.info(`Could not parse the JavaScript file at ${uri} to extract the graphql tags:`);
logger.info(String(error));
return null;
}
};
export const tsParser = (text, uri, logger) => {
try {
return { asts: [babelParser(text, ['typescript'])] };
}
catch (error) {
logger.info(`Could not parse the TypeScript file at ${uri} to extract the graphql tags:`);
logger.info(String(error));
return null;
}
};
//# sourceMappingURL=babel.js.map