Escape quotes in bracketed completions (#21676)

This commit is contained in:
Andy
2018-02-06 09:28:03 -08:00
committed by GitHub
parent abe814f473
commit 044fb53476
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 ||