UNPKG

graphql-language-service-server

Version:
31 lines 1.01 kB
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