graphql-language-service-server
Version:
Server process backing the GraphQL Language Service
37 lines • 1.3 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.tsParser = exports.ecmaParser = exports.babelParser = void 0;
const parser_1 = require("@babel/parser");
const constants_1 = require("../constants");
const babelParser = (text, plugins) => {
const babelPlugins = [...constants_1.BABEL_PLUGINS];
if (plugins) {
babelPlugins.push(...plugins);
}
constants_1.PARSER_OPTIONS.plugins = babelPlugins;
return (0, parser_1.parse)(text, constants_1.PARSER_OPTIONS);
};
exports.babelParser = babelParser;
const ecmaParser = (text, uri, logger) => {
try {
return { asts: [(0, exports.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;
}
};
exports.ecmaParser = ecmaParser;
const tsParser = (text, uri, logger) => {
try {
return { asts: [(0, exports.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;
}
};
exports.tsParser = tsParser;
//# sourceMappingURL=babel.js.map
;