Simplify test cases

This commit is contained in:
Andrew Casey 2018-01-12 11:11:01 -08:00
parent 3b5689fa1f
commit 5de6ac1a2f
5 changed files with 11 additions and 16 deletions

View file

@ -123,6 +123,9 @@ namespace ts.codefix {
case SyntaxKind.Parameter:
const oldFunction = parent.parent;
if (isArrowFunction(oldFunction) && oldFunction.parameters.length === 1) {
// Lambdas with exactly one parameter are special because, after removal, there
// must be an empty parameter list (i.e. `()`) and this won't necessarily be the
// case if the parameter is simply removed (e.g. in `x => 1`).
const newFunction = updateArrowFunction(
oldFunction,
oldFunction.modifiers,

View file

@ -2,13 +2,11 @@
// @noUnusedLocals: true
// @noUnusedParameters: true
//// function f1() {
//// [|return /*~a*/(/*~b*/x/*~c*/:/*~d*/number/*~e*/)/*~f*/ => /*~g*/{/*~h*/}/*~i*/|]
//// }
////[|/*~a*/(/*~b*/x/*~c*/:/*~d*/number/*~e*/)/*~f*/ => /*~g*/{/*~h*/}/*~i*/|]
// In a perfect world, /*~f*/ and /*~h*/ would probably be retained.
verify.codeFix({
description: "Remove declaration for: 'x'",
index: 0,
newRangeContent: "return /*~a*/() => /*~g*/ { }/*~i*/",
newRangeContent: "/*~a*/() => /*~g*/ { }/*~i*/",
});

View file

@ -2,13 +2,11 @@
// @noUnusedLocals: true
// @noUnusedParameters: true
//// function f1() {
//// [|return /*~a*/x/*~b*/ /*~c*/=>/*~d*/ {/*~e*/}/*~f*/|]
//// }
////[|/*~a*/x/*~b*/ /*~c*/=>/*~d*/ {/*~e*/}/*~f*/|]
// In a perfect world, /*~c*/ and /*~e*/ would probably be retained.
verify.codeFix({
description: "Remove declaration for: 'x'",
index: 0,
newRangeContent: "return /*~a*/() => /*~d*/ { }/*~f*/",
newRangeContent: "/*~a*/() => /*~d*/ { }/*~f*/",
});

View file

@ -2,13 +2,11 @@
// @noUnusedLocals: true
// @noUnusedParameters: true
//// function f1() {
//// [|return /*~a*/(/*~b*/x/*~c*/,/*~d*/y/*~e*/)/*~f*/ => /*~g*/x/*~h*/|]
//// }
////[|/*~a*/(/*~b*/x/*~c*/,/*~d*/y/*~e*/)/*~f*/ => /*~g*/x/*~h*/|]
// In a perfect world, /*~c*/ would probably be retained, rather than /*~e*/.
verify.codeFix({
description: "Remove declaration for: 'y'",
index: 0,
newRangeContent: "return /*~a*/(/*~b*/x/*~e*/)/*~f*/ => /*~g*/x/*~h*/",
newRangeContent: "/*~a*/(/*~b*/x/*~e*/)/*~f*/ => /*~g*/x/*~h*/",
});

View file

@ -2,12 +2,10 @@
// @noUnusedLocals: true
// @noUnusedParameters: true
//// function f1() {
//// [|return /*~a*/(/*~b*/x/*~c*/,/*~d*/y/*~e*/)/*~f*/ => /*~g*/y/*~h*/|]
//// }
////[|/*~a*/(/*~b*/x/*~c*/,/*~d*/y/*~e*/)/*~f*/ => /*~g*/y/*~h*/|]
verify.codeFix({
description: "Remove declaration for: 'x'",
index: 0,
newRangeContent: "return /*~a*/(/*~d*/y/*~e*/)/*~f*/ => /*~g*/y/*~h*/",
newRangeContent: "/*~a*/(/*~d*/y/*~e*/)/*~f*/ => /*~g*/y/*~h*/",
});