Improve inlining of string variables in template literals (#54849)

This commit is contained in:
Zzzen
2024-08-16 01:46:22 +08:00
committed by GitHub
parent 20f26a481b
commit a0530722fc
12 changed files with 172 additions and 1 deletions

View 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 🍕?`;"
});

View 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!"))}`;',
});

View 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 🍕?`;"
});

View 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 (\\\\\\\`).?`;"
});

View 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 🍕?`;"
});

View 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 🍕?`;"
});

View 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 🍕`;"
});

View 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 = `\\\\\\``;"
});

View 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 = `\\``;"
});

View 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!"}`;',
});

View 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!")}`;',
});