consider binding elements as always initialized with doing shadow check

This commit is contained in:
Vladimir Matveev
2015-03-13 14:34:10 -07:00
parent 82a940df06
commit 0675a92acc
4 changed files with 107 additions and 27 deletions

View File

@@ -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'.
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}