Fix unused diagnostic for rename-destructuring { a: b }
(#24145)
This commit is contained in:
parent
d4a3c9c61a
commit
2200c94a43
6 changed files with 30 additions and 14 deletions
|
@ -22619,11 +22619,11 @@ namespace ts {
|
||||||
const kind = tryGetRootParameterDeclaration(bindingPattern.parent) ? UnusedKind.Parameter : UnusedKind.Local;
|
const kind = tryGetRootParameterDeclaration(bindingPattern.parent) ? UnusedKind.Parameter : UnusedKind.Local;
|
||||||
if (!bindingPattern.elements.every(e => contains(bindingElements, e))) {
|
if (!bindingPattern.elements.every(e => contains(bindingElements, e))) {
|
||||||
for (const e of bindingElements) {
|
for (const e of bindingElements) {
|
||||||
addDiagnostic(kind, createDiagnosticForNode(e, Diagnostics._0_is_declared_but_its_value_is_never_read, getBindingElementNameText(e)));
|
addDiagnostic(kind, createDiagnosticForNode(e, Diagnostics._0_is_declared_but_its_value_is_never_read, idText(cast(e.name, isIdentifier))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (bindingElements.length === 1) {
|
else if (bindingElements.length === 1) {
|
||||||
addDiagnostic(kind, createDiagnosticForNode(bindingPattern, Diagnostics._0_is_declared_but_its_value_is_never_read, getBindingElementNameText(first(bindingElements))));
|
addDiagnostic(kind, createDiagnosticForNode(bindingPattern, Diagnostics._0_is_declared_but_its_value_is_never_read, idText(cast(first(bindingElements).name, isIdentifier))));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
addDiagnostic(kind, createDiagnosticForNode(bindingPattern, Diagnostics.All_destructured_elements_are_unused));
|
addDiagnostic(kind, createDiagnosticForNode(bindingPattern, Diagnostics.All_destructured_elements_are_unused));
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
tests/cases/compiler/unusedDestructuring.ts(3,7): error TS6198: All destructured elements are unused.
|
tests/cases/compiler/unusedDestructuring.ts(3,7): error TS6198: All destructured elements are unused.
|
||||||
tests/cases/compiler/unusedDestructuring.ts(4,9): error TS6133: 'c' is declared but its value is never read.
|
tests/cases/compiler/unusedDestructuring.ts(4,9): error TS6133: 'c' is declared but its value is never read.
|
||||||
tests/cases/compiler/unusedDestructuring.ts(6,7): error TS6133: 'e' is declared but its value is never read.
|
tests/cases/compiler/unusedDestructuring.ts(6,7): error TS6133: 'e' is declared but its value is never read.
|
||||||
tests/cases/compiler/unusedDestructuring.ts(8,1): error TS6133: 'f' is declared but its value is never read.
|
tests/cases/compiler/unusedDestructuring.ts(7,7): error TS6133: 'g' is declared but its value is never read.
|
||||||
tests/cases/compiler/unusedDestructuring.ts(8,12): error TS6198: All destructured elements are unused.
|
tests/cases/compiler/unusedDestructuring.ts(9,1): error TS6133: 'f' is declared but its value is never read.
|
||||||
tests/cases/compiler/unusedDestructuring.ts(8,24): error TS6133: 'c' is declared but its value is never read.
|
tests/cases/compiler/unusedDestructuring.ts(9,12): error TS6198: All destructured elements are unused.
|
||||||
tests/cases/compiler/unusedDestructuring.ts(8,32): error TS6133: 'e' is declared but its value is never read.
|
tests/cases/compiler/unusedDestructuring.ts(9,24): error TS6133: 'c' is declared but its value is never read.
|
||||||
|
tests/cases/compiler/unusedDestructuring.ts(9,32): error TS6133: 'e' is declared but its value is never read.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/compiler/unusedDestructuring.ts (7 errors) ====
|
==== tests/cases/compiler/unusedDestructuring.ts (8 errors) ====
|
||||||
export {};
|
export {};
|
||||||
declare const o: any;
|
declare const o: any;
|
||||||
const { a, b } = o;
|
const { a, b } = o;
|
||||||
|
@ -20,6 +21,9 @@ tests/cases/compiler/unusedDestructuring.ts(8,32): error TS6133: 'e' is declared
|
||||||
const { e } = o;
|
const { e } = o;
|
||||||
~~~~~
|
~~~~~
|
||||||
!!! error TS6133: 'e' is declared but its value is never read.
|
!!! error TS6133: 'e' is declared but its value is never read.
|
||||||
|
const { f: g } = o;
|
||||||
|
~~~~~~~~
|
||||||
|
!!! error TS6133: 'g' is declared but its value is never read.
|
||||||
|
|
||||||
function f({ a, b }, { c, d }, { e }) {
|
function f({ a, b }, { c, d }, { e }) {
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
|
|
@ -5,6 +5,7 @@ const { a, b } = o;
|
||||||
const { c, d } = o;
|
const { c, d } = o;
|
||||||
d;
|
d;
|
||||||
const { e } = o;
|
const { e } = o;
|
||||||
|
const { f: g } = o;
|
||||||
|
|
||||||
function f({ a, b }, { c, d }, { e }) {
|
function f({ a, b }, { c, d }, { e }) {
|
||||||
d;
|
d;
|
||||||
|
@ -18,6 +19,7 @@ var a = o.a, b = o.b;
|
||||||
var c = o.c, d = o.d;
|
var c = o.c, d = o.d;
|
||||||
d;
|
d;
|
||||||
var e = o.e;
|
var e = o.e;
|
||||||
|
var g = o.f;
|
||||||
function f(_a, _b, _c) {
|
function f(_a, _b, _c) {
|
||||||
var a = _a.a, b = _a.b;
|
var a = _a.a, b = _a.b;
|
||||||
var c = _b.c, d = _b.d;
|
var c = _b.c, d = _b.d;
|
||||||
|
|
|
@ -20,15 +20,19 @@ const { e } = o;
|
||||||
>e : Symbol(e, Decl(unusedDestructuring.ts, 5, 7))
|
>e : Symbol(e, Decl(unusedDestructuring.ts, 5, 7))
|
||||||
>o : Symbol(o, Decl(unusedDestructuring.ts, 1, 13))
|
>o : Symbol(o, Decl(unusedDestructuring.ts, 1, 13))
|
||||||
|
|
||||||
|
const { f: g } = o;
|
||||||
|
>g : Symbol(g, Decl(unusedDestructuring.ts, 6, 7))
|
||||||
|
>o : Symbol(o, Decl(unusedDestructuring.ts, 1, 13))
|
||||||
|
|
||||||
function f({ a, b }, { c, d }, { e }) {
|
function f({ a, b }, { c, d }, { e }) {
|
||||||
>f : Symbol(f, Decl(unusedDestructuring.ts, 5, 16))
|
>f : Symbol(f, Decl(unusedDestructuring.ts, 6, 19))
|
||||||
>a : Symbol(a, Decl(unusedDestructuring.ts, 7, 12))
|
>a : Symbol(a, Decl(unusedDestructuring.ts, 8, 12))
|
||||||
>b : Symbol(b, Decl(unusedDestructuring.ts, 7, 15))
|
>b : Symbol(b, Decl(unusedDestructuring.ts, 8, 15))
|
||||||
>c : Symbol(c, Decl(unusedDestructuring.ts, 7, 22))
|
>c : Symbol(c, Decl(unusedDestructuring.ts, 8, 22))
|
||||||
>d : Symbol(d, Decl(unusedDestructuring.ts, 7, 25))
|
>d : Symbol(d, Decl(unusedDestructuring.ts, 8, 25))
|
||||||
>e : Symbol(e, Decl(unusedDestructuring.ts, 7, 32))
|
>e : Symbol(e, Decl(unusedDestructuring.ts, 8, 32))
|
||||||
|
|
||||||
d;
|
d;
|
||||||
>d : Symbol(d, Decl(unusedDestructuring.ts, 7, 25))
|
>d : Symbol(d, Decl(unusedDestructuring.ts, 8, 25))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,11 @@ const { e } = o;
|
||||||
>e : any
|
>e : any
|
||||||
>o : any
|
>o : any
|
||||||
|
|
||||||
|
const { f: g } = o;
|
||||||
|
>f : any
|
||||||
|
>g : any
|
||||||
|
>o : any
|
||||||
|
|
||||||
function f({ a, b }, { c, d }, { e }) {
|
function f({ a, b }, { c, d }, { e }) {
|
||||||
>f : ({ a, b }: { a: any; b: any; }, { c, d }: { c: any; d: any; }, { e }: { e: any; }) => void
|
>f : ({ a, b }: { a: any; b: any; }, { c, d }: { c: any; d: any; }, { e }: { e: any; }) => void
|
||||||
>a : any
|
>a : any
|
||||||
|
|
|
@ -7,6 +7,7 @@ const { a, b } = o;
|
||||||
const { c, d } = o;
|
const { c, d } = o;
|
||||||
d;
|
d;
|
||||||
const { e } = o;
|
const { e } = o;
|
||||||
|
const { f: g } = o;
|
||||||
|
|
||||||
function f({ a, b }, { c, d }, { e }) {
|
function f({ a, b }, { c, d }, { e }) {
|
||||||
d;
|
d;
|
||||||
|
|
Loading…
Reference in a new issue