Test cases for type annotation visibility errors

This commit is contained in:
Sheetal Nandi 2014-11-10 18:10:00 -08:00
parent c661ffa7ec
commit 5664b6fcf9
12 changed files with 1123 additions and 0 deletions

View File

@ -0,0 +1,133 @@
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(16,21): error TS4043: Return type of public property getter from exported class has or is using private name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(21,13): error TS4043: Return type of public property getter from exported class has or is using private name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(26,25): error TS4037: Parameter 'foo3' of public property setter from exported class has or is using private name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(33,25): error TS4037: Parameter 'foo4' of public property setter from exported class has or is using private name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(37,21): error TS4043: Return type of public property getter from exported class has or is using private name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(72,23): error TS4043: Return type of public property getter from exported class has or is using private name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(77,13): error TS4042: Return type of public property getter from exported class has or is using name 'm2.public2' from private module 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(82,27): error TS4037: Parameter 'foo113' of public property setter from exported class has or is using private name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(89,27): error TS4037: Parameter 'foo114' of public property setter from exported class has or is using private name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(93,23): error TS4043: Return type of public property getter from exported class has or is using private name 'm2'.
==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts (10 errors) ====
module m {
class private1 {
}
export class public1 {
}
module m2 {
export class public2 {
}
}
export class c {
// getter with annotation
get foo1(): private1 {
~~~~~~~~
!!! error TS4043: Return type of public property getter from exported class has or is using private name 'private1'.
return;
}
// getter without annotation
get foo2() {
~~~~
!!! error TS4043: Return type of public property getter from exported class has or is using private name 'private1'.
return new private1();
}
// setter with annotation
set foo3(param: private1) {
~~~~~~~~
!!! error TS4037: Parameter 'foo3' of public property setter from exported class has or is using private name 'private1'.
}
// Both - getter without annotation, setter with annotation
get foo4() {
return new private1();
}
set foo4(param: private1) {
~~~~~~~~
!!! error TS4037: Parameter 'foo4' of public property setter from exported class has or is using private name 'private1'.
}
// Both - with annotation
get foo5(): private1 {
~~~~~~~~
!!! error TS4043: Return type of public property getter from exported class has or is using private name 'private1'.
return;
}
set foo5(param: private1) {
}
// getter with annotation
get foo11(): public1 {
return;
}
// getter without annotation
get foo12() {
return new public1();
}
// setter with annotation
set foo13(param: public1) {
}
// Both - getter without annotation, setter with annotation
get foo14() {
return new public1();
}
set foo14(param: public1) {
}
// Both - with annotation
get foo15(): public1 {
return;
}
set foo15(param: public1) {
}
// getter with annotation
get foo111(): m2.public2 {
~~~~~~~~~~
!!! error TS4043: Return type of public property getter from exported class has or is using private name 'm2'.
return;
}
// getter without annotation
get foo112() {
~~~~~~
!!! error TS4042: Return type of public property getter from exported class has or is using name 'm2.public2' from private module 'm2'.
return new m2.public2();
}
// setter with annotation
set foo113(param: m2.public2) {
~~~~~~~~~~
!!! error TS4037: Parameter 'foo113' of public property setter from exported class has or is using private name 'm2'.
}
// Both - getter without annotation, setter with annotation
get foo114() {
return new m2.public2();
}
set foo114(param: m2.public2) {
~~~~~~~~~~
!!! error TS4037: Parameter 'foo114' of public property setter from exported class has or is using private name 'm2'.
}
// Both - with annotation
get foo115(): m2.public2 {
~~~~~~~~~~
!!! error TS4043: Return type of public property getter from exported class has or is using private name 'm2'.
return;
}
set foo115(param: m2.public2) {
}
}
}

View File

@ -0,0 +1,261 @@
//// [declFileTypeAnnotationVisibilityErrorAccessors.ts]
module m {
class private1 {
}
export class public1 {
}
module m2 {
export class public2 {
}
}
export class c {
// getter with annotation
get foo1(): private1 {
return;
}
// getter without annotation
get foo2() {
return new private1();
}
// setter with annotation
set foo3(param: private1) {
}
// Both - getter without annotation, setter with annotation
get foo4() {
return new private1();
}
set foo4(param: private1) {
}
// Both - with annotation
get foo5(): private1 {
return;
}
set foo5(param: private1) {
}
// getter with annotation
get foo11(): public1 {
return;
}
// getter without annotation
get foo12() {
return new public1();
}
// setter with annotation
set foo13(param: public1) {
}
// Both - getter without annotation, setter with annotation
get foo14() {
return new public1();
}
set foo14(param: public1) {
}
// Both - with annotation
get foo15(): public1 {
return;
}
set foo15(param: public1) {
}
// getter with annotation
get foo111(): m2.public2 {
return;
}
// getter without annotation
get foo112() {
return new m2.public2();
}
// setter with annotation
set foo113(param: m2.public2) {
}
// Both - getter without annotation, setter with annotation
get foo114() {
return new m2.public2();
}
set foo114(param: m2.public2) {
}
// Both - with annotation
get foo115(): m2.public2 {
return;
}
set foo115(param: m2.public2) {
}
}
}
//// [declFileTypeAnnotationVisibilityErrorAccessors.js]
var m;
(function (m) {
var private1 = (function () {
function private1() {
}
return private1;
})();
var public1 = (function () {
function public1() {
}
return public1;
})();
m.public1 = public1;
var m2;
(function (m2) {
var public2 = (function () {
function public2() {
}
return public2;
})();
m2.public2 = public2;
})(m2 || (m2 = {}));
var c = (function () {
function c() {
}
Object.defineProperty(c.prototype, "foo1", {
// getter with annotation
get: function () {
return;
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo2", {
// getter without annotation
get: function () {
return new private1();
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo3", {
// setter with annotation
set: function (param) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo4", {
// Both - getter without annotation, setter with annotation
get: function () {
return new private1();
},
set: function (param) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo5", {
// Both - with annotation
get: function () {
return;
},
set: function (param) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo11", {
// getter with annotation
get: function () {
return;
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo12", {
// getter without annotation
get: function () {
return new public1();
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo13", {
// setter with annotation
set: function (param) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo14", {
// Both - getter without annotation, setter with annotation
get: function () {
return new public1();
},
set: function (param) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo15", {
// Both - with annotation
get: function () {
return;
},
set: function (param) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo111", {
// getter with annotation
get: function () {
return;
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo112", {
// getter without annotation
get: function () {
return new m2.public2();
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo113", {
// setter with annotation
set: function (param) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo114", {
// Both - getter without annotation, setter with annotation
get: function () {
return new m2.public2();
},
set: function (param) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(c.prototype, "foo115", {
// Both - with annotation
get: function () {
return;
},
set: function (param) {
},
enumerable: true,
configurable: true
});
return c;
})();
m.c = c;
})(m || (m = {}));

View File

@ -0,0 +1,60 @@
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorParameterOfFunction.ts(15,34): error TS4078: Parameter 'param' of exported function has or is using private name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorParameterOfFunction.ts(17,26): error TS4078: Parameter 'param' of exported function has or is using private name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorParameterOfFunction.ts(40,35): error TS4078: Parameter 'param' of exported function has or is using private name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorParameterOfFunction.ts(42,28): error TS4077: Parameter 'param' of exported function has or is using name 'm2.public2' from private module 'm2'.
==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorParameterOfFunction.ts (4 errors) ====
module m {
class private1 {
}
export class public1 {
}
// Directly using names from this module
function foo1(param: private1) {
}
function foo2(param = new private1()) {
}
export function foo3(param : private1) {
~~~~~~~~
!!! error TS4078: Parameter 'param' of exported function has or is using private name 'private1'.
}
export function foo4(param = new private1()) {
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4078: Parameter 'param' of exported function has or is using private name 'private1'.
}
function foo11(param: public1) {
}
function foo12(param = new public1()) {
}
export function foo13(param: public1) {
}
export function foo14(param = new public1()) {
}
module m2 {
export class public2 {
}
}
function foo111(param: m2.public2) {
}
function foo112(param = new m2.public2()) {
}
export function foo113(param: m2.public2) {
~~~~~~~~~~
!!! error TS4078: Parameter 'param' of exported function has or is using private name 'm2'.
}
export function foo114(param = new m2.public2()) {
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4077: Parameter 'param' of exported function has or is using name 'm2.public2' from private module 'm2'.
}
}

View File

@ -0,0 +1,108 @@
//// [declFileTypeAnnotationVisibilityErrorParameterOfFunction.ts]
module m {
class private1 {
}
export class public1 {
}
// Directly using names from this module
function foo1(param: private1) {
}
function foo2(param = new private1()) {
}
export function foo3(param : private1) {
}
export function foo4(param = new private1()) {
}
function foo11(param: public1) {
}
function foo12(param = new public1()) {
}
export function foo13(param: public1) {
}
export function foo14(param = new public1()) {
}
module m2 {
export class public2 {
}
}
function foo111(param: m2.public2) {
}
function foo112(param = new m2.public2()) {
}
export function foo113(param: m2.public2) {
}
export function foo114(param = new m2.public2()) {
}
}
//// [declFileTypeAnnotationVisibilityErrorParameterOfFunction.js]
var m;
(function (m) {
var private1 = (function () {
function private1() {
}
return private1;
})();
var public1 = (function () {
function public1() {
}
return public1;
})();
m.public1 = public1;
// Directly using names from this module
function foo1(param) {
}
function foo2(param) {
if (param === void 0) { param = new private1(); }
}
function foo3(param) {
}
m.foo3 = foo3;
function foo4(param) {
if (param === void 0) { param = new private1(); }
}
m.foo4 = foo4;
function foo11(param) {
}
function foo12(param) {
if (param === void 0) { param = new public1(); }
}
function foo13(param) {
}
m.foo13 = foo13;
function foo14(param) {
if (param === void 0) { param = new public1(); }
}
m.foo14 = foo14;
var m2;
(function (m2) {
var public2 = (function () {
function public2() {
}
return public2;
})();
m2.public2 = public2;
})(m2 || (m2 = {}));
function foo111(param) {
}
function foo112(param) {
if (param === void 0) { param = new m2.public2(); }
}
function foo113(param) {
}
m.foo113 = foo113;
function foo114(param) {
if (param === void 0) { param = new m2.public2(); }
}
m.foo114 = foo114;
})(m || (m = {}));

View File

@ -0,0 +1,72 @@
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.ts(17,29): error TS4060: Return type of exported function has or is using private name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.ts(20,21): error TS4060: Return type of exported function has or is using private name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.ts(50,31): error TS4060: Return type of exported function has or is using private name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.ts(53,21): error TS4059: Return type of exported function has or is using name 'm2.public2' from private module 'm2'.
==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.ts (4 errors) ====
module m {
class private1 {
}
export class public1 {
}
// Directly using names from this module
function foo1(): private1 {
return;
}
function foo2() {
return new private1();
}
export function foo3(): private1 {
~~~~~~~~
!!! error TS4060: Return type of exported function has or is using private name 'private1'.
return;
}
export function foo4() {
~~~~
!!! error TS4060: Return type of exported function has or is using private name 'private1'.
return new private1();
}
function foo11(): public1 {
return;
}
function foo12() {
return new public1();
}
export function foo13(): public1 {
return;
}
export function foo14() {
return new public1();
}
module m2 {
export class public2 {
}
}
function foo111(): m2.public2 {
return;
}
function foo112() {
return new m2.public2();
}
export function foo113(): m2.public2 {
~~~~~~~~~~
!!! error TS4060: Return type of exported function has or is using private name 'm2'.
return;
}
export function foo114() {
~~~~~~
!!! error TS4059: Return type of exported function has or is using name 'm2.public2' from private module 'm2'.
return new m2.public2();
}
}

View File

@ -0,0 +1,126 @@
//// [declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.ts]
module m {
class private1 {
}
export class public1 {
}
// Directly using names from this module
function foo1(): private1 {
return;
}
function foo2() {
return new private1();
}
export function foo3(): private1 {
return;
}
export function foo4() {
return new private1();
}
function foo11(): public1 {
return;
}
function foo12() {
return new public1();
}
export function foo13(): public1 {
return;
}
export function foo14() {
return new public1();
}
module m2 {
export class public2 {
}
}
function foo111(): m2.public2 {
return;
}
function foo112() {
return new m2.public2();
}
export function foo113(): m2.public2 {
return;
}
export function foo114() {
return new m2.public2();
}
}
//// [declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.js]
var m;
(function (m) {
var private1 = (function () {
function private1() {
}
return private1;
})();
var public1 = (function () {
function public1() {
}
return public1;
})();
m.public1 = public1;
// Directly using names from this module
function foo1() {
return;
}
function foo2() {
return new private1();
}
function foo3() {
return;
}
m.foo3 = foo3;
function foo4() {
return new private1();
}
m.foo4 = foo4;
function foo11() {
return;
}
function foo12() {
return new public1();
}
function foo13() {
return;
}
m.foo13 = foo13;
function foo14() {
return new public1();
}
m.foo14 = foo14;
var m2;
(function (m2) {
var public2 = (function () {
function public2() {
}
return public2;
})();
m2.public2 = public2;
})(m2 || (m2 = {}));
function foo111() {
return;
}
function foo112() {
return new m2.public2();
}
function foo113() {
return;
}
m.foo113 = foo113;
function foo114() {
return new m2.public2();
}
m.foo114 = foo114;
})(m || (m = {}));

View File

@ -0,0 +1,48 @@
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorVariableDeclaration.ts(13,19): error TS4025: Exported variable 'k' has or is using private name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorVariableDeclaration.ts(14,16): error TS4025: Exported variable 'l' has or is using private name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorVariableDeclaration.ts(30,20): error TS4025: Exported variable 'k3' has or is using private name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorVariableDeclaration.ts(31,16): error TS4024: Exported variable 'l3' has or is using name 'm2.public2' from private module 'm2'.
==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorVariableDeclaration.ts (4 errors) ====
module m {
class private1 {
}
export class public1 {
}
// Directly using names from this module
var x: private1;
var y = new private1();
export var k: private1;
~~~~~~~~
!!! error TS4025: Exported variable 'k' has or is using private name 'private1'.
export var l = new private1();
~
!!! error TS4025: Exported variable 'l' has or is using private name 'private1'.
var x2: public1;
var y2 = new public1();
export var k2: public1;
export var l2 = new public1();
module m2 {
export class public2 {
}
}
var x3: m2.public2;
var y3 = new m2.public2();
export var k3: m2.public2;
~~~~~~~~~~
!!! error TS4025: Exported variable 'k3' has or is using private name 'm2'.
export var l3 = new m2.public2();
~~
!!! error TS4024: Exported variable 'l3' has or is using name 'm2.public2' from private module 'm2'.
}

View File

@ -0,0 +1,72 @@
//// [declFileTypeAnnotationVisibilityErrorVariableDeclaration.ts]
module m {
class private1 {
}
export class public1 {
}
// Directly using names from this module
var x: private1;
var y = new private1();
export var k: private1;
export var l = new private1();
var x2: public1;
var y2 = new public1();
export var k2: public1;
export var l2 = new public1();
module m2 {
export class public2 {
}
}
var x3: m2.public2;
var y3 = new m2.public2();
export var k3: m2.public2;
export var l3 = new m2.public2();
}
//// [declFileTypeAnnotationVisibilityErrorVariableDeclaration.js]
var m;
(function (m) {
var private1 = (function () {
function private1() {
}
return private1;
})();
var public1 = (function () {
function public1() {
}
return public1;
})();
m.public1 = public1;
// Directly using names from this module
var x;
var y = new private1();
m.k;
m.l = new private1();
var x2;
var y2 = new public1();
m.k2;
m.l2 = new public1();
var m2;
(function (m2) {
var public2 = (function () {
function public2() {
}
return public2;
})();
m2.public2 = public2;
})(m2 || (m2 = {}));
var x3;
var y3 = new m2.public2();
m.k3;
m.l3 = new m2.public2();
})(m || (m = {}));

View File

@ -0,0 +1,102 @@
// @target: ES5
// @module: commonjs
// @declaration: true
module m {
class private1 {
}
export class public1 {
}
module m2 {
export class public2 {
}
}
export class c {
// getter with annotation
get foo1(): private1 {
return;
}
// getter without annotation
get foo2() {
return new private1();
}
// setter with annotation
set foo3(param: private1) {
}
// Both - getter without annotation, setter with annotation
get foo4() {
return new private1();
}
set foo4(param: private1) {
}
// Both - with annotation
get foo5(): private1 {
return;
}
set foo5(param: private1) {
}
// getter with annotation
get foo11(): public1 {
return;
}
// getter without annotation
get foo12() {
return new public1();
}
// setter with annotation
set foo13(param: public1) {
}
// Both - getter without annotation, setter with annotation
get foo14() {
return new public1();
}
set foo14(param: public1) {
}
// Both - with annotation
get foo15(): public1 {
return;
}
set foo15(param: public1) {
}
// getter with annotation
get foo111(): m2.public2 {
return;
}
// getter without annotation
get foo112() {
return new m2.public2();
}
// setter with annotation
set foo113(param: m2.public2) {
}
// Both - getter without annotation, setter with annotation
get foo114() {
return new m2.public2();
}
set foo114(param: m2.public2) {
}
// Both - with annotation
get foo115(): m2.public2 {
return;
}
set foo115(param: m2.public2) {
}
}
}

View File

@ -0,0 +1,47 @@
// @target: ES5
// @module: commonjs
// @declaration: true
module m {
class private1 {
}
export class public1 {
}
// Directly using names from this module
function foo1(param: private1) {
}
function foo2(param = new private1()) {
}
export function foo3(param : private1) {
}
export function foo4(param = new private1()) {
}
function foo11(param: public1) {
}
function foo12(param = new public1()) {
}
export function foo13(param: public1) {
}
export function foo14(param = new public1()) {
}
module m2 {
export class public2 {
}
}
function foo111(param: m2.public2) {
}
function foo112(param = new m2.public2()) {
}
export function foo113(param: m2.public2) {
}
export function foo114(param = new m2.public2()) {
}
}

View File

@ -0,0 +1,59 @@
// @target: ES5
// @module: commonjs
// @declaration: true
module m {
class private1 {
}
export class public1 {
}
// Directly using names from this module
function foo1(): private1 {
return;
}
function foo2() {
return new private1();
}
export function foo3(): private1 {
return;
}
export function foo4() {
return new private1();
}
function foo11(): public1 {
return;
}
function foo12() {
return new public1();
}
export function foo13(): public1 {
return;
}
export function foo14() {
return new public1();
}
module m2 {
export class public2 {
}
}
function foo111(): m2.public2 {
return;
}
function foo112() {
return new m2.public2();
}
export function foo113(): m2.public2 {
return;
}
export function foo114() {
return new m2.public2();
}
}

View File

@ -0,0 +1,35 @@
// @target: ES5
// @module: commonjs
// @declaration: true
module m {
class private1 {
}
export class public1 {
}
// Directly using names from this module
var x: private1;
var y = new private1();
export var k: private1;
export var l = new private1();
var x2: public1;
var y2 = new public1();
export var k2: public1;
export var l2 = new public1();
module m2 {
export class public2 {
}
}
var x3: m2.public2;
var y3 = new m2.public2();
export var k3: m2.public2;
export var l3 = new m2.public2();
}