{"version":3,"file":"react.mjs","names":["tsConfig","importPlugin"],"sources":["../src/shared/function-component-definition.ts","../src/react.ts"],"sourcesContent":["import {\n  merge,\n  type RuleFix,\n  type RuleFixer,\n  type RuleFunction,\n} from '@eslint-react/kit';\nimport { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/types';\n\ntype RuleContext = Parameters<RuleFunction>[0];\n\n// Adapted from https://eslint-react.xyz/docs/recipes/function-component-definition\n// to preserve the previous namedComponents: 'function-declaration' configuration.\nexport function functionComponentDefinition(): RuleFunction {\n  return (context, { collect, hint }) => {\n    const { query, visitor } = collect.components(context, {\n      hint:\n        hint.component.Default |\n        hint.component.DoNotIncludeFunctionDefinedAsObjectMethod,\n    });\n\n    return merge(visitor, {\n      'Program:exit'(program) {\n        for (const { node } of query.all(program)) {\n          if (node.type === AST_NODE_TYPES.FunctionDeclaration) continue;\n          const named = node.parent.type === AST_NODE_TYPES.VariableDeclarator;\n          if (!named && node.type === AST_NODE_TYPES.FunctionExpression)\n            continue;\n\n          const fix = buildFix(context, node);\n\n          context.report({\n            node,\n            message: named\n              ? 'Named function components must be defined with function declarations.'\n              : 'Anonymous function components must be defined with function expressions.',\n            fix,\n            suggest: [\n              {\n                desc: named\n                  ? 'Convert to function declaration.'\n                  : 'Convert to function expression.',\n                fix,\n              },\n            ],\n          });\n        }\n      },\n    });\n  };\n}\n\n/** Build the recipe's fix in the direction of the existing function style. */\nfunction buildFix(\n  context: RuleContext,\n  node: TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression,\n) {\n  return (fixer: RuleFixer): RuleFix | null => {\n    const src = context.sourceCode;\n    // Keep generator behavior and named function-expression bindings intact.\n    if (\n      node.type === AST_NODE_TYPES.FunctionExpression &&\n      (node.generator || node.id != null)\n    ) {\n      return null;\n    }\n    // Converting an arrow must not change its lexical this/arguments/super/new.target.\n    if (\n      node.type === AST_NODE_TYPES.ArrowFunctionExpression &&\n      src\n        .getTokens(node)\n        .some(\n          (token, index, tokens) =>\n            ['this', 'arguments', 'super'].includes(token.value) ||\n            (token.value === 'target' &&\n              tokens[index - 1]?.value === '.' &&\n              tokens[index - 2]?.value === 'new'),\n        )\n    ) {\n      return null;\n    }\n\n    const prefix = node.async ? 'async ' : '';\n    const typeParams =\n      node.typeParameters != null ? src.getText(node.typeParameters) : '';\n    const firstParam = node.params[0];\n    const lastParam = node.params.at(-1);\n    const params =\n      firstParam && lastParam\n        ? `(${src.text.slice(firstParam.range[0], lastParam.range[1])})`\n        : '()';\n    const returnType =\n      node.returnType != null ? src.getText(node.returnType) : '';\n    const body =\n      node.body.type === AST_NODE_TYPES.BlockStatement\n        ? src.getText(node.body)\n        : `{ return ${src.getText(node.body)}; }`;\n\n    // Replace the declaration, leaving an enclosing `export` in place.\n    if (node.parent.type === AST_NODE_TYPES.VariableDeclarator) {\n      const declarator = node.parent;\n      const declaration = declarator.parent;\n      if (\n        declarator.id.type !== AST_NODE_TYPES.Identifier ||\n        declarator.id.typeAnnotation != null ||\n        declaration.declarations.length !== 1 ||\n        ![\n          AST_NODE_TYPES.Program,\n          AST_NODE_TYPES.BlockStatement,\n          AST_NODE_TYPES.ExportNamedDeclaration,\n        ].includes(declaration.parent.type)\n      ) {\n        return null;\n      }\n\n      return fixer.replaceText(\n        declaration,\n        `${prefix}function ${declarator.id.name}${typeParams}${params}${returnType} ${body}`,\n      );\n    }\n\n    // Anonymous callbacks/default exports cannot become named declarations.\n    if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) {\n      return fixer.replaceText(\n        node,\n        `${prefix}function${typeParams}${params}${returnType} ${body}`,\n      );\n    }\n\n    return null;\n  };\n}\n","import react from '@eslint-react/eslint-plugin';\nimport eslintReactKit from '@eslint-react/kit';\nimport { defineConfig } from 'eslint/config';\nimport prettier from 'eslint-config-prettier';\nimport { importX as importPlugin } from 'eslint-plugin-import-x';\nimport reactHooks from 'eslint-plugin-react-hooks';\nimport { reactRefresh } from 'eslint-plugin-react-refresh';\nimport globals from 'globals';\n\nimport { functionComponentDefinition } from './shared/function-component-definition.js';\nimport tsConfig from './ts.js';\n\nexport default {\n  configs: {\n    recommended: defineConfig(\n      tsConfig.configs.recommended,\n      importPlugin.flatConfigs.react,\n      {\n        name: 'react/src-globals',\n        files: ['**/*.{js,jsx,ts,tsx}'],\n        languageOptions: {\n          globals: globals.browser,\n        },\n      },\n      react.configs['recommended-typescript'],\n      eslintReactKit().use(functionComponentDefinition).getConfig(),\n      reactHooks.configs.flat['recommended-latest'],\n      react.configs['disable-conflict-eslint-plugin-react-hooks'],\n      reactRefresh.configs.vite(),\n      prettier,\n    ),\n    reactRefreshTanstackRouterOverride: defineConfig(\n      reactRefresh.configs.vite({\n        // XXX: workaround for @tanstack/react-router to suppress the error, but actually react\n        // router doesn't have good support for HMR\n        // References:\n        // https://github.com/ArnaudBarre/eslint-plugin-react-refresh/releases/tag/v0.5.0\n        // https://bsky.app/profile/arnaud-barre.bsky.social/post/3ma5h5tf2sk2e\n        extraHOCs: [\n          'createFileRoute',\n          'createLazyFileRoute',\n          'createRootRoute',\n          'createRootRouteWithContext',\n          'createRoute',\n          'createLazyRoute',\n        ],\n      }),\n    ),\n  },\n};\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,8BAA4C;CAC1D,QAAQ,SAAS,EAAE,SAAS,WAAW;EACrC,MAAM,EAAE,OAAO,YAAY,QAAQ,WAAW,SAAS,EACrD,MACE,KAAK,UAAU,UACf,KAAK,UAAU,0CACnB,CAAC;EAED,OAAO,MAAM,SAAS,EACpB,eAAe,SAAS;GACtB,KAAK,MAAM,EAAE,UAAU,MAAM,IAAI,OAAO,GAAG;IACzC,IAAI,KAAK,SAAS,eAAe,qBAAqB;IACtD,MAAM,QAAQ,KAAK,OAAO,SAAS,eAAe;IAClD,IAAI,CAAC,SAAS,KAAK,SAAS,eAAe,oBACzC;IAEF,MAAM,MAAM,SAAS,SAAS,IAAI;IAElC,QAAQ,OAAO;KACb;KACA,SAAS,QACL,0EACA;KACJ;KACA,SAAS,CACP;MACE,MAA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