From 859466f5dd8469ce6934797c741e9aba65b1b9a0 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 3 Nov 2020 10:48:36 +0200 Subject: [PATCH] feat(31388): allow binding elements starting with an underscore --- src/compiler/checker.ts | 15 +- ...sWithUnderscoreInBindingElement.errors.txt | 145 +++++++ ...VariablesWithUnderscoreInBindingElement.js | 136 +++++++ ...blesWithUnderscoreInBindingElement.symbols | 279 +++++++++++++ ...iablesWithUnderscoreInBindingElement.types | 378 ++++++++++++++++++ ...iablesWithUnderscoreInForOfLoop.errors.txt | 56 +++ ...nusedVariablesWithUnderscoreInForOfLoop.js | 43 +- ...VariablesWithUnderscoreInForOfLoop.symbols | 37 +- ...edVariablesWithUnderscoreInForOfLoop.types | 67 +++- ...ablesWithUnderscoreInForOfLoop1.errors.txt | 23 -- ...usedVariablesWithUnderscoreInForOfLoop1.js | 22 - ...ariablesWithUnderscoreInForOfLoop1.symbols | 17 - ...dVariablesWithUnderscoreInForOfLoop1.types | 29 -- ...VariablesWithUnderscoreInBindingElement.ts | 90 +++++ ...nusedVariablesWithUnderscoreInForOfLoop.ts | 21 +- ...usedVariablesWithUnderscoreInForOfLoop1.ts | 9 - 16 files changed, 1253 insertions(+), 114 deletions(-) create mode 100644 tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.errors.txt create mode 100644 tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.js create mode 100644 tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.symbols create mode 100644 tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.types create mode 100644 tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.errors.txt delete mode 100644 tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.errors.txt delete mode 100644 tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.js delete mode 100644 tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.symbols delete mode 100644 tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.types create mode 100644 tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts delete mode 100644 tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop1.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a220e79dc44a5..a79e835e54ee2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33362,13 +33362,16 @@ namespace ts { } function isValidUnusedLocalDeclaration(declaration: Declaration): boolean { - if (isBindingElement(declaration) && isIdentifierThatStartsWithUnderscore(declaration.name)) { - return !!findAncestor(declaration.parent, ancestor => - isArrayBindingPattern(ancestor) || isVariableDeclaration(ancestor) || isVariableDeclarationList(ancestor) ? false : - isForOfStatement(ancestor) ? true : "quit" - ); + if (isBindingElement(declaration)) { + if (isObjectBindingPattern(declaration.parent)) { + /** + * ignore starts with underscore names _ + * const { a: _a } = { a: 1 } + */ + return !!(declaration.propertyName && isIdentifierThatStartsWithUnderscore(declaration.name)); + } + return isIdentifierThatStartsWithUnderscore(declaration.name); } - return isAmbientModule(declaration) || (isVariableDeclaration(declaration) && isForInOrOfStatement(declaration.parent.parent) || isImportedDeclaration(declaration)) && isIdentifierThatStartsWithUnderscore(declaration.name!); } diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.errors.txt b/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.errors.txt new file mode 100644 index 0000000000000..58eccaee1e8f5 --- /dev/null +++ b/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.errors.txt @@ -0,0 +1,145 @@ +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(12,17): error TS6133: 'b1' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(13,12): error TS6133: 'a2' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(14,12): error TS6133: 'a3' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(14,16): error TS6133: 'b3' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(23,12): error TS6133: 'a3' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(23,18): error TS6133: 'b3' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(23,22): error TS6133: 'c3' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(23,28): error TS6133: 'd3' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(23,32): error TS6133: 'e3' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(37,22): error TS6133: 'b1' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(38,13): error TS6133: 'a2' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(39,11): error TS6198: All destructured elements are unused. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(68,9): error TS6133: 'a3' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(70,18): error TS6198: All destructured elements are unused. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(74,9): error TS6133: 'c3' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(75,9): error TS6133: 'd3' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts(81,11): error TS6198: All destructured elements are unused. + + +==== tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts (17 errors) ==== + function t1() { + const [_a1, b1] = [1, 2]; + console.log(b1); + + const [a2, _b2] = [1, 2]; + console.log(a2); + + const [_a3, _b3] = [1, 2]; + } + + function t2() { + const [_a1, b1] = [1, 2]; + ~~ +!!! error TS6133: 'b1' is declared but its value is never read. + const [a2, _b2] = [1, 2]; + ~~ +!!! error TS6133: 'a2' is declared but its value is never read. + const [a3, b3] = [1, 2]; + ~~ +!!! error TS6133: 'a3' is declared but its value is never read. + ~~ +!!! error TS6133: 'b3' is declared but its value is never read. + } + + function t3() { + const [_a1, [[_b1, c1]], d1, _e1] = [1, [[2, 3]], 4, 5]; + console.log(c1, d1); + + const [_a2, [[_b2, _c2]], _d2, _e2] = [1, [[2, 3]], 4, 5]; + + const [a3, [[b3, c3]], d3, e3] = [1, [[2, 3]], 4, 5]; + ~~ +!!! error TS6133: 'a3' is declared but its value is never read. + ~~ +!!! error TS6133: 'b3' is declared but its value is never read. + ~~ +!!! error TS6133: 'c3' is declared but its value is never read. + ~~ +!!! error TS6133: 'd3' is declared but its value is never read. + ~~ +!!! error TS6133: 'e3' is declared but its value is never read. + } + + function t4() { + const { a1: _a1, b1 } = { a1: 1, b1: 1 }; + console.log(b1); + + const { a2, b2: _b2 } = { a2: 1, b2: 1 }; + console.log(a2); + + const { a3: _a3, b3: _b3 } = { a3: 1, b3: 1 }; + } + + function t5() { + const { a1: _a1, b1 } = { a1: 1, b1: 1 }; + ~~ +!!! error TS6133: 'b1' is declared but its value is never read. + const { a2, b2: _b2 } = { a2: 1, b2: 1 }; + ~~ +!!! error TS6133: 'a2' is declared but its value is never read. + const { a3, b3 } = { a3: 1, b3: 1 }; + ~~~~~~~~~~ +!!! error TS6198: All destructured elements are unused. + } + + function t6() { + const { + a1: _a1, + b1: { + b11: { + b111: _b111, + b112 + } + }, + c1, + d1: _d1 + } = { a1: 1, b1: { b11: { b111: 1, b112: 1 } }, c1: 1, d1: 1 }; + console.log(b112, c1); + + const { + a2: _a2, + b2: { + b21: { + b211: _b211, b212: _b212 + } + }, + c2: _c2, + d2: _d2 + } = { a2: 1, b2: { b21: { b211: 1, b212: 1 } }, c2: 1, d2: 1 }; + + const { + a3, + ~~ +!!! error TS6133: 'a3' is declared but its value is never read. + b3: { + b31: { + ~ + b311, b312 + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ +!!! error TS6198: All destructured elements are unused. + }, + c3, + ~~ +!!! error TS6133: 'c3' is declared but its value is never read. + d3 + ~~ +!!! error TS6133: 'd3' is declared but its value is never read. + } = { a3: 1, b3: { b31: { b311: 1, b312: 1 } }, c3: 1, d3: 1 }; + } + + function t7() { + // error + const { _a1, _b1 } = { _a1: 1, _b1: 1 }; + ~~~~~~~~~~~~ +!!! error TS6198: All destructured elements are unused. + + // ok + const { a2: _a2, b2: _b2 } = { a2: 1, b2: 1 }; + + // ok + const { _a3: _ignoreA3, _b3: _ignoreB3 } = { _a3: 1, _b3: 1 }; + } + \ No newline at end of file diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.js b/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.js new file mode 100644 index 0000000000000..6e6846f470a59 --- /dev/null +++ b/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.js @@ -0,0 +1,136 @@ +//// [unusedVariablesWithUnderscoreInBindingElement.ts] +function t1() { + const [_a1, b1] = [1, 2]; + console.log(b1); + + const [a2, _b2] = [1, 2]; + console.log(a2); + + const [_a3, _b3] = [1, 2]; +} + +function t2() { + const [_a1, b1] = [1, 2]; + const [a2, _b2] = [1, 2]; + const [a3, b3] = [1, 2]; +} + +function t3() { + const [_a1, [[_b1, c1]], d1, _e1] = [1, [[2, 3]], 4, 5]; + console.log(c1, d1); + + const [_a2, [[_b2, _c2]], _d2, _e2] = [1, [[2, 3]], 4, 5]; + + const [a3, [[b3, c3]], d3, e3] = [1, [[2, 3]], 4, 5]; +} + +function t4() { + const { a1: _a1, b1 } = { a1: 1, b1: 1 }; + console.log(b1); + + const { a2, b2: _b2 } = { a2: 1, b2: 1 }; + console.log(a2); + + const { a3: _a3, b3: _b3 } = { a3: 1, b3: 1 }; +} + +function t5() { + const { a1: _a1, b1 } = { a1: 1, b1: 1 }; + const { a2, b2: _b2 } = { a2: 1, b2: 1 }; + const { a3, b3 } = { a3: 1, b3: 1 }; +} + +function t6() { + const { + a1: _a1, + b1: { + b11: { + b111: _b111, + b112 + } + }, + c1, + d1: _d1 + } = { a1: 1, b1: { b11: { b111: 1, b112: 1 } }, c1: 1, d1: 1 }; + console.log(b112, c1); + + const { + a2: _a2, + b2: { + b21: { + b211: _b211, b212: _b212 + } + }, + c2: _c2, + d2: _d2 + } = { a2: 1, b2: { b21: { b211: 1, b212: 1 } }, c2: 1, d2: 1 }; + + const { + a3, + b3: { + b31: { + b311, b312 + } + }, + c3, + d3 + } = { a3: 1, b3: { b31: { b311: 1, b312: 1 } }, c3: 1, d3: 1 }; +} + +function t7() { + // error + const { _a1, _b1 } = { _a1: 1, _b1: 1 }; + + // ok + const { a2: _a2, b2: _b2 } = { a2: 1, b2: 1 }; + + // ok + const { _a3: _ignoreA3, _b3: _ignoreB3 } = { _a3: 1, _b3: 1 }; +} + + +//// [unusedVariablesWithUnderscoreInBindingElement.js] +function t1() { + var _a = [1, 2], _a1 = _a[0], b1 = _a[1]; + console.log(b1); + var _b = [1, 2], a2 = _b[0], _b2 = _b[1]; + console.log(a2); + var _c = [1, 2], _a3 = _c[0], _b3 = _c[1]; +} +function t2() { + var _a = [1, 2], _a1 = _a[0], b1 = _a[1]; + var _b = [1, 2], a2 = _b[0], _b2 = _b[1]; + var _c = [1, 2], a3 = _c[0], b3 = _c[1]; +} +function t3() { + var _a = [1, [[2, 3]], 4, 5], _a1 = _a[0], _b = _a[1][0], _b1 = _b[0], c1 = _b[1], d1 = _a[2], _e1 = _a[3]; + console.log(c1, d1); + var _c = [1, [[2, 3]], 4, 5], _a2 = _c[0], _d = _c[1][0], _b2 = _d[0], _c2 = _d[1], _d2 = _c[2], _e2 = _c[3]; + var _e = [1, [[2, 3]], 4, 5], a3 = _e[0], _f = _e[1][0], b3 = _f[0], c3 = _f[1], d3 = _e[2], e3 = _e[3]; +} +function t4() { + var _a = { a1: 1, b1: 1 }, _a1 = _a.a1, b1 = _a.b1; + console.log(b1); + var _b = { a2: 1, b2: 1 }, a2 = _b.a2, _b2 = _b.b2; + console.log(a2); + var _c = { a3: 1, b3: 1 }, _a3 = _c.a3, _b3 = _c.b3; +} +function t5() { + var _a = { a1: 1, b1: 1 }, _a1 = _a.a1, b1 = _a.b1; + var _b = { a2: 1, b2: 1 }, a2 = _b.a2, _b2 = _b.b2; + var _c = { a3: 1, b3: 1 }, a3 = _c.a3, b3 = _c.b3; +} +function t6() { + var _a = { a1: 1, b1: { b11: { b111: 1, b112: 1 } }, c1: 1, d1: 1 }, _a1 = _a.a1, _b = _a.b1.b11, _b111 = _b.b111, b112 = _b.b112, c1 = _a.c1, _d1 = _a.d1; + console.log(b112, c1); + var _c = { a2: 1, b2: { b21: { b211: 1, b212: 1 } }, c2: 1, d2: 1 }, _a2 = _c.a2, _d = _c.b2.b21, _b211 = _d.b211, _b212 = _d.b212, _c2 = _c.c2, _d2 = _c.d2; + var _e = { a3: 1, b3: { b31: { b311: 1, b312: 1 } }, c3: 1, d3: 1 }, a3 = _e.a3, _f = _e.b3.b31, b311 = _f.b311, b312 = _f.b312, c3 = _e.c3, d3 = _e.d3; +} +function t7() { + // error + var _a = { _a1: 1, _b1: 1 }, _a1 = _a._a1, _b1 = _a._b1; + // ok + var _b = { a2: 1, b2: 1 }, _a2 = _b.a2, _b2 = _b.b2; + // ok + var _c = { _a3: 1, _b3: 1 }, _ignoreA3 = _c._a3, _ignoreB3 = _c._b3; +} diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.symbols b/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.symbols new file mode 100644 index 0000000000000..0c5367a9ed64f --- /dev/null +++ b/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.symbols @@ -0,0 +1,279 @@ +=== tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts === +function t1() { +>t1 : Symbol(t1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 0, 0)) + + const [_a1, b1] = [1, 2]; +>_a1 : Symbol(_a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 1, 11)) +>b1 : Symbol(b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 1, 15)) + + console.log(b1); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>b1 : Symbol(b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 1, 15)) + + const [a2, _b2] = [1, 2]; +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 4, 11)) +>_b2 : Symbol(_b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 4, 14)) + + console.log(a2); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 4, 11)) + + const [_a3, _b3] = [1, 2]; +>_a3 : Symbol(_a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 7, 11)) +>_b3 : Symbol(_b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 7, 15)) +} + +function t2() { +>t2 : Symbol(t2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 8, 1)) + + const [_a1, b1] = [1, 2]; +>_a1 : Symbol(_a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 11, 11)) +>b1 : Symbol(b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 11, 15)) + + const [a2, _b2] = [1, 2]; +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 12, 11)) +>_b2 : Symbol(_b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 12, 14)) + + const [a3, b3] = [1, 2]; +>a3 : Symbol(a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 13, 11)) +>b3 : Symbol(b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 13, 14)) +} + +function t3() { +>t3 : Symbol(t3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 14, 1)) + + const [_a1, [[_b1, c1]], d1, _e1] = [1, [[2, 3]], 4, 5]; +>_a1 : Symbol(_a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 17, 11)) +>_b1 : Symbol(_b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 17, 18)) +>c1 : Symbol(c1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 17, 22)) +>d1 : Symbol(d1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 17, 28)) +>_e1 : Symbol(_e1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 17, 32)) + + console.log(c1, d1); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>c1 : Symbol(c1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 17, 22)) +>d1 : Symbol(d1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 17, 28)) + + const [_a2, [[_b2, _c2]], _d2, _e2] = [1, [[2, 3]], 4, 5]; +>_a2 : Symbol(_a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 20, 11)) +>_b2 : Symbol(_b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 20, 18)) +>_c2 : Symbol(_c2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 20, 22)) +>_d2 : Symbol(_d2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 20, 29)) +>_e2 : Symbol(_e2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 20, 34)) + + const [a3, [[b3, c3]], d3, e3] = [1, [[2, 3]], 4, 5]; +>a3 : Symbol(a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 22, 11)) +>b3 : Symbol(b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 22, 17)) +>c3 : Symbol(c3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 22, 20)) +>d3 : Symbol(d3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 22, 26)) +>e3 : Symbol(e3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 22, 30)) +} + +function t4() { +>t4 : Symbol(t4, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 23, 1)) + + const { a1: _a1, b1 } = { a1: 1, b1: 1 }; +>a1 : Symbol(a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 26, 29)) +>_a1 : Symbol(_a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 26, 11)) +>b1 : Symbol(b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 26, 20)) +>a1 : Symbol(a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 26, 29)) +>b1 : Symbol(b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 26, 36)) + + console.log(b1); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>b1 : Symbol(b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 26, 20)) + + const { a2, b2: _b2 } = { a2: 1, b2: 1 }; +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 29, 11)) +>b2 : Symbol(b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 29, 36)) +>_b2 : Symbol(_b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 29, 15)) +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 29, 29)) +>b2 : Symbol(b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 29, 36)) + + console.log(a2); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 29, 11)) + + const { a3: _a3, b3: _b3 } = { a3: 1, b3: 1 }; +>a3 : Symbol(a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 32, 34)) +>_a3 : Symbol(_a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 32, 11)) +>b3 : Symbol(b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 32, 41)) +>_b3 : Symbol(_b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 32, 20)) +>a3 : Symbol(a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 32, 34)) +>b3 : Symbol(b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 32, 41)) +} + +function t5() { +>t5 : Symbol(t5, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 33, 1)) + + const { a1: _a1, b1 } = { a1: 1, b1: 1 }; +>a1 : Symbol(a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 36, 29)) +>_a1 : Symbol(_a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 36, 11)) +>b1 : Symbol(b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 36, 20)) +>a1 : Symbol(a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 36, 29)) +>b1 : Symbol(b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 36, 36)) + + const { a2, b2: _b2 } = { a2: 1, b2: 1 }; +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 37, 11)) +>b2 : Symbol(b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 37, 36)) +>_b2 : Symbol(_b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 37, 15)) +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 37, 29)) +>b2 : Symbol(b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 37, 36)) + + const { a3, b3 } = { a3: 1, b3: 1 }; +>a3 : Symbol(a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 38, 11)) +>b3 : Symbol(b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 38, 15)) +>a3 : Symbol(a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 38, 24)) +>b3 : Symbol(b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 38, 31)) +} + +function t6() { +>t6 : Symbol(t6, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 39, 1)) + + const { + a1: _a1, +>a1 : Symbol(a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 9)) +>_a1 : Symbol(_a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 42, 11)) + + b1: { +>b1 : Symbol(b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 16)) + + b11: { +>b11 : Symbol(b11, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 22)) + + b111: _b111, +>b111 : Symbol(b111, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 29)) +>_b111 : Symbol(_b111, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 45, 18)) + + b112 +>b112 : Symbol(b112, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 46, 28)) + } + }, + c1, +>c1 : Symbol(c1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 49, 10)) + + d1: _d1 +>d1 : Symbol(d1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 58)) +>_d1 : Symbol(_d1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 50, 11)) + + } = { a1: 1, b1: { b11: { b111: 1, b112: 1 } }, c1: 1, d1: 1 }; +>a1 : Symbol(a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 9)) +>b1 : Symbol(b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 16)) +>b11 : Symbol(b11, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 22)) +>b111 : Symbol(b111, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 29)) +>b112 : Symbol(b112, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 38)) +>c1 : Symbol(c1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 51)) +>d1 : Symbol(d1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 52, 58)) + + console.log(b112, c1); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>b112 : Symbol(b112, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 46, 28)) +>c1 : Symbol(c1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 49, 10)) + + const { + a2: _a2, +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 9)) +>_a2 : Symbol(_a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 55, 11)) + + b2: { +>b2 : Symbol(b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 16)) + + b21: { +>b21 : Symbol(b21, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 22)) + + b211: _b211, b212: _b212 +>b211 : Symbol(b211, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 29)) +>_b211 : Symbol(_b211, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 58, 18)) +>b212 : Symbol(b212, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 38)) +>_b212 : Symbol(_b212, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 59, 28)) + } + }, + c2: _c2, +>c2 : Symbol(c2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 51)) +>_c2 : Symbol(_c2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 61, 10)) + + d2: _d2 +>d2 : Symbol(d2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 58)) +>_d2 : Symbol(_d2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 62, 16)) + + } = { a2: 1, b2: { b21: { b211: 1, b212: 1 } }, c2: 1, d2: 1 }; +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 9)) +>b2 : Symbol(b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 16)) +>b21 : Symbol(b21, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 22)) +>b211 : Symbol(b211, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 29)) +>b212 : Symbol(b212, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 38)) +>c2 : Symbol(c2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 51)) +>d2 : Symbol(d2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 64, 58)) + + const { + a3, +>a3 : Symbol(a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 66, 11)) + + b3: { +>b3 : Symbol(b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 75, 16)) + + b31: { +>b31 : Symbol(b31, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 75, 22)) + + b311, b312 +>b311 : Symbol(b311, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 69, 18)) +>b312 : Symbol(b312, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 70, 21)) + } + }, + c3, +>c3 : Symbol(c3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 72, 10)) + + d3 +>d3 : Symbol(d3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 73, 11)) + + } = { a3: 1, b3: { b31: { b311: 1, b312: 1 } }, c3: 1, d3: 1 }; +>a3 : Symbol(a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 75, 9)) +>b3 : Symbol(b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 75, 16)) +>b31 : Symbol(b31, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 75, 22)) +>b311 : Symbol(b311, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 75, 29)) +>b312 : Symbol(b312, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 75, 38)) +>c3 : Symbol(c3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 75, 51)) +>d3 : Symbol(d3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 75, 58)) +} + +function t7() { +>t7 : Symbol(t7, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 76, 1)) + + // error + const { _a1, _b1 } = { _a1: 1, _b1: 1 }; +>_a1 : Symbol(_a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 80, 11)) +>_b1 : Symbol(_b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 80, 16)) +>_a1 : Symbol(_a1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 80, 26)) +>_b1 : Symbol(_b1, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 80, 34)) + + // ok + const { a2: _a2, b2: _b2 } = { a2: 1, b2: 1 }; +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 83, 34)) +>_a2 : Symbol(_a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 83, 11)) +>b2 : Symbol(b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 83, 41)) +>_b2 : Symbol(_b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 83, 20)) +>a2 : Symbol(a2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 83, 34)) +>b2 : Symbol(b2, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 83, 41)) + + // ok + const { _a3: _ignoreA3, _b3: _ignoreB3 } = { _a3: 1, _b3: 1 }; +>_a3 : Symbol(_a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 86, 48)) +>_ignoreA3 : Symbol(_ignoreA3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 86, 11)) +>_b3 : Symbol(_b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 86, 56)) +>_ignoreB3 : Symbol(_ignoreB3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 86, 27)) +>_a3 : Symbol(_a3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 86, 48)) +>_b3 : Symbol(_b3, Decl(unusedVariablesWithUnderscoreInBindingElement.ts, 86, 56)) +} + diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.types b/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.types new file mode 100644 index 0000000000000..d5d65c91af935 --- /dev/null +++ b/tests/baselines/reference/unusedVariablesWithUnderscoreInBindingElement.types @@ -0,0 +1,378 @@ +=== tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts === +function t1() { +>t1 : () => void + + const [_a1, b1] = [1, 2]; +>_a1 : number +>b1 : number +>[1, 2] : [number, number] +>1 : 1 +>2 : 2 + + console.log(b1); +>console.log(b1) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>b1 : number + + const [a2, _b2] = [1, 2]; +>a2 : number +>_b2 : number +>[1, 2] : [number, number] +>1 : 1 +>2 : 2 + + console.log(a2); +>console.log(a2) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>a2 : number + + const [_a3, _b3] = [1, 2]; +>_a3 : number +>_b3 : number +>[1, 2] : [number, number] +>1 : 1 +>2 : 2 +} + +function t2() { +>t2 : () => void + + const [_a1, b1] = [1, 2]; +>_a1 : number +>b1 : number +>[1, 2] : [number, number] +>1 : 1 +>2 : 2 + + const [a2, _b2] = [1, 2]; +>a2 : number +>_b2 : number +>[1, 2] : [number, number] +>1 : 1 +>2 : 2 + + const [a3, b3] = [1, 2]; +>a3 : number +>b3 : number +>[1, 2] : [number, number] +>1 : 1 +>2 : 2 +} + +function t3() { +>t3 : () => void + + const [_a1, [[_b1, c1]], d1, _e1] = [1, [[2, 3]], 4, 5]; +>_a1 : number +>_b1 : number +>c1 : number +>d1 : number +>_e1 : number +>[1, [[2, 3]], 4, 5] : [number, [[number, number]], number, number] +>1 : 1 +>[[2, 3]] : [[number, number]] +>[2, 3] : [number, number] +>2 : 2 +>3 : 3 +>4 : 4 +>5 : 5 + + console.log(c1, d1); +>console.log(c1, d1) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>c1 : number +>d1 : number + + const [_a2, [[_b2, _c2]], _d2, _e2] = [1, [[2, 3]], 4, 5]; +>_a2 : number +>_b2 : number +>_c2 : number +>_d2 : number +>_e2 : number +>[1, [[2, 3]], 4, 5] : [number, [[number, number]], number, number] +>1 : 1 +>[[2, 3]] : [[number, number]] +>[2, 3] : [number, number] +>2 : 2 +>3 : 3 +>4 : 4 +>5 : 5 + + const [a3, [[b3, c3]], d3, e3] = [1, [[2, 3]], 4, 5]; +>a3 : number +>b3 : number +>c3 : number +>d3 : number +>e3 : number +>[1, [[2, 3]], 4, 5] : [number, [[number, number]], number, number] +>1 : 1 +>[[2, 3]] : [[number, number]] +>[2, 3] : [number, number] +>2 : 2 +>3 : 3 +>4 : 4 +>5 : 5 +} + +function t4() { +>t4 : () => void + + const { a1: _a1, b1 } = { a1: 1, b1: 1 }; +>a1 : any +>_a1 : number +>b1 : number +>{ a1: 1, b1: 1 } : { a1: number; b1: number; } +>a1 : number +>1 : 1 +>b1 : number +>1 : 1 + + console.log(b1); +>console.log(b1) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>b1 : number + + const { a2, b2: _b2 } = { a2: 1, b2: 1 }; +>a2 : number +>b2 : any +>_b2 : number +>{ a2: 1, b2: 1 } : { a2: number; b2: number; } +>a2 : number +>1 : 1 +>b2 : number +>1 : 1 + + console.log(a2); +>console.log(a2) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>a2 : number + + const { a3: _a3, b3: _b3 } = { a3: 1, b3: 1 }; +>a3 : any +>_a3 : number +>b3 : any +>_b3 : number +>{ a3: 1, b3: 1 } : { a3: number; b3: number; } +>a3 : number +>1 : 1 +>b3 : number +>1 : 1 +} + +function t5() { +>t5 : () => void + + const { a1: _a1, b1 } = { a1: 1, b1: 1 }; +>a1 : any +>_a1 : number +>b1 : number +>{ a1: 1, b1: 1 } : { a1: number; b1: number; } +>a1 : number +>1 : 1 +>b1 : number +>1 : 1 + + const { a2, b2: _b2 } = { a2: 1, b2: 1 }; +>a2 : number +>b2 : any +>_b2 : number +>{ a2: 1, b2: 1 } : { a2: number; b2: number; } +>a2 : number +>1 : 1 +>b2 : number +>1 : 1 + + const { a3, b3 } = { a3: 1, b3: 1 }; +>a3 : number +>b3 : number +>{ a3: 1, b3: 1 } : { a3: number; b3: number; } +>a3 : number +>1 : 1 +>b3 : number +>1 : 1 +} + +function t6() { +>t6 : () => void + + const { + a1: _a1, +>a1 : any +>_a1 : number + + b1: { +>b1 : any + + b11: { +>b11 : any + + b111: _b111, +>b111 : any +>_b111 : number + + b112 +>b112 : number + } + }, + c1, +>c1 : number + + d1: _d1 +>d1 : any +>_d1 : number + + } = { a1: 1, b1: { b11: { b111: 1, b112: 1 } }, c1: 1, d1: 1 }; +>{ a1: 1, b1: { b11: { b111: 1, b112: 1 } }, c1: 1, d1: 1 } : { a1: number; b1: { b11: { b111: number; b112: number; }; }; c1: number; d1: number; } +>a1 : number +>1 : 1 +>b1 : { b11: { b111: number; b112: number; }; } +>{ b11: { b111: 1, b112: 1 } } : { b11: { b111: number; b112: number; }; } +>b11 : { b111: number; b112: number; } +>{ b111: 1, b112: 1 } : { b111: number; b112: number; } +>b111 : number +>1 : 1 +>b112 : number +>1 : 1 +>c1 : number +>1 : 1 +>d1 : number +>1 : 1 + + console.log(b112, c1); +>console.log(b112, c1) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>b112 : number +>c1 : number + + const { + a2: _a2, +>a2 : any +>_a2 : number + + b2: { +>b2 : any + + b21: { +>b21 : any + + b211: _b211, b212: _b212 +>b211 : any +>_b211 : number +>b212 : any +>_b212 : number + } + }, + c2: _c2, +>c2 : any +>_c2 : number + + d2: _d2 +>d2 : any +>_d2 : number + + } = { a2: 1, b2: { b21: { b211: 1, b212: 1 } }, c2: 1, d2: 1 }; +>{ a2: 1, b2: { b21: { b211: 1, b212: 1 } }, c2: 1, d2: 1 } : { a2: number; b2: { b21: { b211: number; b212: number; }; }; c2: number; d2: number; } +>a2 : number +>1 : 1 +>b2 : { b21: { b211: number; b212: number; }; } +>{ b21: { b211: 1, b212: 1 } } : { b21: { b211: number; b212: number; }; } +>b21 : { b211: number; b212: number; } +>{ b211: 1, b212: 1 } : { b211: number; b212: number; } +>b211 : number +>1 : 1 +>b212 : number +>1 : 1 +>c2 : number +>1 : 1 +>d2 : number +>1 : 1 + + const { + a3, +>a3 : number + + b3: { +>b3 : any + + b31: { +>b31 : any + + b311, b312 +>b311 : number +>b312 : number + } + }, + c3, +>c3 : number + + d3 +>d3 : number + + } = { a3: 1, b3: { b31: { b311: 1, b312: 1 } }, c3: 1, d3: 1 }; +>{ a3: 1, b3: { b31: { b311: 1, b312: 1 } }, c3: 1, d3: 1 } : { a3: number; b3: { b31: { b311: number; b312: number; }; }; c3: number; d3: number; } +>a3 : number +>1 : 1 +>b3 : { b31: { b311: number; b312: number; }; } +>{ b31: { b311: 1, b312: 1 } } : { b31: { b311: number; b312: number; }; } +>b31 : { b311: number; b312: number; } +>{ b311: 1, b312: 1 } : { b311: number; b312: number; } +>b311 : number +>1 : 1 +>b312 : number +>1 : 1 +>c3 : number +>1 : 1 +>d3 : number +>1 : 1 +} + +function t7() { +>t7 : () => void + + // error + const { _a1, _b1 } = { _a1: 1, _b1: 1 }; +>_a1 : number +>_b1 : number +>{ _a1: 1, _b1: 1 } : { _a1: number; _b1: number; } +>_a1 : number +>1 : 1 +>_b1 : number +>1 : 1 + + // ok + const { a2: _a2, b2: _b2 } = { a2: 1, b2: 1 }; +>a2 : any +>_a2 : number +>b2 : any +>_b2 : number +>{ a2: 1, b2: 1 } : { a2: number; b2: number; } +>a2 : number +>1 : 1 +>b2 : number +>1 : 1 + + // ok + const { _a3: _ignoreA3, _b3: _ignoreB3 } = { _a3: 1, _b3: 1 }; +>_a3 : any +>_ignoreA3 : number +>_b3 : any +>_ignoreB3 : number +>{ _a3: 1, _b3: 1 } : { _a3: number; _b3: number; } +>_a3 : number +>1 : 1 +>_b3 : number +>1 : 1 +} + diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.errors.txt b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.errors.txt new file mode 100644 index 0000000000000..38476fd6c796a --- /dev/null +++ b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.errors.txt @@ -0,0 +1,56 @@ +tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts(15,21): error TS6133: 'b' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts(17,17): error TS6133: 'a' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts(19,17): error TS6133: 'a' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts(19,20): error TS6133: 'b' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts(23,23): error TS6133: 'b' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts(25,19): error TS6133: 'a' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts(27,19): error TS6133: 'a' is declared but its value is never read. +tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts(27,22): error TS6133: 'b' is declared but its value is never read. + + +==== tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts (8 errors) ==== + function t1() { + for (const [_a, b] of [['key', 1]]) { + console.log(b); + } + + for (const [a, _b] of [['key', 1]]) { + console.log(a); + } + + for (const [_a, _b] of [['key', 1]]) {} + } + + + function t2() { + for (const [_a, b] of [['key', 1]]) {} + ~ +!!! error TS6133: 'b' is declared but its value is never read. + + for (const [a, _b] of [['key', 1]]) {} + ~ +!!! error TS6133: 'a' is declared but its value is never read. + + for (const [a, b] of [['key', 1]]) {} + ~ +!!! error TS6133: 'a' is declared but its value is never read. + ~ +!!! error TS6133: 'b' is declared but its value is never read. + } + + function t3() { + for (const [[[_a, b]]] of [[[['key', 1]]]]) {} + ~ +!!! error TS6133: 'b' is declared but its value is never read. + + for (const [[[a, _b]]] of [[[['key', 1]]]]) {} + ~ +!!! error TS6133: 'a' is declared but its value is never read. + + for (const [[[a, b]]] of [[[['key', 1]]]]) {} + ~ +!!! error TS6133: 'a' is declared but its value is never read. + ~ +!!! error TS6133: 'b' is declared but its value is never read. + } + \ No newline at end of file diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.js b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.js index 0c08ba841931f..3418db8795e79 100644 --- a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.js +++ b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.js @@ -1,5 +1,5 @@ //// [unusedVariablesWithUnderscoreInForOfLoop.ts] -function f() { +function t1() { for (const [_a, b] of [['key', 1]]) { console.log(b); } @@ -10,10 +10,27 @@ function f() { for (const [_a, _b] of [['key', 1]]) {} } + + +function t2() { + for (const [_a, b] of [['key', 1]]) {} + + for (const [a, _b] of [['key', 1]]) {} + + for (const [a, b] of [['key', 1]]) {} +} + +function t3() { + for (const [[[_a, b]]] of [[[['key', 1]]]]) {} + + for (const [[[a, _b]]] of [[[['key', 1]]]]) {} + + for (const [[[a, b]]] of [[[['key', 1]]]]) {} +} //// [unusedVariablesWithUnderscoreInForOfLoop.js] -function f() { +function t1() { for (var _i = 0, _c = [['key', 1]]; _i < _c.length; _i++) { var _d = _c[_i], _a = _d[0], b = _d[1]; console.log(b); @@ -26,3 +43,25 @@ function f() { var _k = _j[_h], _a = _k[0], _b = _k[1]; } } +function t2() { + for (var _i = 0, _c = [['key', 1]]; _i < _c.length; _i++) { + var _d = _c[_i], _a = _d[0], b = _d[1]; + } + for (var _e = 0, _f = [['key', 1]]; _e < _f.length; _e++) { + var _g = _f[_e], a = _g[0], _b = _g[1]; + } + for (var _h = 0, _j = [['key', 1]]; _h < _j.length; _h++) { + var _k = _j[_h], a = _k[0], b = _k[1]; + } +} +function t3() { + for (var _i = 0, _c = [[[['key', 1]]]]; _i < _c.length; _i++) { + var _d = _c[_i][0][0], _a = _d[0], b = _d[1]; + } + for (var _e = 0, _f = [[[['key', 1]]]]; _e < _f.length; _e++) { + var _g = _f[_e][0][0], a = _g[0], _b = _g[1]; + } + for (var _h = 0, _j = [[[['key', 1]]]]; _h < _j.length; _h++) { + var _k = _j[_h][0][0], a = _k[0], b = _k[1]; + } +} diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.symbols b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.symbols index d6c97536d3b4f..2bc45a8911a2f 100644 --- a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.symbols +++ b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.symbols @@ -1,6 +1,6 @@ === tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts === -function f() { ->f : Symbol(f, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 0, 0)) +function t1() { +>t1 : Symbol(t1, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 0, 0)) for (const [_a, b] of [['key', 1]]) { >_a : Symbol(_a, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 1, 16)) @@ -29,3 +29,36 @@ function f() { >_b : Symbol(_b, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 9, 19)) } + +function t2() { +>t2 : Symbol(t2, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 10, 1)) + + for (const [_a, b] of [['key', 1]]) {} +>_a : Symbol(_a, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 14, 16)) +>b : Symbol(b, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 14, 19)) + + for (const [a, _b] of [['key', 1]]) {} +>a : Symbol(a, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 16, 16)) +>_b : Symbol(_b, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 16, 18)) + + for (const [a, b] of [['key', 1]]) {} +>a : Symbol(a, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 18, 16)) +>b : Symbol(b, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 18, 18)) +} + +function t3() { +>t3 : Symbol(t3, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 19, 1)) + + for (const [[[_a, b]]] of [[[['key', 1]]]]) {} +>_a : Symbol(_a, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 22, 18)) +>b : Symbol(b, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 22, 21)) + + for (const [[[a, _b]]] of [[[['key', 1]]]]) {} +>a : Symbol(a, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 24, 18)) +>_b : Symbol(_b, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 24, 20)) + + for (const [[[a, b]]] of [[[['key', 1]]]]) {} +>a : Symbol(a, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 26, 18)) +>b : Symbol(b, Decl(unusedVariablesWithUnderscoreInForOfLoop.ts, 26, 20)) +} + diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.types b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.types index eb1ce0b0bbeae..b86d820a46b91 100644 --- a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.types +++ b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop.types @@ -1,6 +1,6 @@ === tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts === -function f() { ->f : () => void +function t1() { +>t1 : () => void for (const [_a, b] of [['key', 1]]) { >_a : string | number @@ -43,3 +43,66 @@ function f() { >1 : 1 } + +function t2() { +>t2 : () => void + + for (const [_a, b] of [['key', 1]]) {} +>_a : string | number +>b : string | number +>[['key', 1]] : (string | number)[][] +>['key', 1] : (string | number)[] +>'key' : "key" +>1 : 1 + + for (const [a, _b] of [['key', 1]]) {} +>a : string | number +>_b : string | number +>[['key', 1]] : (string | number)[][] +>['key', 1] : (string | number)[] +>'key' : "key" +>1 : 1 + + for (const [a, b] of [['key', 1]]) {} +>a : string | number +>b : string | number +>[['key', 1]] : (string | number)[][] +>['key', 1] : (string | number)[] +>'key' : "key" +>1 : 1 +} + +function t3() { +>t3 : () => void + + for (const [[[_a, b]]] of [[[['key', 1]]]]) {} +>_a : string | number +>b : string | number +>[[[['key', 1]]]] : (string | number)[][][][] +>[[['key', 1]]] : (string | number)[][][] +>[['key', 1]] : (string | number)[][] +>['key', 1] : (string | number)[] +>'key' : "key" +>1 : 1 + + for (const [[[a, _b]]] of [[[['key', 1]]]]) {} +>a : string | number +>_b : string | number +>[[[['key', 1]]]] : (string | number)[][][][] +>[[['key', 1]]] : (string | number)[][][] +>[['key', 1]] : (string | number)[][] +>['key', 1] : (string | number)[] +>'key' : "key" +>1 : 1 + + for (const [[[a, b]]] of [[[['key', 1]]]]) {} +>a : string | number +>b : string | number +>[[[['key', 1]]]] : (string | number)[][][][] +>[[['key', 1]]] : (string | number)[][][] +>[['key', 1]] : (string | number)[][] +>['key', 1] : (string | number)[] +>'key' : "key" +>1 : 1 +} + diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.errors.txt b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.errors.txt deleted file mode 100644 index fa8b7d9d55caf..0000000000000 --- a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop1.ts(2,21): error TS6133: 'b' is declared but its value is never read. -tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop1.ts(4,17): error TS6133: 'a' is declared but its value is never read. -tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop1.ts(6,17): error TS6133: 'a' is declared but its value is never read. -tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop1.ts(6,20): error TS6133: 'b' is declared but its value is never read. - - -==== tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop1.ts (4 errors) ==== - function f() { - for (const [_a, b] of [['key', 1]]) {} - ~ -!!! error TS6133: 'b' is declared but its value is never read. - - for (const [a, _b] of [['key', 1]]) {} - ~ -!!! error TS6133: 'a' is declared but its value is never read. - - for (const [a, b] of [['key', 1]]) {} - ~ -!!! error TS6133: 'a' is declared but its value is never read. - ~ -!!! error TS6133: 'b' is declared but its value is never read. - } - \ No newline at end of file diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.js b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.js deleted file mode 100644 index bb5ecbfe974c2..0000000000000 --- a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.js +++ /dev/null @@ -1,22 +0,0 @@ -//// [unusedVariablesWithUnderscoreInForOfLoop1.ts] -function f() { - for (const [_a, b] of [['key', 1]]) {} - - for (const [a, _b] of [['key', 1]]) {} - - for (const [a, b] of [['key', 1]]) {} -} - - -//// [unusedVariablesWithUnderscoreInForOfLoop1.js] -function f() { - for (var _i = 0, _c = [['key', 1]]; _i < _c.length; _i++) { - var _d = _c[_i], _a = _d[0], b = _d[1]; - } - for (var _e = 0, _f = [['key', 1]]; _e < _f.length; _e++) { - var _g = _f[_e], a = _g[0], _b = _g[1]; - } - for (var _h = 0, _j = [['key', 1]]; _h < _j.length; _h++) { - var _k = _j[_h], a = _k[0], b = _k[1]; - } -} diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.symbols b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.symbols deleted file mode 100644 index b98293944afd4..0000000000000 --- a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.symbols +++ /dev/null @@ -1,17 +0,0 @@ -=== tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop1.ts === -function f() { ->f : Symbol(f, Decl(unusedVariablesWithUnderscoreInForOfLoop1.ts, 0, 0)) - - for (const [_a, b] of [['key', 1]]) {} ->_a : Symbol(_a, Decl(unusedVariablesWithUnderscoreInForOfLoop1.ts, 1, 16)) ->b : Symbol(b, Decl(unusedVariablesWithUnderscoreInForOfLoop1.ts, 1, 19)) - - for (const [a, _b] of [['key', 1]]) {} ->a : Symbol(a, Decl(unusedVariablesWithUnderscoreInForOfLoop1.ts, 3, 16)) ->_b : Symbol(_b, Decl(unusedVariablesWithUnderscoreInForOfLoop1.ts, 3, 18)) - - for (const [a, b] of [['key', 1]]) {} ->a : Symbol(a, Decl(unusedVariablesWithUnderscoreInForOfLoop1.ts, 5, 16)) ->b : Symbol(b, Decl(unusedVariablesWithUnderscoreInForOfLoop1.ts, 5, 18)) -} - diff --git a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.types b/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.types deleted file mode 100644 index 100e87191482f..0000000000000 --- a/tests/baselines/reference/unusedVariablesWithUnderscoreInForOfLoop1.types +++ /dev/null @@ -1,29 +0,0 @@ -=== tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop1.ts === -function f() { ->f : () => void - - for (const [_a, b] of [['key', 1]]) {} ->_a : string | number ->b : string | number ->[['key', 1]] : (string | number)[][] ->['key', 1] : (string | number)[] ->'key' : "key" ->1 : 1 - - for (const [a, _b] of [['key', 1]]) {} ->a : string | number ->_b : string | number ->[['key', 1]] : (string | number)[][] ->['key', 1] : (string | number)[] ->'key' : "key" ->1 : 1 - - for (const [a, b] of [['key', 1]]) {} ->a : string | number ->b : string | number ->[['key', 1]] : (string | number)[][] ->['key', 1] : (string | number)[] ->'key' : "key" ->1 : 1 -} - diff --git a/tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts b/tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts new file mode 100644 index 0000000000000..23b732d51edb9 --- /dev/null +++ b/tests/cases/compiler/unusedVariablesWithUnderscoreInBindingElement.ts @@ -0,0 +1,90 @@ +// @noUnusedLocals: true + +function t1() { + const [_a1, b1] = [1, 2]; + console.log(b1); + + const [a2, _b2] = [1, 2]; + console.log(a2); + + const [_a3, _b3] = [1, 2]; +} + +function t2() { + const [_a1, b1] = [1, 2]; + const [a2, _b2] = [1, 2]; + const [a3, b3] = [1, 2]; +} + +function t3() { + const [_a1, [[_b1, c1]], d1, _e1] = [1, [[2, 3]], 4, 5]; + console.log(c1, d1); + + const [_a2, [[_b2, _c2]], _d2, _e2] = [1, [[2, 3]], 4, 5]; + + const [a3, [[b3, c3]], d3, e3] = [1, [[2, 3]], 4, 5]; +} + +function t4() { + const { a1: _a1, b1 } = { a1: 1, b1: 1 }; + console.log(b1); + + const { a2, b2: _b2 } = { a2: 1, b2: 1 }; + console.log(a2); + + const { a3: _a3, b3: _b3 } = { a3: 1, b3: 1 }; +} + +function t5() { + const { a1: _a1, b1 } = { a1: 1, b1: 1 }; + const { a2, b2: _b2 } = { a2: 1, b2: 1 }; + const { a3, b3 } = { a3: 1, b3: 1 }; +} + +function t6() { + const { + a1: _a1, + b1: { + b11: { + b111: _b111, + b112 + } + }, + c1, + d1: _d1 + } = { a1: 1, b1: { b11: { b111: 1, b112: 1 } }, c1: 1, d1: 1 }; + console.log(b112, c1); + + const { + a2: _a2, + b2: { + b21: { + b211: _b211, b212: _b212 + } + }, + c2: _c2, + d2: _d2 + } = { a2: 1, b2: { b21: { b211: 1, b212: 1 } }, c2: 1, d2: 1 }; + + const { + a3, + b3: { + b31: { + b311, b312 + } + }, + c3, + d3 + } = { a3: 1, b3: { b31: { b311: 1, b312: 1 } }, c3: 1, d3: 1 }; +} + +function t7() { + // error + const { _a1, _b1 } = { _a1: 1, _b1: 1 }; + + // ok + const { a2: _a2, b2: _b2 } = { a2: 1, b2: 1 }; + + // ok + const { _a3: _ignoreA3, _b3: _ignoreB3 } = { _a3: 1, _b3: 1 }; +} diff --git a/tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts b/tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts index 064e1971ead3d..0bd35321760d9 100644 --- a/tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts +++ b/tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop.ts @@ -1,6 +1,6 @@ -//@noUnusedLocals:true +// @noUnusedLocals: true -function f() { +function t1() { for (const [_a, b] of [['key', 1]]) { console.log(b); } @@ -11,3 +11,20 @@ function f() { for (const [_a, _b] of [['key', 1]]) {} } + + +function t2() { + for (const [_a, b] of [['key', 1]]) {} + + for (const [a, _b] of [['key', 1]]) {} + + for (const [a, b] of [['key', 1]]) {} +} + +function t3() { + for (const [[[_a, b]]] of [[[['key', 1]]]]) {} + + for (const [[[a, _b]]] of [[[['key', 1]]]]) {} + + for (const [[[a, b]]] of [[[['key', 1]]]]) {} +} diff --git a/tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop1.ts b/tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop1.ts deleted file mode 100644 index 0848f20d34a1d..0000000000000 --- a/tests/cases/compiler/unusedVariablesWithUnderscoreInForOfLoop1.ts +++ /dev/null @@ -1,9 +0,0 @@ -//@noUnusedLocals:true - -function f() { - for (const [_a, b] of [['key', 1]]) {} - - for (const [a, _b] of [['key', 1]]) {} - - for (const [a, b] of [['key', 1]]) {} -}