Don't consider 'typeof a' as using 'a' (#28528)
* Don't consider 'typeof a' as using 'a' * Also handle markPropertyAsReferenced * Use isInTypeQuery
This commit is contained in:
parent
b059135c51
commit
0c4ceeec24
|
@ -1478,7 +1478,7 @@ namespace ts {
|
||||||
// We just climbed up parents looking for the name, meaning that we started in a descendant node of `lastLocation`.
|
// We just climbed up parents looking for the name, meaning that we started in a descendant node of `lastLocation`.
|
||||||
// If `result === lastSelfReferenceLocation.symbol`, that means that we are somewhere inside `lastSelfReferenceLocation` looking up a name, and resolving to `lastLocation` itself.
|
// If `result === lastSelfReferenceLocation.symbol`, that means that we are somewhere inside `lastSelfReferenceLocation` looking up a name, and resolving to `lastLocation` itself.
|
||||||
// That means that this is a self-reference of `lastLocation`, and shouldn't count this when considering whether `lastLocation` is used.
|
// That means that this is a self-reference of `lastLocation`, and shouldn't count this when considering whether `lastLocation` is used.
|
||||||
if (isUse && result && (!lastSelfReferenceLocation || result !== lastSelfReferenceLocation.symbol)) {
|
if (isUse && result && (!lastSelfReferenceLocation || result !== lastSelfReferenceLocation.symbol) && !isInTypeQuery(originalLocation!)) {
|
||||||
result.isReferenced! |= meaning;
|
result.isReferenced! |= meaning;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19022,7 +19022,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
function markPropertyAsReferenced(prop: Symbol, nodeForCheckWriteOnly: Node | undefined, isThisAccess: boolean) {
|
function markPropertyAsReferenced(prop: Symbol, nodeForCheckWriteOnly: Node | undefined, isThisAccess: boolean) {
|
||||||
if (!prop || !(prop.flags & SymbolFlags.ClassMember) || !prop.valueDeclaration || !hasModifier(prop.valueDeclaration, ModifierFlags.Private)) {
|
if (nodeForCheckWriteOnly && isInTypeQuery(nodeForCheckWriteOnly) || !prop || !(prop.flags & SymbolFlags.ClassMember) || !prop.valueDeclaration || !hasModifier(prop.valueDeclaration, ModifierFlags.Private)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (nodeForCheckWriteOnly && isWriteOnlyAccess(nodeForCheckWriteOnly) && !(prop.flags & SymbolFlags.SetAccessor && !(prop.flags & SymbolFlags.GetAccessor))) {
|
if (nodeForCheckWriteOnly && isWriteOnlyAccess(nodeForCheckWriteOnly) && !(prop.flags & SymbolFlags.SetAccessor && !(prop.flags & SymbolFlags.GetAccessor))) {
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
tests/cases/compiler/unusedParameterUsedInTypeOf.ts(1,14): error TS6133: 'a' is declared but its value is never read.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/compiler/unusedParameterUsedInTypeOf.ts (1 errors) ====
|
||||||
|
function f1 (a: number, b: typeof a) {
|
||||||
|
~
|
||||||
|
!!! error TS6133: 'a' is declared but its value is never read.
|
||||||
|
return b;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
tests/cases/compiler/unusedPropertyUsedInTypeOf.ts(2,29): error TS6133: 'x' is declared but its value is never read.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/compiler/unusedPropertyUsedInTypeOf.ts (1 errors) ====
|
||||||
|
class C {
|
||||||
|
private static readonly x: number;
|
||||||
|
~
|
||||||
|
!!! error TS6133: 'x' is declared but its value is never read.
|
||||||
|
m(p: typeof C.x) { return p; }
|
||||||
|
}
|
||||||
|
|
14
tests/baselines/reference/unusedPropertyUsedInTypeOf.js
Normal file
14
tests/baselines/reference/unusedPropertyUsedInTypeOf.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
//// [unusedPropertyUsedInTypeOf.ts]
|
||||||
|
class C {
|
||||||
|
private static readonly x: number;
|
||||||
|
m(p: typeof C.x) { return p; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//// [unusedPropertyUsedInTypeOf.js]
|
||||||
|
var C = /** @class */ (function () {
|
||||||
|
function C() {
|
||||||
|
}
|
||||||
|
C.prototype.m = function (p) { return p; };
|
||||||
|
return C;
|
||||||
|
}());
|
16
tests/baselines/reference/unusedPropertyUsedInTypeOf.symbols
Normal file
16
tests/baselines/reference/unusedPropertyUsedInTypeOf.symbols
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
=== tests/cases/compiler/unusedPropertyUsedInTypeOf.ts ===
|
||||||
|
class C {
|
||||||
|
>C : Symbol(C, Decl(unusedPropertyUsedInTypeOf.ts, 0, 0))
|
||||||
|
|
||||||
|
private static readonly x: number;
|
||||||
|
>x : Symbol(C.x, Decl(unusedPropertyUsedInTypeOf.ts, 0, 9))
|
||||||
|
|
||||||
|
m(p: typeof C.x) { return p; }
|
||||||
|
>m : Symbol(C.m, Decl(unusedPropertyUsedInTypeOf.ts, 1, 38))
|
||||||
|
>p : Symbol(p, Decl(unusedPropertyUsedInTypeOf.ts, 2, 6))
|
||||||
|
>C.x : Symbol(C.x, Decl(unusedPropertyUsedInTypeOf.ts, 0, 9))
|
||||||
|
>C : Symbol(C, Decl(unusedPropertyUsedInTypeOf.ts, 0, 0))
|
||||||
|
>x : Symbol(C.x, Decl(unusedPropertyUsedInTypeOf.ts, 0, 9))
|
||||||
|
>p : Symbol(p, Decl(unusedPropertyUsedInTypeOf.ts, 2, 6))
|
||||||
|
}
|
||||||
|
|
16
tests/baselines/reference/unusedPropertyUsedInTypeOf.types
Normal file
16
tests/baselines/reference/unusedPropertyUsedInTypeOf.types
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
=== tests/cases/compiler/unusedPropertyUsedInTypeOf.ts ===
|
||||||
|
class C {
|
||||||
|
>C : C
|
||||||
|
|
||||||
|
private static readonly x: number;
|
||||||
|
>x : number
|
||||||
|
|
||||||
|
m(p: typeof C.x) { return p; }
|
||||||
|
>m : (p: number) => number
|
||||||
|
>p : number
|
||||||
|
>C.x : number
|
||||||
|
>C : typeof C
|
||||||
|
>x : number
|
||||||
|
>p : number
|
||||||
|
}
|
||||||
|
|
7
tests/cases/compiler/unusedPropertyUsedInTypeOf.ts
Normal file
7
tests/cases/compiler/unusedPropertyUsedInTypeOf.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
// @noUnusedLocals:true
|
||||||
|
// @noUnusedParameters:true
|
||||||
|
|
||||||
|
class C {
|
||||||
|
private static readonly x: number;
|
||||||
|
m(p: typeof C.x) { return p; }
|
||||||
|
}
|
Loading…
Reference in a new issue