mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
consider binding elements as always initialized with doing shadow check
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(4,13): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(5,15): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(6,18): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(7,15): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(8,18): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts (5 errors) ====
|
||||
if (true) {
|
||||
let x;
|
||||
if (true) {
|
||||
var x = 0; // Error
|
||||
~
|
||||
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
var { x = 0 } = { x: 0 }; // Error
|
||||
~
|
||||
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
var { x: x = 0 } = { x: 0 }; // Error
|
||||
~
|
||||
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
var { x } = { x: 0 }; // No error, even though the let x is being initialized
|
||||
~
|
||||
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
var { x: x } = { x: 0 }; // No error, even though the let x is being initialized
|
||||
~
|
||||
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//// [shadowingViaLocalValueOrBindingElement.ts]
|
||||
if (true) {
|
||||
let x;
|
||||
if (true) {
|
||||
var x = 0; // Error
|
||||
var { x = 0 } = { x: 0 }; // Error
|
||||
var { x: x = 0 } = { x: 0 }; // Error
|
||||
var { x } = { x: 0 }; // No error, even though the let x is being initialized
|
||||
var { x: x } = { x: 0 }; // No error, even though the let x is being initialized
|
||||
}
|
||||
}
|
||||
|
||||
//// [shadowingViaLocalValueOrBindingElement.js]
|
||||
if (true) {
|
||||
var _x;
|
||||
if (true) {
|
||||
var x = 0; // Error
|
||||
var _a = ({
|
||||
_x: 0
|
||||
}).x, x = _a === void 0 ? 0 : _a; // Error
|
||||
var _b = ({
|
||||
_x: 0
|
||||
}).x, x = _b === void 0 ? 0 : _b; // Error
|
||||
var x = ({
|
||||
_x: 0
|
||||
}).x; // No error, even though the let x is being initialized
|
||||
var x = ({
|
||||
_x: 0
|
||||
}).x; // No error, even though the let x is being initialized
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
if (true) {
|
||||
let x;
|
||||
if (true) {
|
||||
var x = 0; // Error
|
||||
var { x = 0 } = { x: 0 }; // Error
|
||||
var { x: x = 0 } = { x: 0 }; // Error
|
||||
var { x } = { x: 0 }; // No error, even though the let x is being initialized
|
||||
var { x: x } = { x: 0 }; // No error, even though the let x is being initialized
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user