Skip to content

Commit 2200c94

Browse files
author
Andy
authored
Fix unused diagnostic for rename-destructuring { a: b } (microsoft#24145)
1 parent d4a3c9c commit 2200c94

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22619,11 +22619,11 @@ namespace ts {
2261922619
const kind = tryGetRootParameterDeclaration(bindingPattern.parent) ? UnusedKind.Parameter : UnusedKind.Local;
2262022620
if (!bindingPattern.elements.every(e => contains(bindingElements, e))) {
2262122621
for (const e of bindingElements) {
22622-
addDiagnostic(kind, createDiagnosticForNode(e, Diagnostics._0_is_declared_but_its_value_is_never_read, getBindingElementNameText(e)));
22622+
addDiagnostic(kind, createDiagnosticForNode(e, Diagnostics._0_is_declared_but_its_value_is_never_read, idText(cast(e.name, isIdentifier))));
2262322623
}
2262422624
}
2262522625
else if (bindingElements.length === 1) {
22626-
addDiagnostic(kind, createDiagnosticForNode(bindingPattern, Diagnostics._0_is_declared_but_its_value_is_never_read, getBindingElementNameText(first(bindingElements))));
22626+
addDiagnostic(kind, createDiagnosticForNode(bindingPattern, Diagnostics._0_is_declared_but_its_value_is_never_read, idText(cast(first(bindingElements).name, isIdentifier))));
2262722627
}
2262822628
else {
2262922629
addDiagnostic(kind, createDiagnosticForNode(bindingPattern, Diagnostics.All_destructured_elements_are_unused));

tests/baselines/reference/unusedDestructuring.errors.txt

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
tests/cases/compiler/unusedDestructuring.ts(3,7): error TS6198: All destructured elements are unused.
22
tests/cases/compiler/unusedDestructuring.ts(4,9): error TS6133: 'c' is declared but its value is never read.
33
tests/cases/compiler/unusedDestructuring.ts(6,7): error TS6133: 'e' is declared but its value is never read.
4-
tests/cases/compiler/unusedDestructuring.ts(8,1): error TS6133: 'f' is declared but its value is never read.
5-
tests/cases/compiler/unusedDestructuring.ts(8,12): error TS6198: All destructured elements are unused.
6-
tests/cases/compiler/unusedDestructuring.ts(8,24): error TS6133: 'c' is declared but its value is never read.
7-
tests/cases/compiler/unusedDestructuring.ts(8,32): error TS6133: 'e' is declared but its value is never read.
4+
tests/cases/compiler/unusedDestructuring.ts(7,7): error TS6133: 'g' is declared but its value is never read.
5+
tests/cases/compiler/unusedDestructuring.ts(9,1): error TS6133: 'f' is declared but its value is never read.
6+
tests/cases/compiler/unusedDestructuring.ts(9,12): error TS6198: All destructured elements are unused.
7+
tests/cases/compiler/unusedDestructuring.ts(9,24): error TS6133: 'c' is declared but its value is never read.
8+
tests/cases/compiler/unusedDestructuring.ts(9,32): error TS6133: 'e' is declared but its value is never read.
89

910

10-
==== tests/cases/compiler/unusedDestructuring.ts (7 errors) ====
11+
==== tests/cases/compiler/unusedDestructuring.ts (8 errors) ====
1112
export {};
1213
declare const o: any;
1314
const { a, b } = o;
@@ -20,6 +21,9 @@ tests/cases/compiler/unusedDestructuring.ts(8,32): error TS6133: 'e' is declared
2021
const { e } = o;
2122
~~~~~
2223
!!! error TS6133: 'e' is declared but its value is never read.
24+
const { f: g } = o;
25+
~~~~~~~~
26+
!!! error TS6133: 'g' is declared but its value is never read.
2327

2428
function f({ a, b }, { c, d }, { e }) {
2529
~~~~~~~~~~

tests/baselines/reference/unusedDestructuring.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { a, b } = o;
55
const { c, d } = o;
66
d;
77
const { e } = o;
8+
const { f: g } = o;
89

910
function f({ a, b }, { c, d }, { e }) {
1011
d;
@@ -18,6 +19,7 @@ var a = o.a, b = o.b;
1819
var c = o.c, d = o.d;
1920
d;
2021
var e = o.e;
22+
var g = o.f;
2123
function f(_a, _b, _c) {
2224
var a = _a.a, b = _a.b;
2325
var c = _b.c, d = _b.d;

tests/baselines/reference/unusedDestructuring.symbols

+11-7
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ const { e } = o;
2020
>e : Symbol(e, Decl(unusedDestructuring.ts, 5, 7))
2121
>o : Symbol(o, Decl(unusedDestructuring.ts, 1, 13))
2222

23+
const { f: g } = o;
24+
>g : Symbol(g, Decl(unusedDestructuring.ts, 6, 7))
25+
>o : Symbol(o, Decl(unusedDestructuring.ts, 1, 13))
26+
2327
function f({ a, b }, { c, d }, { e }) {
24-
>f : Symbol(f, Decl(unusedDestructuring.ts, 5, 16))
25-
>a : Symbol(a, Decl(unusedDestructuring.ts, 7, 12))
26-
>b : Symbol(b, Decl(unusedDestructuring.ts, 7, 15))
27-
>c : Symbol(c, Decl(unusedDestructuring.ts, 7, 22))
28-
>d : Symbol(d, Decl(unusedDestructuring.ts, 7, 25))
29-
>e : Symbol(e, Decl(unusedDestructuring.ts, 7, 32))
28+
>f : Symbol(f, Decl(unusedDestructuring.ts, 6, 19))
29+
>a : Symbol(a, Decl(unusedDestructuring.ts, 8, 12))
30+
>b : Symbol(b, Decl(unusedDestructuring.ts, 8, 15))
31+
>c : Symbol(c, Decl(unusedDestructuring.ts, 8, 22))
32+
>d : Symbol(d, Decl(unusedDestructuring.ts, 8, 25))
33+
>e : Symbol(e, Decl(unusedDestructuring.ts, 8, 32))
3034

3135
d;
32-
>d : Symbol(d, Decl(unusedDestructuring.ts, 7, 25))
36+
>d : Symbol(d, Decl(unusedDestructuring.ts, 8, 25))
3337
}
3438

tests/baselines/reference/unusedDestructuring.types

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const { e } = o;
2020
>e : any
2121
>o : any
2222

23+
const { f: g } = o;
24+
>f : any
25+
>g : any
26+
>o : any
27+
2328
function f({ a, b }, { c, d }, { e }) {
2429
>f : ({ a, b }: { a: any; b: any; }, { c, d }: { c: any; d: any; }, { e }: { e: any; }) => void
2530
>a : any

tests/cases/compiler/unusedDestructuring.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { a, b } = o;
77
const { c, d } = o;
88
d;
99
const { e } = o;
10+
const { f: g } = o;
1011

1112
function f({ a, b }, { c, d }, { e }) {
1213
d;

0 commit comments

Comments
 (0)