Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getGQLTagsFromSource = (source: string) => {
const finder = lineColumn(source);
let sdl = "";
let loc;
visit(parse(source), {
visitTaggedTemplateExpression(path) {
this.traverse(path);
const expr = path.node;
if (Identifier.check(expr.tag) && expr.tag.name === "gql") {
loc = finder.toIndex(expr.loc!.start.line, expr.loc!.start.column) + 5; // 5 = offset from the gql tag to SDL
expr.quasi.quasis.forEach(v => (sdl += v.value.raw));
}
}
});
// @ts-ignore Says `loc` is used before defined, but it isn't.
return { sdl, loc };
// return sdl;
};