{
  "version": 3,
  "sources": ["../src/findGraphQLTags.ts"],
  "sourcesContent": ["/**\n * Taken from https://github.com/relay-tools/relay-compiler-language-typescript/blob/b186ac3d9d9682949638211c3126c015f8706b0f/src/FindGraphQLTags.ts\n * License: MIT\n * Copyright 2018 Kaare Hoff Skovgaard kaare@kaareskovgaard.net, Eloy Dur\u00E1n eloy.de.enige@gmail.com\n */\n\nimport * as ts from \"typescript\";\nimport {\n  GraphQLTag,\n  GraphQLTagFinder,\n} from \"relay-compiler/lib/language/RelayLanguagePluginInterface\";\nimport invariant from \"invariant\";\n// import { rewriteGraphitationDirectives } from \"./rewriteGraphitationDirectives\";\n\nfunction isGraphQLTag(tag: ts.Node): boolean {\n  return (\n    tag.kind === ts.SyntaxKind.Identifier &&\n    (tag as ts.Identifier).text === \"graphql\"\n  );\n}\n\nexport function findGraphQLTagsFactory(\n  allowInterpolation: boolean,\n): GraphQLTagFinder {\n  /**\n   * @note Difference from the TS language plugin is that we only support hooks, so no need for HOCs.\n   */\n  function visit(\n    node: ts.Node,\n    addGraphQLTag: (tag: GraphQLTag) => void,\n  ): void {\n    function visitNode(node: ts.Node) {\n      switch (node.kind) {\n        case ts.SyntaxKind.TaggedTemplateExpression: {\n          const taggedTemplate = node as ts.TaggedTemplateExpression;\n          if (isGraphQLTag(taggedTemplate.tag)) {\n            // TODO: This code previously had no validation and thus no\n            //       keyName/sourceLocationOffset. Are these right?\n            addGraphQLTag({\n              keyName: null,\n              template: getGraphQLText(taggedTemplate),\n              sourceLocationOffset: getSourceLocationOffset(taggedTemplate),\n            });\n          }\n        }\n      }\n      ts.forEachChild(node, visitNode);\n    }\n\n    visitNode(node);\n  }\n\n  /**\n   * @note The difference here is that we do allow substitutions, but only in the trailing part, so we always return the\n   *       head. This might lead to a bad DX when the user does allow substitution in the document part and receiving\n   *       hard to understand errors, but seeing as this is meant as temporary solution it may be a worthwhile trade-off.\n   */\n  function getTemplateNode(quasi: ts.TaggedTemplateExpression) {\n    if (\n      allowInterpolation &&\n      quasi.template.kind === ts.SyntaxKind.TemplateExpression\n    ) {\n      return quasi.template.head;\n    }\n    invariant(\n      quasi.template.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral,\n      \"FindGraphQLTags: Interpolations are not allowed in graphql tags.\",\n    );\n    return quasi.template as ts.NoSubstitutionTemplateLiteral;\n  }\n\n  /**\n   * @note The difference here is that we rewrite graphitation specific directives to relay ones.\n   */\n  function getGraphQLText(quasi: ts.TaggedTemplateExpression) {\n    // return rewriteGraphitationDirectives(getTemplateNode(quasi).text);\n    return getTemplateNode(quasi).text;\n  }\n\n  function getSourceLocationOffset(quasi: ts.TaggedTemplateExpression) {\n    const pos = getTemplateNode(quasi).pos;\n    const loc = quasi.getSourceFile().getLineAndCharacterOfPosition(pos);\n    return {\n      line: loc.line + 1,\n      column: loc.character + 1,\n    };\n  }\n\n  return (text, filePath) => {\n    const result: GraphQLTag[] = [];\n    const ast = ts.createSourceFile(\n      filePath,\n      text,\n      ts.ScriptTarget.Latest,\n      true,\n    );\n    visit(ast, (tag) => result.push(tag));\n    return result;\n  };\n}\n"],
  "mappings": ";AAMA,YAAY,QAAQ;AAKpB,OAAO,eAAe;AAGtB,SAAS,aAAa,KAAuB;AAC3C,SACE,IAAI,SAAY,cAAW,cAC1B,IAAsB,SAAS;AAEpC;AAEO,SAAS,uBACd,oBACkB;AAIlB,WAAS,MACP,MACA,eACM;AACN,aAAS,UAAUA,OAAe;AAChC,cAAQA,MAAK,MAAM;AAAA,QACjB,KAAQ,cAAW,0BAA0B;AAC3C,gBAAM,iBAAiBA;AACvB,cAAI,aAAa,eAAe,GAAG,GAAG;AAGpC,0BAAc;AAAA,cACZ,SAAS;AAAA,cACT,UAAU,eAAe,cAAc;AAAA,cACvC,sBAAsB,wBAAwB,cAAc;AAAA,YAC9D,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF;AACA,MAAG,gBAAaA,OAAM,SAAS;AAAA,IACjC;AAEA,cAAU,IAAI;AAAA,EAChB;AA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