Skip to content

Commit 19db9ad

Browse files
authored
Swapping the quote style of a string for completions should swap _all_ quotes in the string (#42650)
1 parent f569aa3 commit 19db9ad

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/services/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ namespace ts {
24952495
// Editors can pass in undefined or empty string - we want to infer the preference in those cases.
24962496
const quotePreference = getQuotePreference(sourceFile, preferences);
24972497
const quoted = JSON.stringify(text);
2498-
return quotePreference === QuotePreference.Single ? `'${stripQuotes(quoted).replace("'", "\\'").replace('\\"', '"')}'` : quoted;
2498+
return quotePreference === QuotePreference.Single ? `'${stripQuotes(quoted).replace(/'/g, "\\'").replace(/\\"/g, '"')}'` : quoted;
24992499
}
25002500

25012501
export function isEqualityOperatorKind(kind: SyntaxKind): kind is EqualityOperator {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @filename: /a.ts
4+
////export const a = null;
5+
6+
// @filename: /b.ts
7+
////import { a } from './a';
8+
////
9+
////const foo = { '"a name\'s all good but it\'s better with more"': null };
10+
////foo[|./**/|]
11+
12+
goTo.file("/b.ts");
13+
verify.completions({
14+
marker: "",
15+
exact: [
16+
{ 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] },
17+
],
18+
preferences: {
19+
includeInsertTextCompletions: true,
20+
quotePreference: "auto"
21+
}
22+
});

0 commit comments

Comments
 (0)