Add tests when object spread is used in destructuring
This commit is contained in:
parent
07ce4bd2e3
commit
9505a18894
3 changed files with 87 additions and 0 deletions
|
@ -0,0 +1,27 @@
|
|||
tests/cases/compiler/unusedLocalsAndObjectSpread.ts(7,12): error TS6133: 'a' is declared but never used.
|
||||
tests/cases/compiler/unusedLocalsAndObjectSpread.ts(14,15): error TS6133: '_' is declared but never used.
|
||||
|
||||
|
||||
==== tests/cases/compiler/unusedLocalsAndObjectSpread.ts (2 errors) ====
|
||||
|
||||
declare var console: { log(a: any): void };
|
||||
|
||||
function one() {
|
||||
const foo = { a: 1, b: 2 };
|
||||
// 'a' is declared but never used
|
||||
const {a, ...bar} = foo;
|
||||
~
|
||||
!!! error TS6133: 'a' is declared but never used.
|
||||
console.log(bar);
|
||||
}
|
||||
|
||||
function two() {
|
||||
const foo = { a: 1, b: 2 };
|
||||
// '_' is declared but never used
|
||||
const {a: _, ...bar} = foo;
|
||||
~
|
||||
!!! error TS6133: '_' is declared but never used.
|
||||
console.log(bar);
|
||||
}
|
||||
|
||||
|
42
tests/baselines/reference/unusedLocalsAndObjectSpread.js
Normal file
42
tests/baselines/reference/unusedLocalsAndObjectSpread.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
//// [unusedLocalsAndObjectSpread.ts]
|
||||
|
||||
declare var console: { log(a: any): void };
|
||||
|
||||
function one() {
|
||||
const foo = { a: 1, b: 2 };
|
||||
// 'a' is declared but never used
|
||||
const {a, ...bar} = foo;
|
||||
console.log(bar);
|
||||
}
|
||||
|
||||
function two() {
|
||||
const foo = { a: 1, b: 2 };
|
||||
// '_' is declared but never used
|
||||
const {a: _, ...bar} = foo;
|
||||
console.log(bar);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//// [unusedLocalsAndObjectSpread.js]
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
};
|
||||
function one() {
|
||||
var foo = { a: 1, b: 2 };
|
||||
// 'a' is declared but never used
|
||||
var a = foo.a, bar = __rest(foo, ["a"]);
|
||||
console.log(bar);
|
||||
}
|
||||
function two() {
|
||||
var foo = { a: 1, b: 2 };
|
||||
// '_' is declared but never used
|
||||
var _ = foo.a, bar = __rest(foo, ["a"]);
|
||||
console.log(bar);
|
||||
}
|
18
tests/cases/compiler/unusedLocalsAndObjectSpread.ts
Normal file
18
tests/cases/compiler/unusedLocalsAndObjectSpread.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
//@noUnusedLocals:true
|
||||
|
||||
declare var console: { log(a: any): void };
|
||||
|
||||
function one() {
|
||||
const foo = { a: 1, b: 2 };
|
||||
// 'a' is declared but never used
|
||||
const {a, ...bar} = foo;
|
||||
console.log(bar);
|
||||
}
|
||||
|
||||
function two() {
|
||||
const foo = { a: 1, b: 2 };
|
||||
// '_' is declared but never used
|
||||
const {a: _, ...bar} = foo;
|
||||
console.log(bar);
|
||||
}
|
||||
|
Loading…
Reference in a new issue