mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-15 22:15:05 -05:00
Improve inlining of string variables in template literals (#54849)
This commit is contained in:
13
tests/cases/fourslash/inlineVariableTemplateString1.ts
Normal file
13
tests/cases/fourslash/inlineVariableTemplateString1.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const /*a*/pizza/*b*/ = "🍕";
|
||||
////export const prompt = `Hello, would you like some ${pizza}?`;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent: "export const prompt = `Hello, would you like some 🍕?`;"
|
||||
});
|
||||
13
tests/cases/fourslash/inlineVariableTemplateString10.ts
Normal file
13
tests/cases/fourslash/inlineVariableTemplateString10.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const /*a*/message/*b*/ = "Hello, World!";
|
||||
////await $`echo ${((message))}`;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent: 'await $`echo ${(("Hello, World!"))}`;',
|
||||
});
|
||||
13
tests/cases/fourslash/inlineVariableTemplateString11.ts
Normal file
13
tests/cases/fourslash/inlineVariableTemplateString11.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const /*a*/pizza/*b*/ = "🍕";
|
||||
////export const prompt = `Hello, would you like some ${((pizza))}?`;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent: "export const prompt = `Hello, would you like some 🍕?`;"
|
||||
});
|
||||
13
tests/cases/fourslash/inlineVariableTemplateString2.ts
Normal file
13
tests/cases/fourslash/inlineVariableTemplateString2.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const /*a*/codeText/*b*/ = "Code-formatted text looks `like this` and requires surrounding by backticks (\\`).";
|
||||
////export const mdTutorial = `Let's talk about markdown.\n${codeText}?`;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent: "export const mdTutorial = `Let's talk about markdown.\\nCode-formatted text looks \\`like this\\` and requires surrounding by backticks (\\\\\\\`).?`;"
|
||||
});
|
||||
15
tests/cases/fourslash/inlineVariableTemplateString3.ts
Normal file
15
tests/cases/fourslash/inlineVariableTemplateString3.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const /*a*/pizza/*b*/ = "🍕";
|
||||
////export const prompt = `Hello, would you like some ${
|
||||
//// pizza
|
||||
//// }?`;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent: "export const prompt = `Hello, would you like some 🍕?`;"
|
||||
});
|
||||
13
tests/cases/fourslash/inlineVariableTemplateString4.ts
Normal file
13
tests/cases/fourslash/inlineVariableTemplateString4.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const /*a*/pizza/*b*/ = "🍕";
|
||||
////export const prompt = `Hello, would you like some ${pizza} or ${pizza}?`;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent: "export const prompt = `Hello, would you like some 🍕 or 🍕?`;"
|
||||
});
|
||||
13
tests/cases/fourslash/inlineVariableTemplateString5.ts
Normal file
13
tests/cases/fourslash/inlineVariableTemplateString5.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const /*a*/pizza/*b*/ = "🍕";
|
||||
////export const prompt = `Hello, would you like some ${pizza}`;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent: "export const prompt = `Hello, would you like some 🍕`;"
|
||||
});
|
||||
13
tests/cases/fourslash/inlineVariableTemplateString6.ts
Normal file
13
tests/cases/fourslash/inlineVariableTemplateString6.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const /*a*/x/*b*/ = "\\`";
|
||||
////export const y = `${x}`;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent: "export const y = `\\\\\\``;"
|
||||
});
|
||||
13
tests/cases/fourslash/inlineVariableTemplateString7.ts
Normal file
13
tests/cases/fourslash/inlineVariableTemplateString7.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const /*a*/x/*b*/ = "`";
|
||||
////export const y = `${x}`;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent: "export const y = `\\``;"
|
||||
});
|
||||
13
tests/cases/fourslash/inlineVariableTemplateString8.ts
Normal file
13
tests/cases/fourslash/inlineVariableTemplateString8.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const /*a*/message/*b*/ = "Hello, World!";
|
||||
////await $`echo ${message}`;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent: 'await $`echo ${"Hello, World!"}`;',
|
||||
});
|
||||
13
tests/cases/fourslash/inlineVariableTemplateString9.ts
Normal file
13
tests/cases/fourslash/inlineVariableTemplateString9.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const /*a*/message/*b*/ = "Hello, World!";
|
||||
////await $`echo ${(message)}`;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent: 'await $`echo ${("Hello, World!")}`;',
|
||||
});
|
||||
Reference in New Issue
Block a user