From 9debedd79075fccff6c2b55d08668c4d2181461c Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Sun, 29 Mar 2026 04:25:18 +0900 Subject: [PATCH 1/4] Fix color issue --- src/analyzer.ts | 9 +- test/analyzer.test.ts | 192 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+), 1 deletion(-) diff --git a/src/analyzer.ts b/src/analyzer.ts index bacc2cf..472cfa8 100644 --- a/src/analyzer.ts +++ b/src/analyzer.ts @@ -726,6 +726,7 @@ const SK_NamespaceImport = ts.SyntaxKind.NamespaceImport const SK_NamedExports = ts.SyntaxKind.NamedExports const SK_ExportKw = ts.SyntaxKind.ExportKeyword const SK_DefaultKw = ts.SyntaxKind.DefaultKeyword +const SK_TypeLiteral = ts.SyntaxKind.TypeLiteral function isComponentIdentifier(name: string): boolean { const code = name.charCodeAt(0) @@ -829,6 +830,7 @@ function collectSourceElements( let currentComponent: string | undefined let currentComponentTracked = false + let typeLiteralDepth = 0 const visit = (node: ts.Node): void => { const nodeKind = node.kind @@ -841,6 +843,9 @@ function collectSourceElements( return } + const isTypeLiteral = nodeKind === SK_TypeLiteral + if (isTypeLiteral) typeLiteralDepth++ + const entry = componentByPos.get(node.pos) const entered = entry !== undefined && entry.end === node.end @@ -869,7 +874,7 @@ function collectSourceElements( if (jsxTag) { jsxTags.push(jsxTag) } - } else if (nodeKind === SK_TypeReference) { + } else if (nodeKind === SK_TypeReference && typeLiteralDepth === 0) { const typeName = (node as ts.TypeReferenceNode).typeName if ( typeName.kind === SK_Identifier && @@ -937,6 +942,8 @@ function collectSourceElements( ts.forEachChild(node, visit) + if (isTypeLiteral) typeLiteralDepth-- + if (entered) { currentComponent = savedComponent currentComponentTracked = savedTracked diff --git a/test/analyzer.test.ts b/test/analyzer.test.ts index 926454c..b52cea8 100644 --- a/test/analyzer.test.ts +++ b/test/analyzer.test.ts @@ -7,6 +7,7 @@ import { expect, test } from 'bun:test' import { ComponentLensAnalyzer, type ScopeConfig } from '../src/analyzer' import { createDiskSignature, + createOpenSignature, ImportResolver, type SourceHost, } from '../src/resolver' @@ -1688,6 +1689,197 @@ test('codelens scope tracks source file paths for imports', async () => { } }) +test('does not color type references inside inline object types', async () => { + const project = createProject({ + 'Button.tsx': [ + "'use client';", + '', + 'interface ButtonProps {', + ' label: string;', + '}', + '', + 'function Button(props: { children: ReactNode }) {', + ' return