From 3f38a133c481c254040715be1e98aa417782f82f Mon Sep 17 00:00:00 2001 From: falshami2002 Date: Mon, 28 Jul 2025 22:33:42 -0700 Subject: [PATCH 1/2] Adding a space after the string literal in a computed property name causes an incorrect hover display #62101 --- src/compiler/checker.ts | 2 +- .../cases/fourslash/hoverComputedPropertyWhitespace.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/hoverComputedPropertyWhitespace.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 77f35376da785..268498b7efc44 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8858,7 +8858,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } else { if (firstChar === CharacterCodes.openBracket) { - symbolName = symbolName.substring(1, symbolName.length - 1); + symbolName = symbolName.substring(1, symbolName.length - 1).trim(); firstChar = symbolName.charCodeAt(0); } let expression: Expression | undefined; diff --git a/tests/cases/fourslash/hoverComputedPropertyWhitespace.ts b/tests/cases/fourslash/hoverComputedPropertyWhitespace.ts new file mode 100644 index 0000000000000..50f995ea22fe6 --- /dev/null +++ b/tests/cases/fourslash/hoverComputedPropertyWhitespace.ts @@ -0,0 +1,10 @@ +/// +//// interface Point { +//// ["x" ]: number; +//// } +//// +//// const p: Point = { ["x" ]: 42 }; +//// p["x"/*hover*/]; + +goTo.marker("hover"); +verify.quickInfoIs('(property) Point["x"]: number'); \ No newline at end of file From 69fb417716ef6b2fe96c1e5c210268c5701c93b8 Mon Sep 17 00:00:00 2001 From: falshami2002 Date: Mon, 28 Jul 2025 23:27:01 -0700 Subject: [PATCH 2/2] Moved .trim() to prevent unintended consequences on conformity ES5 and ES6 test cases. Passing all test cases now. --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 268498b7efc44..00dc170c2bb84 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8858,12 +8858,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } else { if (firstChar === CharacterCodes.openBracket) { - symbolName = symbolName.substring(1, symbolName.length - 1).trim(); + symbolName = symbolName.substring(1, symbolName.length - 1); firstChar = symbolName.charCodeAt(0); } let expression: Expression | undefined; if (isSingleOrDoubleQuote(firstChar) && !(symbol.flags & SymbolFlags.EnumMember)) { - const literalText = stripQuotes(symbolName).replace(/\\./g, s => s.substring(1)); + const literalText = stripQuotes(symbolName.trim()).replace(/\\./g, s => s.substring(1)); context.approximateLength += literalText.length + 2; // "literalText" expression = factory.createStringLiteral(literalText, firstChar === CharacterCodes.singleQuote); }