mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-27 04:48:33 -05:00
Adding test cases for errors resulting because class/modules are strict
This commit is contained in:
@@ -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'.
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}());
|
||||
@@ -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'.
|
||||
@@ -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
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
// @target: ES5
|
||||
class c {
|
||||
method() {
|
||||
if (true) {
|
||||
function foo() { }
|
||||
foo(); // ok
|
||||
}
|
||||
foo(); // not ok
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// @target: ES5
|
||||
// @module: amd
|
||||
if (true) {
|
||||
function foo() { }
|
||||
foo(); // ok
|
||||
}
|
||||
|
||||
export = foo; // not ok
|
||||
Reference in New Issue
Block a user