From e8a3f614c7a4546a6babb035904a8ea0325ec46d Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Sat, 14 Jun 2025 21:31:00 +0300 Subject: [PATCH] fix(61867): fix find-all-refs for constructors involving string literals --- src/services/findAllReferences.ts | 4 +- .../findAllRefsConstructor.baseline.jsonc | 82 +++++++++++++++++++ .../cases/fourslash/findAllRefsConstructor.ts | 10 +++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/findAllRefsConstructor.baseline.jsonc create mode 100644 tests/cases/fourslash/findAllRefsConstructor.ts diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index a2ed0feb795a7..857e05f011884 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1838,13 +1838,13 @@ export namespace Core { case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.StringLiteral: { const str = node as StringLiteralLike; - return str.text.length === searchSymbolName.length && ( + return ( isLiteralNameOfPropertyDeclarationOrIndexAccess(str) || isNameOfModuleDeclaration(node) || isExpressionOfExternalModuleImportEqualsDeclaration(node) || (isCallExpression(node.parent) && isBindableObjectDefinePropertyCall(node.parent) && node.parent.arguments[1] === node) || isImportOrExportSpecifier(node.parent) - ); + ) && str.text.length === searchSymbolName.length; } case SyntaxKind.NumericLiteral: diff --git a/tests/baselines/reference/findAllRefsConstructor.baseline.jsonc b/tests/baselines/reference/findAllRefsConstructor.baseline.jsonc new file mode 100644 index 0000000000000..6f4635faedc2a --- /dev/null +++ b/tests/baselines/reference/findAllRefsConstructor.baseline.jsonc @@ -0,0 +1,82 @@ +// === findAllReferences === +// === lib.d.ts === +// --- (line: --) skipped --- +// +// interface Object { +// /** The initial value of Object.prototype.constructor is the standard built-in Object constructor. */ +// <|[|{| isWriteAccess: true |}constructor|]: Function;|> +// +// /** Returns a string representation of an object. */ +// toString(): string; +// --- (line: --) skipped --- + +// === /tests/cases/fourslash/findAllRefsConstructor.ts === +// class A { +// 'constructor'() { } +// } +// const a = new A() +// console.log(a.[|constructor|]/*FIND ALL REFS*/) + + // === Definitions === + // === lib.d.ts === + // --- (line: --) skipped --- + // + // interface Object { + // /** The initial value of Object.prototype.constructor is the standard built-in Object constructor. */ + // <|[|constructor|]: Function;|> + // + // /** Returns a string representation of an object. */ + // toString(): string; + // --- (line: --) skipped --- + + // === Details === + [ + { + "containerKind": "", + "containerName": "", + "kind": "property", + "name": "(property) Object.constructor: Function", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Object", + "kind": "localName" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "constructor", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Function", + "kind": "localName" + } + ] + } + ] \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsConstructor.ts b/tests/cases/fourslash/findAllRefsConstructor.ts new file mode 100644 index 0000000000000..53b8aabaa6c5a --- /dev/null +++ b/tests/cases/fourslash/findAllRefsConstructor.ts @@ -0,0 +1,10 @@ +/// +// @target: esnext + +////class A { +//// 'constructor'() { } +////} +////const a = new A() +////console.log(a.constructor/**/) + +verify.baselineFindAllReferences('');