mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
added check that var and let\const cannot share scope, added check that var is not shadowed by the let\const from the inner scope
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(7,9): error TS2451: Cannot redeclare block-scoped variable 'x'.
|
||||
tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(15,13): error TS2451: Cannot redeclare block-scoped variable 'y'.
|
||||
tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS2451: Cannot redeclare block-scoped variable 'z'.
|
||||
tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(7,9): error TS4090: Cannot initialize outer scope variable 'x' when having block-scoped variable with the same name.
|
||||
tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(15,13): error TS4090: Cannot initialize outer scope variable 'y' when having block-scoped variable with the same name.
|
||||
tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS4090: Cannot initialize outer scope variable 'z' when having block-scoped variable with the same name.
|
||||
|
||||
|
||||
==== tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts (3 errors) ====
|
||||
@@ -12,7 +12,7 @@ tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS
|
||||
|
||||
var x = 0;
|
||||
~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x'.
|
||||
!!! error TS4090: Cannot initialize outer scope variable 'x' when having block-scoped variable with the same name.
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS
|
||||
{
|
||||
var y = 0;
|
||||
~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'y'.
|
||||
!!! error TS4090: Cannot initialize outer scope variable 'y' when having block-scoped variable with the same name.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,5 +31,5 @@ tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS
|
||||
const z = 0;
|
||||
var z = 0
|
||||
~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'z'.
|
||||
!!! error TS4090: Cannot initialize outer scope variable 'z' when having block-scoped variable with the same name.
|
||||
}
|
||||
118
tests/baselines/reference/letAndVarRedeclaration.errors.txt
Normal file
118
tests/baselines/reference/letAndVarRedeclaration.errors.txt
Normal file
@@ -0,0 +1,118 @@
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'e0'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(3,5): error TS2451: Cannot redeclare block-scoped variable 'e0'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(4,10): error TS2451: Cannot redeclare block-scoped variable 'e0'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(7,9): error TS2451: Cannot redeclare block-scoped variable 'x1'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(8,9): error TS2451: Cannot redeclare block-scoped variable 'x1'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(9,14): error TS2451: Cannot redeclare block-scoped variable 'x1'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(13,9): error TS2451: Cannot redeclare block-scoped variable 'x'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(15,13): error TS2451: Cannot redeclare block-scoped variable 'x'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(18,18): error TS2451: Cannot redeclare block-scoped variable 'x'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(23,9): error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(24,9): error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(25,14): error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(29,9): error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(31,13): error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(34,18): error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(38,5): error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(39,10): error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(43,9): error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(44,14): error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(49,9): error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
tests/cases/compiler/letAndVarRedeclaration.ts(50,14): error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/letAndVarRedeclaration.ts (21 errors) ====
|
||||
|
||||
let e0
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'e0'.
|
||||
var e0;
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'e0'.
|
||||
function e0() { }
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'e0'.
|
||||
|
||||
function f0() {
|
||||
let x1;
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x1'.
|
||||
var x1;
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x1'.
|
||||
function x1() { }
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x1'.
|
||||
}
|
||||
|
||||
function f1() {
|
||||
let x;
|
||||
~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x'.
|
||||
{
|
||||
var x;
|
||||
~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x'.
|
||||
}
|
||||
{
|
||||
function x() { }
|
||||
~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x'.
|
||||
}
|
||||
}
|
||||
|
||||
module M0 {
|
||||
let x2;
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
var x2;
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
function x2() { }
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
}
|
||||
|
||||
module M1 {
|
||||
let x2;
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
{
|
||||
var x2;
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
}
|
||||
{
|
||||
function x2() { }
|
||||
~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x2'.
|
||||
}
|
||||
}
|
||||
|
||||
let x11;
|
||||
~~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
for (var x11; ;) {
|
||||
~~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
}
|
||||
|
||||
function f2() {
|
||||
let x11;
|
||||
~~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
for (var x11; ;) {
|
||||
~~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
}
|
||||
}
|
||||
|
||||
module M2 {
|
||||
let x11;
|
||||
~~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
for (var x11; ;) {
|
||||
~~~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'x11'.
|
||||
}
|
||||
}
|
||||
102
tests/baselines/reference/letAndVarRedeclaration.js
Normal file
102
tests/baselines/reference/letAndVarRedeclaration.js
Normal file
@@ -0,0 +1,102 @@
|
||||
//// [letAndVarRedeclaration.ts]
|
||||
|
||||
let e0
|
||||
var e0;
|
||||
function e0() { }
|
||||
|
||||
function f0() {
|
||||
let x1;
|
||||
var x1;
|
||||
function x1() { }
|
||||
}
|
||||
|
||||
function f1() {
|
||||
let x;
|
||||
{
|
||||
var x;
|
||||
}
|
||||
{
|
||||
function x() { }
|
||||
}
|
||||
}
|
||||
|
||||
module M0 {
|
||||
let x2;
|
||||
var x2;
|
||||
function x2() { }
|
||||
}
|
||||
|
||||
module M1 {
|
||||
let x2;
|
||||
{
|
||||
var x2;
|
||||
}
|
||||
{
|
||||
function x2() { }
|
||||
}
|
||||
}
|
||||
|
||||
let x11;
|
||||
for (var x11; ;) {
|
||||
}
|
||||
|
||||
function f2() {
|
||||
let x11;
|
||||
for (var x11; ;) {
|
||||
}
|
||||
}
|
||||
|
||||
module M2 {
|
||||
let x11;
|
||||
for (var x11; ;) {
|
||||
}
|
||||
}
|
||||
|
||||
//// [letAndVarRedeclaration.js]
|
||||
let e0;
|
||||
var e0;
|
||||
function e0() { }
|
||||
function f0() {
|
||||
let x1;
|
||||
var x1;
|
||||
function x1() { }
|
||||
}
|
||||
function f1() {
|
||||
let x;
|
||||
{
|
||||
var x;
|
||||
}
|
||||
{
|
||||
function x() { }
|
||||
}
|
||||
}
|
||||
var M0;
|
||||
(function (M0) {
|
||||
let x2;
|
||||
var x2;
|
||||
function x2() { }
|
||||
})(M0 || (M0 = {}));
|
||||
var M1;
|
||||
(function (M1) {
|
||||
let x2;
|
||||
{
|
||||
var x2;
|
||||
}
|
||||
{
|
||||
function x2() { }
|
||||
}
|
||||
})(M1 || (M1 = {}));
|
||||
let x11;
|
||||
for (var x11;;) {
|
||||
}
|
||||
function f2() {
|
||||
let x11;
|
||||
for (var x11;;) {
|
||||
}
|
||||
}
|
||||
var M2;
|
||||
(function (M2) {
|
||||
let x11;
|
||||
for (var x11;;) {
|
||||
}
|
||||
})(M2 || (M2 = {}));
|
||||
30
tests/baselines/reference/shadowingViaLocalValue.errors.txt
Normal file
30
tests/baselines/reference/shadowingViaLocalValue.errors.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
tests/cases/compiler/shadowingViaLocalValue.ts(2,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher.
|
||||
tests/cases/compiler/shadowingViaLocalValue.ts(4,13): error TS4090: Cannot initialize outer scope variable 'x' when having block-scoped variable with the same name.
|
||||
tests/cases/compiler/shadowingViaLocalValue.ts(9,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher.
|
||||
tests/cases/compiler/shadowingViaLocalValue.ts(11,18): error TS4090: Cannot initialize outer scope variable 'x1' when having block-scoped variable with the same name.
|
||||
|
||||
|
||||
==== tests/cases/compiler/shadowingViaLocalValue.ts (4 errors) ====
|
||||
{
|
||||
let x;
|
||||
~~~
|
||||
!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher.
|
||||
{
|
||||
var x = 1;
|
||||
~
|
||||
!!! error TS4090: Cannot initialize outer scope variable 'x' when having block-scoped variable with the same name.
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let x1;
|
||||
~~~
|
||||
!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher.
|
||||
{
|
||||
for (var x1 = 0; ;);
|
||||
~~
|
||||
!!! error TS4090: Cannot initialize outer scope variable 'x1' when having block-scoped variable with the same name.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
31
tests/baselines/reference/shadowingViaLocalValue.js
Normal file
31
tests/baselines/reference/shadowingViaLocalValue.js
Normal file
@@ -0,0 +1,31 @@
|
||||
//// [shadowingViaLocalValue.ts]
|
||||
{
|
||||
let x;
|
||||
{
|
||||
var x = 1;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let x1;
|
||||
{
|
||||
for (var x1 = 0; ;);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//// [shadowingViaLocalValue.js]
|
||||
{
|
||||
let x;
|
||||
{
|
||||
var x = 1;
|
||||
}
|
||||
}
|
||||
{
|
||||
let x1;
|
||||
{
|
||||
for (var x1 = 0;;)
|
||||
;
|
||||
}
|
||||
}
|
||||
53
tests/cases/compiler/letAndVarRedeclaration.ts
Normal file
53
tests/cases/compiler/letAndVarRedeclaration.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
// @target: es6
|
||||
|
||||
let e0
|
||||
var e0;
|
||||
function e0() { }
|
||||
|
||||
function f0() {
|
||||
let x1;
|
||||
var x1;
|
||||
function x1() { }
|
||||
}
|
||||
|
||||
function f1() {
|
||||
let x;
|
||||
{
|
||||
var x;
|
||||
}
|
||||
{
|
||||
function x() { }
|
||||
}
|
||||
}
|
||||
|
||||
module M0 {
|
||||
let x2;
|
||||
var x2;
|
||||
function x2() { }
|
||||
}
|
||||
|
||||
module M1 {
|
||||
let x2;
|
||||
{
|
||||
var x2;
|
||||
}
|
||||
{
|
||||
function x2() { }
|
||||
}
|
||||
}
|
||||
|
||||
let x11;
|
||||
for (var x11; ;) {
|
||||
}
|
||||
|
||||
function f2() {
|
||||
let x11;
|
||||
for (var x11; ;) {
|
||||
}
|
||||
}
|
||||
|
||||
module M2 {
|
||||
let x11;
|
||||
for (var x11; ;) {
|
||||
}
|
||||
}
|
||||
14
tests/cases/compiler/shadowingViaLocalValue.ts
Normal file
14
tests/cases/compiler/shadowingViaLocalValue.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
let x;
|
||||
{
|
||||
var x = 1;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let x1;
|
||||
{
|
||||
for (var x1 = 0; ;);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user