{"version":3,"file":"detect-router-imports.cjs","names":[],"sources":["../../../src/utils/detect-router-imports.ts"],"sourcesContent":["import { TSESTree } from '@typescript-eslint/utils'\nimport type { ESLintUtils, TSESLint } from '@typescript-eslint/utils'\n\ntype Create = Parameters<\n  ReturnType<typeof ESLintUtils.RuleCreator>\n>[0]['create']\n\ntype Context = Parameters<Create>[0]\ntype Options = Parameters<Create>[1]\ntype Helpers = {\n  isSpecificTanstackRouterImport: (\n    node: TSESTree.Identifier,\n    source: string,\n  ) => boolean\n  isTanstackRouterImport: (node: TSESTree.Identifier) => boolean\n}\n\ntype EnhancedCreate = (\n  context: Context,\n  options: Options,\n  helpers: Helpers,\n) => ReturnType<Create>\n\nexport function detectTanstackRouterImports(create: EnhancedCreate): Create {\n  return (context, optionsWithDefault) => {\n    const tanstackRouterImportSpecifiers: Array<TSESTree.ImportClause> = []\n\n    const helpers: Helpers = {\n      isSpecificTanstackRouterImport(node, source) {\n        return !!tanstackRouterImportSpecifiers.find((specifier) => {\n          if (\n            specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier &&\n            specifier.parent.type ===\n              TSESTree.AST_NODE_TYPES.ImportDeclaration &&\n            specifier.parent.source.value === source\n          ) {\n            return node.name === specifier.local.name\n          }\n\n          return false\n        })\n      },\n      isTanstackRouterImport(node) {\n        return !!tanstackRouterImportSpecifiers.find((specifier) => {\n          if (specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier) {\n            return node.name === specifier.local.name\n          }\n\n          return false\n        })\n      },\n    }\n\n    const detectionInstructions: TSESLint.RuleListener = {\n      ImportDeclaration(node) {\n        if (\n          node.specifiers.length > 0 &&\n          // `importKind` is parser-dependent and can be undefined (eg. Espree)\n          node.importKind !== 'type' &&\n          node.source.value.startsWith('@tanstack/') &&\n          node.source.value.endsWith('-router')\n        ) {\n          tanstackRouterImportSpecifiers.push(...node.specifiers)\n        }\n      },\n    }\n\n    // Call original rule definition\n    const ruleInstructions = create(context, optionsWithDefault, helpers)\n    const enhancedRuleInstructions: TSESLint.RuleListener = {}\n\n    const allKeys = new Set(\n      Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions)),\n    )\n\n    // Iterate over ALL instructions keys so we can override original rule instructions\n    // to prevent their execution if conditions to report errors are not met.\n    allKeys.forEach((instruction) => {\n      enhancedRuleInstructions[instruction] = (node) => {\n        if (instruction in detectionInstructions) {\n          detectionInstructions[instruction]?.(node)\n        }\n\n        const ruleFunction = ruleInstructions[instruction]\n        if (ruleFunction !== undefined) {\n          return ruleFunction(node)\n        }\n\n        return undefined\n      }\n    })\n\n    return enhancedRuleInstructions\n  }\n}\n"],"mappings":";;AAuBA,SAAgB,4BAA4B,QAAgC;AAC1E,SAAQ,SAAS,uBAAuB;EACtC,MAAM,iCAA+D,EAAE;EAEvE,MAAM,UAAmB;GACvB,+BAA+B,MAAM,QAAQ;AAC3C,WAAO,CAAC,CAAC,+BAA+B,MAAM,cAAc;AAC1D,SACE,UAAU,SAAS,yBAAA,SAAS,eAAe,mBAC3C,UAAU,OAAO,SACf,yBAAA,SAAS,eAAe,qBAC1B,UAAU,OAAO,OAAO,UAAU,OAElC,QAAO,KAAK,SAAS,UAAU,MAAM;AAGvC,YAAO;MACP;;GAEJ,uBAAuB,MAAM;AAC3B,WAAO,CAAC,CAAC,+BAA+B,MAAM,cAAc;AAC1D,SAAI,UAAU,SAAS,yBAAA,SAAS,eAAe,gBAC7C,QAAO,KAAK,SAAS,UAAU,MAAM;AAGvC,YAAO;MACP;;GAEL;EAED,MAAM,wBAA+C,EACnD,kBAAkB,MAAM;AACtB,OACE,KAAK,WAAW,SAAS,KAEzB,KAAK,eAAe,UACpB,KAAK,OAAO,MAAM,WAAW,aAAa,IAC1C,KAAK,OAAO,MAAM,SAAS,UAAU,CAErC,gCAA+B,KAAK,GAAG,KAAK,WAAW;KAG5D;EAGD,MAAM,mBAAmB,OAAO,SAAS,oBAAoB,QAAQ;EACrE,MAAM,2BAAkD,EAAE;AAE1C,MAAI,IAClB,OAAO,KAAK,sBAAsB,CAAC,OAAO,OAAO,KAAK,iBAAiB,CAAC,CACzE,CAIO,SAAS,gBAAgB;AAC/B,4BAAyB,gBAAgB,SAAS;AAChD,QAAI,eAAe,sBACjB,uBAAsB,eAAe,KAAK;IAG5C,MAAM,eAAe,iBAAiB;AACtC,QAAI,iBAAiB,KAAA,EACnB,QAAO,aAAa,KAAK;;IAK7B;AAEF,SAAO"}