mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-11 06:02:53 -05:00
Add test cases for function declarations in block scope
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
//// [blockScopedFunctionDeclarationES5.ts]
|
||||
if (true) {
|
||||
function foo() { }
|
||||
foo();
|
||||
}
|
||||
foo();
|
||||
|
||||
//// [blockScopedFunctionDeclarationES5.js]
|
||||
if (true) {
|
||||
function foo() { }
|
||||
foo();
|
||||
}
|
||||
foo();
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [blockScopedFunctionDeclarationES6.ts]
|
||||
if (true) {
|
||||
function foo() { }
|
||||
foo();
|
||||
}
|
||||
foo();
|
||||
|
||||
//// [blockScopedFunctionDeclarationES6.js]
|
||||
if (true) {
|
||||
function foo() { }
|
||||
foo();
|
||||
}
|
||||
foo();
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// @target: ES5
|
||||
if (true) {
|
||||
function foo() { }
|
||||
foo();
|
||||
}
|
||||
foo();
|
||||
@@ -0,0 +1,6 @@
|
||||
// @target: ES6
|
||||
if (true) {
|
||||
function foo() { }
|
||||
foo();
|
||||
}
|
||||
foo();
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user