mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Merge pull request #23423 from Kingwl/add-braces
add support for add or remove braces to arrow function
This commit is contained in:
31 files changed
+408
-16
No files matched your search
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => a + 1;
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Add braces to arrow function",
|
||||
actionDescription: "Add braces to arrow function",
|
||||
newContent: `const foo = a => {
|
||||
return a + 1;
|
||||
};`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return (1, 2, 3); };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => (1, 2, 3);`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return 1, 2, 3; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => (1, 2, 3);`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return "foo"; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => "foo";`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return null; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => null;`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return undefined; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => undefined;`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return void 0; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => void 0;`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return {}; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => ({});`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return `abc{a}`; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => \`abc{a}\`;`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return `abc`; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => \`abc\`;`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return a; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => a;`,
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => ({ a: 1 });
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Add braces to arrow function",
|
||||
actionDescription: "Add braces to arrow function",
|
||||
newContent: `const foo = a => {
|
||||
return ({ a: 1 });
|
||||
};`,
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => {
|
||||
//// // return comment
|
||||
//// return a;
|
||||
//// };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => /* return comment*/ a;`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => void 0;`,
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const /*a*/foo/*b*/ = /*c*/(/*d*//*e*/aa/*f*/aa, /*g*/b/*h*/) /*i*//*j*/ /*k*/=>/*l*/ /*m*/{/*n*/ /*o*/return/*p*/ 1; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.not.refactorAvailable("Add or remove braces in an arrow function", "Remove braces from arrow function")
|
||||
|
||||
goTo.select("c", "d");
|
||||
verify.refactorAvailable("Add or remove braces in an arrow function", "Remove braces from arrow function")
|
||||
|
||||
goTo.select("e", "f");
|
||||
verify.refactorAvailable("Add or remove braces in an arrow function", "Remove braces from arrow function")
|
||||
|
||||
goTo.select("g", "h");
|
||||
verify.refactorAvailable("Add or remove braces in an arrow function", "Remove braces from arrow function")
|
||||
|
||||
goTo.select("i", "j");
|
||||
verify.refactorAvailable("Add or remove braces in an arrow function", "Remove braces from arrow function")
|
||||
|
||||
goTo.select("k", "l");
|
||||
verify.refactorAvailable("Add or remove braces in an arrow function", "Remove braces from arrow function")
|
||||
|
||||
goTo.select("m", "n");
|
||||
verify.not.refactorAvailable("Add or remove braces in an arrow function", "Remove braces from arrow function")
|
||||
|
||||
goTo.select("o", "p");
|
||||
verify.not.refactorAvailable("Add or remove braces in an arrow function", "Remove braces from arrow function")
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const /*a*/foo/*b*/ = /*c*/()/*d*/ /*e*//*f*/ /*g*/=>/*h*/ /*i*/1/*j*/;
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.not.refactorAvailable("Add or remove braces in an arrow function", "Add braces to arrow function")
|
||||
|
||||
goTo.select("c", "d");
|
||||
verify.refactorAvailable("Add or remove braces in an arrow function", "Add braces to arrow function")
|
||||
|
||||
goTo.select("e", "f");
|
||||
verify.refactorAvailable("Add or remove braces in an arrow function", "Add braces to arrow function")
|
||||
|
||||
goTo.select("g", "h");
|
||||
verify.refactorAvailable("Add or remove braces in an arrow function", "Add braces to arrow function")
|
||||
|
||||
goTo.select("i", "j");
|
||||
verify.not.refactorAvailable("Add or remove braces in an arrow function", "Add braces to arrow function")
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => 1;
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Add braces to arrow function",
|
||||
actionDescription: "Add braces to arrow function",
|
||||
newContent: `const foo = a => {
|
||||
return 1;
|
||||
};`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return a + 1; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => a + 1;`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return { a: 1 }; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => ({ a: 1 });`,
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { return 1; };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Remove braces from arrow function",
|
||||
actionDescription: "Remove braces from arrow function",
|
||||
newContent: `const foo = a => 1;`,
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => { };
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.not.refactorAvailable("Add or remove braces in an arrow function");
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => {
|
||||
//// const b = 1;
|
||||
//// return a + b;
|
||||
//// };
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.not.refactorAvailable("Add or remove braces in an arrow function");
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*a*/a/*b*/ => (1, 2, 3);
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Add braces to arrow function",
|
||||
actionDescription: "Add braces to arrow function",
|
||||
newContent: `const foo = a => {
|
||||
return (1, 2, 3);
|
||||
};`,
|
||||
});
|
||||
Reference in new issue
Block a user