Adding test cases for errors resulting because class/modules are strict

This commit is contained in:
Sheetal Nandi
2016-04-11 12:17:41 -07:00
parent 2db59d6753
commit 141dbb8986
6 changed files with 91 additions and 0 deletions

View File

@@ -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'.
}
}

View File

@@ -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;
}());

View File

@@ -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'.

View File

@@ -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
}
});

View File

@@ -0,0 +1,10 @@
// @target: ES5
class c {
method() {
if (true) {
function foo() { }
foo(); // ok
}
foo(); // not ok
}
}

View File

@@ -0,0 +1,8 @@
// @target: ES5
// @module: amd
if (true) {
function foo() { }
foo(); // ok
}
export = foo; // not ok