Skip to content

Commit 32909bc

Browse files
committed
Tests for Stop destructuring assignment of private properties
1 parent 28640c8 commit 32909bc

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(12,13): error TS2341: Property 'priv' is private and only accessible within class 'K'.
2+
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(17,5): error TS2341: Property 'priv' is private and only accessible within class 'K'.
3+
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(18,5): error TS2445: Property 'prot' is protected and only accessible within class 'K' and its subclasses.
4+
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(19,5): error TS2341: Property 'privateMethod' is private and only accessible within class 'K'.
5+
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(20,5): error TS2341: Property 'priv' is private and only accessible within class 'K'.
6+
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(20,5): error TS2341: Property 'privateMethod' is private and only accessible within class 'K'.
7+
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(20,5): error TS2445: Property 'prot' is protected and only accessible within class 'K' and its subclasses.
8+
9+
10+
==== tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts (7 errors) ====
11+
class K {
12+
private priv;
13+
protected prot;
14+
private privateMethod() { }
15+
m() {
16+
let { priv: a, prot: b } = this; // ok
17+
let { priv, prot } = new K(); // ok
18+
}
19+
}
20+
class C extends K {
21+
m2() {
22+
let { priv: a } = this; // error
23+
~~~~~~~~~~~
24+
!!! error TS2341: Property 'priv' is private and only accessible within class 'K'.
25+
let { prot: b } = this; // ok
26+
}
27+
}
28+
let k = new K();
29+
let { priv } = k; // error
30+
~~~~~~~~
31+
!!! error TS2341: Property 'priv' is private and only accessible within class 'K'.
32+
let { prot } = k; // error
33+
~~~~~~~~
34+
!!! error TS2445: Property 'prot' is protected and only accessible within class 'K' and its subclasses.
35+
let { privateMethod } = k; // error
36+
~~~~~~~~~~~~~~~~~
37+
!!! error TS2341: Property 'privateMethod' is private and only accessible within class 'K'.
38+
let { priv: a, prot: b, privateMethod: f } = k; // error
39+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40+
!!! error TS2341: Property 'priv' is private and only accessible within class 'K'.
41+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42+
!!! error TS2341: Property 'privateMethod' is private and only accessible within class 'K'.
43+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44+
!!! error TS2445: Property 'prot' is protected and only accessible within class 'K' and its subclasses.
45+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//// [privateProtectedMembersAreNotAccessibleDestructuring.ts]
2+
class K {
3+
private priv;
4+
protected prot;
5+
private privateMethod() { }
6+
m() {
7+
let { priv: a, prot: b } = this; // ok
8+
let { priv, prot } = new K(); // ok
9+
}
10+
}
11+
class C extends K {
12+
m2() {
13+
let { priv: a } = this; // error
14+
let { prot: b } = this; // ok
15+
}
16+
}
17+
let k = new K();
18+
let { priv } = k; // error
19+
let { prot } = k; // error
20+
let { privateMethod } = k; // error
21+
let { priv: a, prot: b, privateMethod: f } = k; // error
22+
23+
24+
//// [privateProtectedMembersAreNotAccessibleDestructuring.js]
25+
var __extends = (this && this.__extends) || function (d, b) {
26+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
27+
function __() { this.constructor = d; }
28+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29+
};
30+
var K = (function () {
31+
function K() {
32+
}
33+
K.prototype.privateMethod = function () { };
34+
K.prototype.m = function () {
35+
var _a = this, a = _a.priv, b = _a.prot; // ok
36+
var _b = new K(), priv = _b.priv, prot = _b.prot; // ok
37+
};
38+
return K;
39+
}());
40+
var C = (function (_super) {
41+
__extends(C, _super);
42+
function C() {
43+
_super.apply(this, arguments);
44+
}
45+
C.prototype.m2 = function () {
46+
var a = this.priv; // error
47+
var b = this.prot; // ok
48+
};
49+
return C;
50+
}(K));
51+
var k = new K();
52+
var priv = k.priv; // error
53+
var prot = k.prot; // error
54+
var privateMethod = k.privateMethod; // error
55+
var a = k.priv, b = k.prot, f = k.privateMethod; // error
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class K {
2+
private priv;
3+
protected prot;
4+
private privateMethod() { }
5+
m() {
6+
let { priv: a, prot: b } = this; // ok
7+
let { priv, prot } = new K(); // ok
8+
}
9+
}
10+
class C extends K {
11+
m2() {
12+
let { priv: a } = this; // error
13+
let { prot: b } = this; // ok
14+
}
15+
}
16+
let k = new K();
17+
let { priv } = k; // error
18+
let { prot } = k; // error
19+
let { privateMethod } = k; // error
20+
let { priv: a, prot: b, privateMethod: f } = k; // error

0 commit comments

Comments
 (0)