Add test cases for function declarations in block scope

This commit is contained in:
Sheetal Nandi
2016-04-11 11:12:09 -07:00
parent b0584b58fa
commit f2c8e5c85e
16 changed files with 194 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
//// [blockScopedFunctionDeclarationES5.ts]
if (true) {
function foo() { }
foo();
}
foo();
//// [blockScopedFunctionDeclarationES5.js]
if (true) {
function foo() { }
foo();
}
foo();

View File

@@ -0,0 +1,11 @@
=== tests/cases/compiler/blockScopedFunctionDeclarationES5.ts ===
if (true) {
function foo() { }
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationES5.ts, 0, 11))
foo();
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationES5.ts, 0, 11))
}
foo();
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationES5.ts, 0, 11))

View File

@@ -0,0 +1,15 @@
=== tests/cases/compiler/blockScopedFunctionDeclarationES5.ts ===
if (true) {
>true : boolean
function foo() { }
>foo : () => void
foo();
>foo() : void
>foo : () => void
}
foo();
>foo() : void
>foo : () => void

View File

@@ -0,0 +1,13 @@
//// [blockScopedFunctionDeclarationES6.ts]
if (true) {
function foo() { }
foo();
}
foo();
//// [blockScopedFunctionDeclarationES6.js]
if (true) {
function foo() { }
foo();
}
foo();

View File

@@ -0,0 +1,11 @@
=== tests/cases/compiler/blockScopedFunctionDeclarationES6.ts ===
if (true) {
function foo() { }
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationES6.ts, 0, 11))
foo();
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationES6.ts, 0, 11))
}
foo();
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationES6.ts, 0, 11))

View File

@@ -0,0 +1,15 @@
=== tests/cases/compiler/blockScopedFunctionDeclarationES6.ts ===
if (true) {
>true : boolean
function foo() { }
>foo : () => void
foo();
>foo() : void
>foo : () => void
}
foo();
>foo() : void
>foo : () => void

View File

@@ -0,0 +1,15 @@
//// [blockScopedFunctionDeclarationStrictES5.ts]
"use strict";
if (true) {
function foo() { } // Error to declare function in block scope
foo(); // This call should be ok
}
foo(); // Error to find name foo
//// [blockScopedFunctionDeclarationStrictES5.js]
"use strict";
if (true) {
function foo() { } // Error to declare function in block scope
foo(); // This call should be ok
}
foo(); // Error to find name foo

View File

@@ -0,0 +1,12 @@
=== tests/cases/compiler/blockScopedFunctionDeclarationStrictES5.ts ===
"use strict";
if (true) {
function foo() { } // Error to declare function in block scope
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationStrictES5.ts, 1, 11))
foo(); // This call should be ok
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationStrictES5.ts, 1, 11))
}
foo(); // Error to find name foo
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationStrictES5.ts, 1, 11))

View File

@@ -0,0 +1,18 @@
=== tests/cases/compiler/blockScopedFunctionDeclarationStrictES5.ts ===
"use strict";
>"use strict" : string
if (true) {
>true : boolean
function foo() { } // Error to declare function in block scope
>foo : () => void
foo(); // This call should be ok
>foo() : void
>foo : () => void
}
foo(); // Error to find name foo
>foo() : void
>foo : () => void

View File

@@ -0,0 +1,15 @@
//// [blockScopedFunctionDeclarationStrictES6.ts]
"use strict";
if (true) {
function foo() { } // Allowed to declare block scope function
foo(); // This call should be ok
}
foo(); // Cannot find name since foo is block scoped
//// [blockScopedFunctionDeclarationStrictES6.js]
"use strict";
if (true) {
function foo() { } // Allowed to declare block scope function
foo(); // This call should be ok
}
foo(); // Cannot find name since foo is block scoped

View File

@@ -0,0 +1,12 @@
=== tests/cases/compiler/blockScopedFunctionDeclarationStrictES6.ts ===
"use strict";
if (true) {
function foo() { } // Allowed to declare block scope function
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationStrictES6.ts, 1, 11))
foo(); // This call should be ok
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationStrictES6.ts, 1, 11))
}
foo(); // Cannot find name since foo is block scoped
>foo : Symbol(foo, Decl(blockScopedFunctionDeclarationStrictES6.ts, 1, 11))

View File

@@ -0,0 +1,18 @@
=== tests/cases/compiler/blockScopedFunctionDeclarationStrictES6.ts ===
"use strict";
>"use strict" : string
if (true) {
>true : boolean
function foo() { } // Allowed to declare block scope function
>foo : () => void
foo(); // This call should be ok
>foo() : void
>foo : () => void
}
foo(); // Cannot find name since foo is block scoped
>foo() : void
>foo : () => void

View File

@@ -0,0 +1,6 @@
// @target: ES5
if (true) {
function foo() { }
foo();
}
foo();

View File

@@ -0,0 +1,6 @@
// @target: ES6
if (true) {
function foo() { }
foo();
}
foo();

View File

@@ -0,0 +1,7 @@
// @target: ES5
"use strict";
if (true) {
function foo() { } // Error to declare function in block scope
foo(); // This call should be ok
}
foo(); // Error to find name foo

View File

@@ -0,0 +1,7 @@
// @target: ES6
"use strict";
if (true) {
function foo() { } // Allowed to declare block scope function
foo(); // This call should be ok
}
foo(); // Cannot find name since foo is block scoped