Bind the function declarations in block scope in strict mode

This commit is contained in:
Sheetal Nandi
2016-04-11 12:20:06 -07:00
parent f2c8e5c85e
commit 6988a0a479
7 changed files with 30 additions and 61 deletions
+6 -1
View File
@@ -1640,7 +1640,12 @@ namespace ts {
}
checkStrictModeFunctionName(<FunctionDeclaration>node);
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
if (inStrictMode) {
bindBlockScopedDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
}
else {
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
}
}
function bindFunctionExpression(node: FunctionExpression) {
@@ -0,0 +1,12 @@
tests/cases/compiler/blockScopedFunctionDeclarationStrictES5.ts(6,1): error TS2304: Cannot find name 'foo'.
==== tests/cases/compiler/blockScopedFunctionDeclarationStrictES5.ts (1 errors) ====
"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
~~~
!!! error TS2304: Cannot find name 'foo'.
@@ -1,12 +0,0 @@
=== 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))
@@ -1,18 +0,0 @@
=== 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,12 @@
tests/cases/compiler/blockScopedFunctionDeclarationStrictES6.ts(6,1): error TS2304: Cannot find name 'foo'.
==== tests/cases/compiler/blockScopedFunctionDeclarationStrictES6.ts (1 errors) ====
"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
~~~
!!! error TS2304: Cannot find name 'foo'.
@@ -1,12 +0,0 @@
=== 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))
@@ -1,18 +0,0 @@
=== 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