diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b63e301fbbc..1a31030c09e 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1640,7 +1640,12 @@ namespace ts { } checkStrictModeFunctionName(node); - return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes); + if (inStrictMode) { + bindBlockScopedDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes); + } + else { + return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes); + } } function bindFunctionExpression(node: FunctionExpression) { diff --git a/tests/baselines/reference/blockScopedFunctionDeclarationStrictES5.errors.txt b/tests/baselines/reference/blockScopedFunctionDeclarationStrictES5.errors.txt new file mode 100644 index 00000000000..d86b1e02953 --- /dev/null +++ b/tests/baselines/reference/blockScopedFunctionDeclarationStrictES5.errors.txt @@ -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'. \ No newline at end of file diff --git a/tests/baselines/reference/blockScopedFunctionDeclarationStrictES5.symbols b/tests/baselines/reference/blockScopedFunctionDeclarationStrictES5.symbols deleted file mode 100644 index b29ea10c205..00000000000 --- a/tests/baselines/reference/blockScopedFunctionDeclarationStrictES5.symbols +++ /dev/null @@ -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)) - diff --git a/tests/baselines/reference/blockScopedFunctionDeclarationStrictES5.types b/tests/baselines/reference/blockScopedFunctionDeclarationStrictES5.types deleted file mode 100644 index 94a61fc99af..00000000000 --- a/tests/baselines/reference/blockScopedFunctionDeclarationStrictES5.types +++ /dev/null @@ -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 - diff --git a/tests/baselines/reference/blockScopedFunctionDeclarationStrictES6.errors.txt b/tests/baselines/reference/blockScopedFunctionDeclarationStrictES6.errors.txt new file mode 100644 index 00000000000..6772a29926b --- /dev/null +++ b/tests/baselines/reference/blockScopedFunctionDeclarationStrictES6.errors.txt @@ -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'. \ No newline at end of file diff --git a/tests/baselines/reference/blockScopedFunctionDeclarationStrictES6.symbols b/tests/baselines/reference/blockScopedFunctionDeclarationStrictES6.symbols deleted file mode 100644 index af53145d3f2..00000000000 --- a/tests/baselines/reference/blockScopedFunctionDeclarationStrictES6.symbols +++ /dev/null @@ -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)) - diff --git a/tests/baselines/reference/blockScopedFunctionDeclarationStrictES6.types b/tests/baselines/reference/blockScopedFunctionDeclarationStrictES6.types deleted file mode 100644 index 2149b75f871..00000000000 --- a/tests/baselines/reference/blockScopedFunctionDeclarationStrictES6.types +++ /dev/null @@ -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 -