🤖 Pick PR #58514 (Fixed a regression with reporting u...) into release-5.5 (#58841)

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
This commit is contained in:
TypeScript Bot
2024-06-14 06:51:53 -07:00
committed by GitHub
co-authored by Mateusz Burzyński
parent 602b098c03
commit a20c69e8df
5 changed files with 60 additions and 2 deletions
+5 -2
View File
@@ -11439,7 +11439,7 @@ export function createNameResolver({
}
break;
}
if (isSelfReferenceLocation(location)) {
if (isSelfReferenceLocation(location, lastLocation)) {
lastSelfReferenceLocation = location;
}
lastLocation = location;
@@ -11573,6 +11573,7 @@ export function createNameResolver({
}
type SelfReferenceLocation =
| ParameterDeclaration
| FunctionDeclaration
| ClassDeclaration
| InterfaceDeclaration
@@ -11580,8 +11581,10 @@ export function createNameResolver({
| TypeAliasDeclaration
| ModuleDeclaration;
function isSelfReferenceLocation(node: Node): node is SelfReferenceLocation {
function isSelfReferenceLocation(node: Node, lastLocation: Node | undefined): node is SelfReferenceLocation {
switch (node.kind) {
case SyntaxKind.Parameter:
return !!lastLocation && lastLocation === (node as ParameterDeclaration).name;
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
@@ -0,0 +1,10 @@
noUnusedLocals_potentialPredicateUnusedParam.ts(1,40): error TS6133: 'a' is declared but its value is never read.
==== noUnusedLocals_potentialPredicateUnusedParam.ts (1 errors) ====
function potentialPredicateUnusedParam(a: unknown) {
~
!!! error TS6133: 'a' is declared but its value is never read.
return !!Math.random();
}
@@ -0,0 +1,13 @@
//// [tests/cases/compiler/noUnusedLocals_potentialPredicateUnusedParam.ts] ////
=== noUnusedLocals_potentialPredicateUnusedParam.ts ===
function potentialPredicateUnusedParam(a: unknown) {
>potentialPredicateUnusedParam : Symbol(potentialPredicateUnusedParam, Decl(noUnusedLocals_potentialPredicateUnusedParam.ts, 0, 0))
>a : Symbol(a, Decl(noUnusedLocals_potentialPredicateUnusedParam.ts, 0, 39))
return !!Math.random();
>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
}
@@ -0,0 +1,24 @@
//// [tests/cases/compiler/noUnusedLocals_potentialPredicateUnusedParam.ts] ////
=== noUnusedLocals_potentialPredicateUnusedParam.ts ===
function potentialPredicateUnusedParam(a: unknown) {
>potentialPredicateUnusedParam : (a: unknown) => boolean
> : ^ ^^ ^^^^^^^^^^^^
>a : unknown
> : ^^^^^^^
return !!Math.random();
>!!Math.random() : boolean
> : ^^^^^^^
>!Math.random() : boolean
> : ^^^^^^^
>Math.random() : number
> : ^^^^^^
>Math.random : () => number
> : ^^^^^^
>Math : Math
> : ^^^^
>random : () => number
> : ^^^^^^
}
@@ -0,0 +1,8 @@
// @strict: true
// @noEmit: true
// @noUnusedLocals: true
// @noUnusedParameters: true
function potentialPredicateUnusedParam(a: unknown) {
return !!Math.random();
}