{"version":3,"file":"components.mjs","names":["findComponentRoot","file","resolve","filename","directory","dirname","roots","definesComponent","conventionalComponentRoot","match","relative","root","sep","config","existsSync","parseSync","readFileSync","errors","names","namespaces","statement","program","specifier","declaration","expressions","item","expression","callee"],"sources":["../../src/oxlint/components.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, resolve, relative, sep } from 'node:path'\nimport { parseSync } from 'oxc-parser'\n\n/** Locate standalone components as well as the conventional components/<name> layout. */\nexport function findComponentRoot(filename: string, roots: readonly string[] = []) {\n\tconst file = resolve(filename)\n\tfor (let directory = dirname(file); ; directory = dirname(directory)) {\n\t\tif (roots.includes(directory) || definesComponent(directory)) return directory\n\t\tif (dirname(directory) === directory) return null\n\t}\n}\n\nexport function conventionalComponentRoot(filename: string, root: string) {\n\tconst match = relative(root, filename)\n\t\t.split(sep)\n\t\t.join('/')\n\t\t.match(/^components\\/([^/]+)(?:\\/|$)/)\n\treturn match ? resolve(root, 'components', match[1]) : null\n}\n\nfunction definesComponent(directory: string) {\n\tconst config = resolve(directory, 'convex.config.ts')\n\tif (!existsSync(config)) return false\n\tconst { program, errors } = parseSync(config, readFileSync(config, 'utf8'))\n\tif (errors.length) return false\n\tconst names = new Set<string>()\n\tconst namespaces = new Set<string>()\n\tfor (const statement of program.body) {\n\t\tif (statement.type !== 'ImportDeclaration' || statement.source.value !== 'convex/server')\n\t\t\tcontinue\n\t\tfor (const specifier of statement.specifiers) {\n\t\t\tif (specifier.type === 'ImportNamespaceSpecifier') namespaces.add(specifier.local.name)\n\t\t\tif (\n\t\t\t\tspecifier.type === 'ImportSpecifier' &&\n\t\t\t\t(specifier.imported.type === 'Identifier'\n\t\t\t\t\t? specifier.imported.name\n\t\t\t\t\t: specifier.imported.value) === 'defineComponent'\n\t\t\t)\n\t\t\t\tnames.add(specifier.local.name)\n\t\t}\n\t}\n\tfor (const statement of program.body) {\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' ? statement.declaration : statement\n\t\tconst expressions =\n\t\t\tdeclaration?.type === 'VariableDeclaration'\n\t\t\t\t? declaration.declarations.map((item) => item.init)\n\t\t\t\t: statement.type === 'ExportDefaultDeclaration'\n\t\t\t\t\t? [statement.declaration]\n\t\t\t\t\t: []\n\t\tfor (const expression of expressions) {\n\t\t\tif (expression?.type !== 'CallExpression') continue\n\t\t\tconst callee = expression.callee\n\t\t\tif (callee.type === 'Identifier' && names.has(callee.name)) return true\n\t\t\tif (\n\t\t\t\tcallee.type === 'MemberExpression' &&\n\t\t\t\t!callee.computed &&\n\t\t\t\tcallee.property.type === 'Identifier' &&\n\t\t\t\tcallee.property.name === 'defineComponent' &&\n\t\t\t\tcallee.object.type === 'Identifier' &&\n\t\t\t\tnamespaces.has(callee.object.name)\n\t\t\t)\n\t\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n"],"mappings":"sKAKA,SAAgBA,EAAkB,EAAkB,EAA2B,CAAC,EAAG,CAClF,IAAMC,EAAOC,EAAQC,CAAQ,EAC7B,IAAK,IAAIC,EAAYC,EAAQJ,CAAI,GAAK,EAAYI,EAAQD,CAAS,EAAG,CACrE,GAAIE,EAAM,SAASF,CAAS,GAAKG,EAAiBH,CAAS,EAAG,OAAOA,EACrE,GAAIC,EAAQD,CAAS,IAAMA,EAAW,OAAO,IAC9C,CACD,CAEA,SAAgBI,EAA0B,EAAkB,EAAc,CACzE,IAAMC,EAAQC,EAASC,EAAMR,CAAQ,CAAC,CACpC,MAAMS,CAAG,CAAC,CACV,KAAK,GAAG,CAAC,CACT,MAAM,8BAA8B,EACtC,OAAOH,EAAQP,EAAQS,EAAM,aAAcF,EAAM,EAAE,EAAI,IACxD,CAEA,SAASF,EAAiB,EAAmB,CAC5C,IAAMM,EAASX,EAAQE,EAAW,kBAAkB,EACpD,GAAI,CAACU,EAAWD,CAAM,EAAG,MAAO,GAChC,GAAM,CAAE,UAAS,UAAWE,EAAUF,EAAQG,EAAaH,EAAQ,MAAM,CAAC,EAC1E,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