diff --git a/tests/baselines/reference/blockScopedFunctionDeclarationInStrictClass.errors.txt b/tests/baselines/reference/blockScopedFunctionDeclarationInStrictClass.errors.txt new file mode 100644 index 00000000000..685abb1d886 --- /dev/null +++ b/tests/baselines/reference/blockScopedFunctionDeclarationInStrictClass.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/blockScopedFunctionDeclarationInStrictClass.ts(4,22): error TS1251: In ES5 or lower, function declarations are not allowed in block scope. Class definitions are automatically in strict mode. +tests/cases/compiler/blockScopedFunctionDeclarationInStrictClass.ts(7,9): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/compiler/blockScopedFunctionDeclarationInStrictClass.ts (2 errors) ==== + class c { + method() { + if (true) { + function foo() { } + ~~~ +!!! error TS1251: In ES5 or lower, function declarations are not allowed in block scope. Class definitions are automatically in strict mode. + foo(); // ok + } + foo(); // not ok + ~~~ +!!! error TS2304: Cannot find name 'foo'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/blockScopedFunctionDeclarationInStrictClass.js b/tests/baselines/reference/blockScopedFunctionDeclarationInStrictClass.js new file mode 100644 index 00000000000..70a00a95a41 --- /dev/null +++ b/tests/baselines/reference/blockScopedFunctionDeclarationInStrictClass.js @@ -0,0 +1,24 @@ +//// [blockScopedFunctionDeclarationInStrictClass.ts] +class c { + method() { + if (true) { + function foo() { } + foo(); // ok + } + foo(); // not ok + } +} + +//// [blockScopedFunctionDeclarationInStrictClass.js] +var c = (function () { + function c() { + } + c.prototype.method = function () { + if (true) { + function foo() { } + foo(); // ok + } + foo(); // not ok + }; + return c; +}()); diff --git a/tests/baselines/reference/blockScopedFunctionDeclarationInStrictModule.errors.txt b/tests/baselines/reference/blockScopedFunctionDeclarationInStrictModule.errors.txt new file mode 100644 index 00000000000..7916cb93da1 --- /dev/null +++ b/tests/baselines/reference/blockScopedFunctionDeclarationInStrictModule.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/blockScopedFunctionDeclarationInStrictModule.ts(2,14): error TS1252: In ES5 or lower, function declarations are not allowed in block scope. Modules are automatically in strict mode. +tests/cases/compiler/blockScopedFunctionDeclarationInStrictModule.ts(6,10): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/compiler/blockScopedFunctionDeclarationInStrictModule.ts (2 errors) ==== + if (true) { + function foo() { } + ~~~ +!!! error TS1252: In ES5 or lower, function declarations are not allowed in block scope. Modules are automatically in strict mode. + foo(); // ok + } + + export = foo; // not ok + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/blockScopedFunctionDeclarationInStrictModule.js b/tests/baselines/reference/blockScopedFunctionDeclarationInStrictModule.js new file mode 100644 index 00000000000..cd118733e3c --- /dev/null +++ b/tests/baselines/reference/blockScopedFunctionDeclarationInStrictModule.js @@ -0,0 +1,16 @@ +//// [blockScopedFunctionDeclarationInStrictModule.ts] +if (true) { + function foo() { } + foo(); // ok +} + +export = foo; // not ok + +//// [blockScopedFunctionDeclarationInStrictModule.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + if (true) { + function foo() { } + foo(); // ok + } +}); diff --git a/tests/cases/compiler/blockScopedFunctionDeclarationInStrictClass.ts b/tests/cases/compiler/blockScopedFunctionDeclarationInStrictClass.ts new file mode 100644 index 00000000000..48d83e6ad87 --- /dev/null +++ b/tests/cases/compiler/blockScopedFunctionDeclarationInStrictClass.ts @@ -0,0 +1,10 @@ +// @target: ES5 +class c { + method() { + if (true) { + function foo() { } + foo(); // ok + } + foo(); // not ok + } +} \ No newline at end of file diff --git a/tests/cases/compiler/blockScopedFunctionDeclarationInStrictModule.ts b/tests/cases/compiler/blockScopedFunctionDeclarationInStrictModule.ts new file mode 100644 index 00000000000..48c68770620 --- /dev/null +++ b/tests/cases/compiler/blockScopedFunctionDeclarationInStrictModule.ts @@ -0,0 +1,8 @@ +// @target: ES5 +// @module: amd +if (true) { + function foo() { } + foo(); // ok +} + +export = foo; // not ok \ No newline at end of file