Escape quotes in bracketed completions (#21676) (#21683)

This commit is contained in:
Andy 2018-02-06 10:00:32 -08:00 committed by GitHub
parent b671a8ce1f
commit c4dca618ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -180,11 +180,10 @@ namespace ts.Completions {
let replacementSpan: TextSpan | undefined;
if (includeInsertTextCompletions) {
if (origin && origin.type === "this-type") {
insertText = needsConvertPropertyAccess ? `this["${name}"]` : `this.${name}`;
insertText = needsConvertPropertyAccess ? `this[${quote(name)}]` : `this.${name}`;
}
else if (needsConvertPropertyAccess) {
// TODO: GH#20619 Use configured quote style
insertText = `["${name}"]`;
insertText = `[${quote(name)}]`;
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;
@ -222,6 +221,10 @@ namespace ts.Completions {
};
}
function quote(text: string): string {
// TODO: GH#20619 Use configured quote style
return JSON.stringify(text);
}
function isRecommendedCompletionMatch(localSymbol: Symbol, recommendedCompletion: Symbol, checker: TypeChecker): boolean {
return localSymbol === recommendedCompletion ||

View File

@ -0,0 +1,7 @@
/// <reference path='fourslash.ts' />
////declare const x: { '"': 0 };
////x[|./**/|];
const replacementSpan = test.ranges()[0];
verify.completionsAt("", [{ name: '"', insertText: '["\\""]', replacementSpan }], { includeInsertTextCompletions: true });