From 1f34a4e25fe4be2d544661b6ae8a619487af0c59 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 26 Nov 2018 14:45:19 -0800 Subject: [PATCH] Revert "Don't consider 'typeof a' as using 'a' (#28528)" This reverts commit 0c4ceeec24f16f87e75386355c86ac38612a1175. --- src/compiler/checker.ts | 4 ++-- .../unusedParameterUsedInTypeOf.errors.txt | 9 --------- .../unusedPropertyUsedInTypeOf.errors.txt | 11 ----------- .../reference/unusedPropertyUsedInTypeOf.js | 14 -------------- .../reference/unusedPropertyUsedInTypeOf.symbols | 16 ---------------- .../reference/unusedPropertyUsedInTypeOf.types | 16 ---------------- .../cases/compiler/unusedPropertyUsedInTypeOf.ts | 7 ------- 7 files changed, 2 insertions(+), 75 deletions(-) delete mode 100644 tests/baselines/reference/unusedParameterUsedInTypeOf.errors.txt delete mode 100644 tests/baselines/reference/unusedPropertyUsedInTypeOf.errors.txt delete mode 100644 tests/baselines/reference/unusedPropertyUsedInTypeOf.js delete mode 100644 tests/baselines/reference/unusedPropertyUsedInTypeOf.symbols delete mode 100644 tests/baselines/reference/unusedPropertyUsedInTypeOf.types delete mode 100644 tests/cases/compiler/unusedPropertyUsedInTypeOf.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 118af6486ed..341ba540bfe 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1483,7 +1483,7 @@ namespace ts { // 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. // 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) && !isInTypeQuery(originalLocation!)) { + if (isUse && result && (!lastSelfReferenceLocation || result !== lastSelfReferenceLocation.symbol)) { result.isReferenced! |= meaning; } @@ -19055,7 +19055,7 @@ namespace ts { } function markPropertyAsReferenced(prop: Symbol, nodeForCheckWriteOnly: Node | undefined, isThisAccess: boolean) { - if (nodeForCheckWriteOnly && isInTypeQuery(nodeForCheckWriteOnly) || !(prop.flags & SymbolFlags.ClassMember) || !prop.valueDeclaration || !hasModifier(prop.valueDeclaration, ModifierFlags.Private)) { + if (!prop || !(prop.flags & SymbolFlags.ClassMember) || !prop.valueDeclaration || !hasModifier(prop.valueDeclaration, ModifierFlags.Private)) { return; } if (nodeForCheckWriteOnly && isWriteOnlyAccess(nodeForCheckWriteOnly) && !(prop.flags & SymbolFlags.SetAccessor && !(prop.flags & SymbolFlags.GetAccessor))) { diff --git a/tests/baselines/reference/unusedParameterUsedInTypeOf.errors.txt b/tests/baselines/reference/unusedParameterUsedInTypeOf.errors.txt deleted file mode 100644 index a2a30badc4a..00000000000 --- a/tests/baselines/reference/unusedParameterUsedInTypeOf.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -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; - } \ No newline at end of file diff --git a/tests/baselines/reference/unusedPropertyUsedInTypeOf.errors.txt b/tests/baselines/reference/unusedPropertyUsedInTypeOf.errors.txt deleted file mode 100644 index 60657d9c8c9..00000000000 --- a/tests/baselines/reference/unusedPropertyUsedInTypeOf.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -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; } - } - \ No newline at end of file diff --git a/tests/baselines/reference/unusedPropertyUsedInTypeOf.js b/tests/baselines/reference/unusedPropertyUsedInTypeOf.js deleted file mode 100644 index 98a1e9f0029..00000000000 --- a/tests/baselines/reference/unusedPropertyUsedInTypeOf.js +++ /dev/null @@ -1,14 +0,0 @@ -//// [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; -}()); diff --git a/tests/baselines/reference/unusedPropertyUsedInTypeOf.symbols b/tests/baselines/reference/unusedPropertyUsedInTypeOf.symbols deleted file mode 100644 index 9715c3fa11f..00000000000 --- a/tests/baselines/reference/unusedPropertyUsedInTypeOf.symbols +++ /dev/null @@ -1,16 +0,0 @@ -=== 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)) -} - diff --git a/tests/baselines/reference/unusedPropertyUsedInTypeOf.types b/tests/baselines/reference/unusedPropertyUsedInTypeOf.types deleted file mode 100644 index 12b40eb5ff6..00000000000 --- a/tests/baselines/reference/unusedPropertyUsedInTypeOf.types +++ /dev/null @@ -1,16 +0,0 @@ -=== 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 -} - diff --git a/tests/cases/compiler/unusedPropertyUsedInTypeOf.ts b/tests/cases/compiler/unusedPropertyUsedInTypeOf.ts deleted file mode 100644 index 41c685e4b06..00000000000 --- a/tests/cases/compiler/unusedPropertyUsedInTypeOf.ts +++ /dev/null @@ -1,7 +0,0 @@ -// @noUnusedLocals:true -// @noUnusedParameters:true - -class C { - private static readonly x: number; - m(p: typeof C.x) { return p; } -}