Skip to content

Commit 60b29e9

Browse files
committed
Merge pull request #730 from Microsoft/protectedConformanceTests
Added protected conformance tests
2 parents 647e68a + 1257257 commit 60b29e9

File tree

61 files changed

+3782
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3782
-8
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(22,12): error TS1029: 'private' modifier must precede 'static' modifier.
2+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(23,12): error TS1029: 'private' modifier must precede 'static' modifier.
3+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(24,12): error TS1029: 'private' modifier must precede 'static' modifier.
4+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(25,12): error TS1029: 'private' modifier must precede 'static' modifier.
5+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(27,12): error TS1029: 'protected' modifier must precede 'static' modifier.
6+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(28,12): error TS1029: 'protected' modifier must precede 'static' modifier.
7+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(29,12): error TS1029: 'protected' modifier must precede 'static' modifier.
8+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(30,12): error TS1029: 'protected' modifier must precede 'static' modifier.
9+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(32,12): error TS1029: 'public' modifier must precede 'static' modifier.
10+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(33,12): error TS1029: 'public' modifier must precede 'static' modifier.
11+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(34,12): error TS1029: 'public' modifier must precede 'static' modifier.
12+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(35,12): error TS1029: 'public' modifier must precede 'static' modifier.
13+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(40,13): error TS1028: Accessibility modifier already seen.
14+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(40,20): error TS1028: Accessibility modifier already seen.
15+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(41,12): error TS1028: Accessibility modifier already seen.
16+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(42,13): error TS1028: Accessibility modifier already seen.
17+
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(43,12): error TS1028: Accessibility modifier already seen.
18+
19+
20+
==== tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts (17 errors) ====
21+
22+
// No errors
23+
class C {
24+
private static privateProperty;
25+
private static privateMethod() { }
26+
private static get privateGetter() { return 0; }
27+
private static set privateSetter(a: number) { }
28+
29+
protected static protectedProperty;
30+
protected static protectedMethod() { }
31+
protected static get protectedGetter() { return 0; }
32+
protected static set protectedSetter(a: number) { }
33+
34+
public static publicProperty;
35+
public static publicMethod() { }
36+
public static get publicGetter() { return 0; }
37+
public static set publicSetter(a: number) { }
38+
}
39+
40+
// Errors, accessibility modifiers must precede static
41+
class D {
42+
static private privateProperty;
43+
~~~~~~~
44+
!!! error TS1029: 'private' modifier must precede 'static' modifier.
45+
static private privateMethod() { }
46+
~~~~~~~
47+
!!! error TS1029: 'private' modifier must precede 'static' modifier.
48+
static private get privateGetter() { return 0; }
49+
~~~~~~~
50+
!!! error TS1029: 'private' modifier must precede 'static' modifier.
51+
static private set privateSetter(a: number) { }
52+
~~~~~~~
53+
!!! error TS1029: 'private' modifier must precede 'static' modifier.
54+
55+
static protected protectedProperty;
56+
~~~~~~~~~
57+
!!! error TS1029: 'protected' modifier must precede 'static' modifier.
58+
static protected protectedMethod() { }
59+
~~~~~~~~~
60+
!!! error TS1029: 'protected' modifier must precede 'static' modifier.
61+
static protected get protectedGetter() { return 0; }
62+
~~~~~~~~~
63+
!!! error TS1029: 'protected' modifier must precede 'static' modifier.
64+
static protected set protectedSetter(a: number) { }
65+
~~~~~~~~~
66+
!!! error TS1029: 'protected' modifier must precede 'static' modifier.
67+
68+
static public publicProperty;
69+
~~~~~~
70+
!!! error TS1029: 'public' modifier must precede 'static' modifier.
71+
static public publicMethod() { }
72+
~~~~~~
73+
!!! error TS1029: 'public' modifier must precede 'static' modifier.
74+
static public get publicGetter() { return 0; }
75+
~~~~~~
76+
!!! error TS1029: 'public' modifier must precede 'static' modifier.
77+
static public set publicSetter(a: number) { }
78+
~~~~~~
79+
!!! error TS1029: 'public' modifier must precede 'static' modifier.
80+
}
81+
82+
// Errors, multiple accessibility modifier
83+
class E {
84+
private public protected property;
85+
~~~~~~
86+
!!! error TS1028: Accessibility modifier already seen.
87+
~~~~~~~~~
88+
!!! error TS1028: Accessibility modifier already seen.
89+
public protected method() { }
90+
~~~~~~~~~
91+
!!! error TS1028: Accessibility modifier already seen.
92+
private protected get getter() { return 0; }
93+
~~~~~~~~~
94+
!!! error TS1028: Accessibility modifier already seen.
95+
public public set setter(a: number) { }
96+
~~~~~~
97+
!!! error TS1028: Accessibility modifier already seen.
98+
}
99+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(3,9): error TS2379: Getter and setter accessors do not agree in visibility.
2+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(6,17): error TS2379: Getter and setter accessors do not agree in visibility.
3+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(11,19): error TS2379: Getter and setter accessors do not agree in visibility.
4+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(14,17): error TS2379: Getter and setter accessors do not agree in visibility.
5+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(19,19): error TS2379: Getter and setter accessors do not agree in visibility.
6+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(21,9): error TS2379: Getter and setter accessors do not agree in visibility.
7+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(27,26): error TS2379: Getter and setter accessors do not agree in visibility.
8+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(29,16): error TS2379: Getter and setter accessors do not agree in visibility.
9+
10+
11+
==== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts (8 errors) ====
12+
13+
class C {
14+
get x() {
15+
~
16+
!!! error TS2379: Getter and setter accessors do not agree in visibility.
17+
return 1;
18+
}
19+
private set x(v) {
20+
~
21+
!!! error TS2379: Getter and setter accessors do not agree in visibility.
22+
}
23+
}
24+
25+
class D {
26+
protected get x() {
27+
~
28+
!!! error TS2379: Getter and setter accessors do not agree in visibility.
29+
return 1;
30+
}
31+
private set x(v) {
32+
~
33+
!!! error TS2379: Getter and setter accessors do not agree in visibility.
34+
}
35+
}
36+
37+
class E {
38+
protected set x(v) {
39+
~
40+
!!! error TS2379: Getter and setter accessors do not agree in visibility.
41+
}
42+
get x() {
43+
~
44+
!!! error TS2379: Getter and setter accessors do not agree in visibility.
45+
return 1;
46+
}
47+
}
48+
49+
class F {
50+
protected static set x(v) {
51+
~
52+
!!! error TS2379: Getter and setter accessors do not agree in visibility.
53+
}
54+
static get x() {
55+
~
56+
!!! error TS2379: Getter and setter accessors do not agree in visibility.
57+
return 1;
58+
}
59+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//// [accessorWithMismatchedAccessibilityModifiers.ts]
2+
3+
class C {
4+
get x() {
5+
return 1;
6+
}
7+
private set x(v) {
8+
}
9+
}
10+
11+
class D {
12+
protected get x() {
13+
return 1;
14+
}
15+
private set x(v) {
16+
}
17+
}
18+
19+
class E {
20+
protected set x(v) {
21+
}
22+
get x() {
23+
return 1;
24+
}
25+
}
26+
27+
class F {
28+
protected static set x(v) {
29+
}
30+
static get x() {
31+
return 1;
32+
}
33+
}
34+
35+
//// [accessorWithMismatchedAccessibilityModifiers.js]
36+
var C = (function () {
37+
function C() {
38+
}
39+
Object.defineProperty(C.prototype, "x", {
40+
get: function () {
41+
return 1;
42+
},
43+
set: function (v) {
44+
},
45+
enumerable: true,
46+
configurable: true
47+
});
48+
return C;
49+
})();
50+
var D = (function () {
51+
function D() {
52+
}
53+
Object.defineProperty(D.prototype, "x", {
54+
get: function () {
55+
return 1;
56+
},
57+
set: function (v) {
58+
},
59+
enumerable: true,
60+
configurable: true
61+
});
62+
return D;
63+
})();
64+
var E = (function () {
65+
function E() {
66+
}
67+
Object.defineProperty(E.prototype, "x", {
68+
get: function () {
69+
return 1;
70+
},
71+
set: function (v) {
72+
},
73+
enumerable: true,
74+
configurable: true
75+
});
76+
return E;
77+
})();
78+
var F = (function () {
79+
function F() {
80+
}
81+
Object.defineProperty(F, "x", {
82+
get: function () {
83+
return 1;
84+
},
85+
set: function (v) {
86+
},
87+
enumerable: true,
88+
configurable: true
89+
});
90+
return F;
91+
})();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility.ts(12,1): error TS2341: Property 'p' is private and only accessible within class 'C2'.
2+
tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility.ts(19,1): error TS2445: Property 'p' is protected and only accessible within class 'C3' and its subclasses.
3+
4+
5+
==== tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility.ts (2 errors) ====
6+
class C1 {
7+
constructor(public x: number) { }
8+
}
9+
var c1: C1;
10+
c1.x // OK
11+
12+
13+
class C2 {
14+
constructor(private p: number) { }
15+
}
16+
var c2: C2;
17+
c2.p // private, error
18+
~~~~
19+
!!! error TS2341: Property 'p' is private and only accessible within class 'C2'.
20+
21+
22+
class C3 {
23+
constructor(protected p: number) { }
24+
}
25+
var c3: C3;
26+
c3.p // protected, error
27+
~~~~
28+
!!! error TS2445: Property 'p' is protected and only accessible within class 'C3' and its subclasses.
29+
class Derived extends C3 {
30+
constructor(p: number) {
31+
super(p);
32+
this.p; // OK
33+
}
34+
}
35+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//// [classConstructorParametersAccessibility.ts]
2+
class C1 {
3+
constructor(public x: number) { }
4+
}
5+
var c1: C1;
6+
c1.x // OK
7+
8+
9+
class C2 {
10+
constructor(private p: number) { }
11+
}
12+
var c2: C2;
13+
c2.p // private, error
14+
15+
16+
class C3 {
17+
constructor(protected p: number) { }
18+
}
19+
var c3: C3;
20+
c3.p // protected, error
21+
class Derived extends C3 {
22+
constructor(p: number) {
23+
super(p);
24+
this.p; // OK
25+
}
26+
}
27+
28+
29+
//// [classConstructorParametersAccessibility.js]
30+
var __extends = this.__extends || function (d, b) {
31+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
32+
function __() { this.constructor = d; }
33+
__.prototype = b.prototype;
34+
d.prototype = new __();
35+
};
36+
var C1 = (function () {
37+
function C1(x) {
38+
this.x = x;
39+
}
40+
return C1;
41+
})();
42+
var c1;
43+
c1.x; // OK
44+
var C2 = (function () {
45+
function C2(p) {
46+
this.p = p;
47+
}
48+
return C2;
49+
})();
50+
var c2;
51+
c2.p; // private, error
52+
var C3 = (function () {
53+
function C3(p) {
54+
this.p = p;
55+
}
56+
return C3;
57+
})();
58+
var c3;
59+
c3.p; // protected, error
60+
var Derived = (function (_super) {
61+
__extends(Derived, _super);
62+
function Derived(p) {
63+
_super.call(this, p);
64+
this.p; // OK
65+
}
66+
return Derived;
67+
})(C3);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility2.ts(12,1): error TS2341: Property 'p' is private and only accessible within class 'C2'.
2+
tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility2.ts(19,1): error TS2445: Property 'p' is protected and only accessible within class 'C3' and its subclasses.
3+
4+
5+
==== tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility2.ts (2 errors) ====
6+
class C1 {
7+
constructor(public x?: number) { }
8+
}
9+
var c1: C1;
10+
c1.x // OK
11+
12+
13+
class C2 {
14+
constructor(private p?: number) { }
15+
}
16+
var c2: C2;
17+
c2.p // private, error
18+
~~~~
19+
!!! error TS2341: Property 'p' is private and only accessible within class 'C2'.
20+
21+
22+
class C3 {
23+
constructor(protected p?: number) { }
24+
}
25+
var c3: C3;
26+
c3.p // protected, error
27+
~~~~
28+
!!! error TS2445: Property 'p' is protected and only accessible within class 'C3' and its subclasses.
29+
class Derived extends C3 {
30+
constructor(p: number) {
31+
super(p);
32+
this.p; // OK
33+
}
34+
}
35+

0 commit comments

Comments
 (0)