mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-12 21:37:41 -06:00
Fix bug: replacmentSpan for completion shouldn't include property name that doesn't start with completion name (#21587) (#21648)
This commit is contained in:
parent
f13f0934a4
commit
24ec4d612e
@ -185,7 +185,10 @@ namespace ts.Completions {
|
||||
else if (needsConvertPropertyAccess) {
|
||||
// TODO: GH#20619 Use configured quote style
|
||||
insertText = `["${name}"]`;
|
||||
replacementSpan = createTextSpanFromBounds(findChildOfKind(propertyAccessToConvert!, SyntaxKind.DotToken, sourceFile)!.getStart(sourceFile), propertyAccessToConvert!.name.end);
|
||||
const dot = findChildOfKind(propertyAccessToConvert!, SyntaxKind.DotToken, sourceFile)!;
|
||||
// If the text after the '.' starts with this name, write over it. Else, add new text.
|
||||
const end = startsWith(name, propertyAccessToConvert!.name.text) ? propertyAccessToConvert!.name.end : dot.end;
|
||||
replacementSpan = createTextSpanFromBounds(dot.getStart(sourceFile), end);
|
||||
}
|
||||
|
||||
if (isJsxInitializer) {
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////declare const x: { "foo ": "space in the name", };
|
||||
////x[|.fo/**/|];
|
||||
////x[|.fo/*0*/|];
|
||||
////x[|./*1*/|]
|
||||
////unrelatedIdentifier;
|
||||
|
||||
const replacementSpan = test.ranges()[0];
|
||||
verify.completionsAt("", [{ name: "foo ", insertText: '["foo "]', replacementSpan }], { includeInsertTextCompletions: true });
|
||||
const [r0, r1] = test.ranges();
|
||||
verify.completionsAt("0", [{ name: "foo ", insertText: '["foo "]', replacementSpan: r0 }], { includeInsertTextCompletions: true });
|
||||
verify.completionsAt("1", [{ name: "foo ", insertText: '["foo "]', replacementSpan: r1 }], { includeInsertTextCompletions: true });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user