diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 1fb8a23043ef7..d57f267ea977c 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2495,7 +2495,7 @@ namespace ts { // Editors can pass in undefined or empty string - we want to infer the preference in those cases. const quotePreference = getQuotePreference(sourceFile, preferences); const quoted = JSON.stringify(text); - return quotePreference === QuotePreference.Single ? `'${stripQuotes(quoted).replace("'", "\\'").replace('\\"', '"')}'` : quoted; + return quotePreference === QuotePreference.Single ? `'${stripQuotes(quoted).replace(/'/g, "\\'").replace(/\\"/g, '"')}'` : quoted; } export function isEqualityOperatorKind(kind: SyntaxKind): kind is EqualityOperator { diff --git a/tests/cases/fourslash/completionForStringLiteral_quotePreference8.ts b/tests/cases/fourslash/completionForStringLiteral_quotePreference8.ts new file mode 100644 index 0000000000000..9e66dcb1fe953 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteral_quotePreference8.ts @@ -0,0 +1,22 @@ +/// + +// @filename: /a.ts +////export const a = null; + +// @filename: /b.ts +////import { a } from './a'; +//// +////const foo = { '"a name\'s all good but it\'s better with more"': null }; +////foo[|./**/|] + +goTo.file("/b.ts"); +verify.completions({ + marker: "", + exact: [ + { name: "\"a name's all good but it's better with more\"", insertText: "['\"a name\\'s all good but it\\'s better with more\"']", replacementSpan: test.ranges()[0] }, + ], + preferences: { + includeInsertTextCompletions: true, + quotePreference: "auto" + } +});