Skip to content

Commit 5de6ac1

Browse files
committed
Simplify test cases
1 parent 3b5689f commit 5de6ac1

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

src/services/codefixes/fixUnusedIdentifier.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ namespace ts.codefix {
123123
case SyntaxKind.Parameter:
124124
const oldFunction = parent.parent;
125125
if (isArrowFunction(oldFunction) && oldFunction.parameters.length === 1) {
126+
// Lambdas with exactly one parameter are special because, after removal, there
127+
// must be an empty parameter list (i.e. `()`) and this won't necessarily be the
128+
// case if the parameter is simply removed (e.g. in `x => 1`).
126129
const newFunction = updateArrowFunction(
127130
oldFunction,
128131
oldFunction.modifiers,

tests/cases/fourslash/unusedParameterInLambda1.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
// @noUnusedLocals: true
44
// @noUnusedParameters: true
5-
//// function f1() {
6-
//// [|return /*~a*/(/*~b*/x/*~c*/:/*~d*/number/*~e*/)/*~f*/ => /*~g*/{/*~h*/}/*~i*/|]
7-
//// }
5+
////[|/*~a*/(/*~b*/x/*~c*/:/*~d*/number/*~e*/)/*~f*/ => /*~g*/{/*~h*/}/*~i*/|]
86

97
// In a perfect world, /*~f*/ and /*~h*/ would probably be retained.
108
verify.codeFix({
119
description: "Remove declaration for: 'x'",
1210
index: 0,
13-
newRangeContent: "return /*~a*/() => /*~g*/ { }/*~i*/",
11+
newRangeContent: "/*~a*/() => /*~g*/ { }/*~i*/",
1412
});

tests/cases/fourslash/unusedParameterInLambda2.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
// @noUnusedLocals: true
44
// @noUnusedParameters: true
5-
//// function f1() {
6-
//// [|return /*~a*/x/*~b*/ /*~c*/=>/*~d*/ {/*~e*/}/*~f*/|]
7-
//// }
5+
////[|/*~a*/x/*~b*/ /*~c*/=>/*~d*/ {/*~e*/}/*~f*/|]
86

97
// In a perfect world, /*~c*/ and /*~e*/ would probably be retained.
108
verify.codeFix({
119
description: "Remove declaration for: 'x'",
1210
index: 0,
13-
newRangeContent: "return /*~a*/() => /*~d*/ { }/*~f*/",
11+
newRangeContent: "/*~a*/() => /*~d*/ { }/*~f*/",
1412
});

tests/cases/fourslash/unusedParameterInLambda3.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
// @noUnusedLocals: true
44
// @noUnusedParameters: true
5-
//// function f1() {
6-
//// [|return /*~a*/(/*~b*/x/*~c*/,/*~d*/y/*~e*/)/*~f*/ => /*~g*/x/*~h*/|]
7-
//// }
5+
////[|/*~a*/(/*~b*/x/*~c*/,/*~d*/y/*~e*/)/*~f*/ => /*~g*/x/*~h*/|]
86

97
// In a perfect world, /*~c*/ would probably be retained, rather than /*~e*/.
108
verify.codeFix({
119
description: "Remove declaration for: 'y'",
1210
index: 0,
13-
newRangeContent: "return /*~a*/(/*~b*/x/*~e*/)/*~f*/ => /*~g*/x/*~h*/",
11+
newRangeContent: "/*~a*/(/*~b*/x/*~e*/)/*~f*/ => /*~g*/x/*~h*/",
1412
});

tests/cases/fourslash/unusedParameterInLambda4.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
// @noUnusedLocals: true
44
// @noUnusedParameters: true
5-
//// function f1() {
6-
//// [|return /*~a*/(/*~b*/x/*~c*/,/*~d*/y/*~e*/)/*~f*/ => /*~g*/y/*~h*/|]
7-
//// }
5+
////[|/*~a*/(/*~b*/x/*~c*/,/*~d*/y/*~e*/)/*~f*/ => /*~g*/y/*~h*/|]
86

97
verify.codeFix({
108
description: "Remove declaration for: 'x'",
119
index: 0,
12-
newRangeContent: "return /*~a*/(/*~d*/y/*~e*/)/*~f*/ => /*~g*/y/*~h*/",
10+
newRangeContent: "/*~a*/(/*~d*/y/*~e*/)/*~f*/ => /*~g*/y/*~h*/",
1311
});

0 commit comments

Comments
 (0)