Skip to content

Commit a20c69e

Browse files
TypeScript BotAndarist
TypeScript Bot
andauthored
🤖 Pick PR #58514 (Fixed a regression with reporting u...) into release-5.5 (#58841)
Co-authored-by: Mateusz BurzyÅ„ski <[email protected]>
1 parent 602b098 commit a20c69e

5 files changed

+60
-2
lines changed

Diff for: ‎src/compiler/utilities.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -11439,7 +11439,7 @@ export function createNameResolver({
1143911439
}
1144011440
break;
1144111441
}
11442-
if (isSelfReferenceLocation(location)) {
11442+
if (isSelfReferenceLocation(location, lastLocation)) {
1144311443
lastSelfReferenceLocation = location;
1144411444
}
1144511445
lastLocation = location;
@@ -11573,15 +11573,18 @@ export function createNameResolver({
1157311573
}
1157411574

1157511575
type SelfReferenceLocation =
11576+
| ParameterDeclaration
1157611577
| FunctionDeclaration
1157711578
| ClassDeclaration
1157811579
| InterfaceDeclaration
1157911580
| EnumDeclaration
1158011581
| TypeAliasDeclaration
1158111582
| ModuleDeclaration;
1158211583

11583-
function isSelfReferenceLocation(node: Node): node is SelfReferenceLocation {
11584+
function isSelfReferenceLocation(node: Node, lastLocation: Node | undefined): node is SelfReferenceLocation {
1158411585
switch (node.kind) {
11586+
case SyntaxKind.Parameter:
11587+
return !!lastLocation && lastLocation === (node as ParameterDeclaration).name;
1158511588
case SyntaxKind.FunctionDeclaration:
1158611589
case SyntaxKind.ClassDeclaration:
1158711590
case SyntaxKind.InterfaceDeclaration:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
noUnusedLocals_potentialPredicateUnusedParam.ts(1,40): error TS6133: 'a' is declared but its value is never read.
2+
3+
4+
==== noUnusedLocals_potentialPredicateUnusedParam.ts (1 errors) ====
5+
function potentialPredicateUnusedParam(a: unknown) {
6+
~
7+
!!! error TS6133: 'a' is declared but its value is never read.
8+
return !!Math.random();
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/compiler/noUnusedLocals_potentialPredicateUnusedParam.ts] ////
2+
3+
=== noUnusedLocals_potentialPredicateUnusedParam.ts ===
4+
function potentialPredicateUnusedParam(a: unknown) {
5+
>potentialPredicateUnusedParam : Symbol(potentialPredicateUnusedParam, Decl(noUnusedLocals_potentialPredicateUnusedParam.ts, 0, 0))
6+
>a : Symbol(a, Decl(noUnusedLocals_potentialPredicateUnusedParam.ts, 0, 39))
7+
8+
return !!Math.random();
9+
>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
10+
>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
11+
>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
12+
}
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/compiler/noUnusedLocals_potentialPredicateUnusedParam.ts] ////
2+
3+
=== noUnusedLocals_potentialPredicateUnusedParam.ts ===
4+
function potentialPredicateUnusedParam(a: unknown) {
5+
>potentialPredicateUnusedParam : (a: unknown) => boolean
6+
> : ^ ^^ ^^^^^^^^^^^^
7+
>a : unknown
8+
> : ^^^^^^^
9+
10+
return !!Math.random();
11+
>!!Math.random() : boolean
12+
> : ^^^^^^^
13+
>!Math.random() : boolean
14+
> : ^^^^^^^
15+
>Math.random() : number
16+
> : ^^^^^^
17+
>Math.random : () => number
18+
> : ^^^^^^
19+
>Math : Math
20+
> : ^^^^
21+
>random : () => number
22+
> : ^^^^^^
23+
}
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @strict: true
2+
// @noEmit: true
3+
// @noUnusedLocals: true
4+
// @noUnusedParameters: true
5+
6+
function potentialPredicateUnusedParam(a: unknown) {
7+
return !!Math.random();
8+
}

0 commit comments

Comments
 (0)