mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 01:34:55 -06:00
Tests for Stop destructuring assignment of private properties
This commit is contained in:
parent
28640c8ae1
commit
32909bc6e5
@ -0,0 +1,45 @@
|
||||
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(12,13): error TS2341: Property 'priv' is private and only accessible within class 'K'.
|
||||
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(17,5): error TS2341: Property 'priv' is private and only accessible within class 'K'.
|
||||
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.
|
||||
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(19,5): error TS2341: Property 'privateMethod' is private and only accessible within class 'K'.
|
||||
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(20,5): error TS2341: Property 'priv' is private and only accessible within class 'K'.
|
||||
tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts(20,5): error TS2341: Property 'privateMethod' is private and only accessible within class 'K'.
|
||||
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.
|
||||
|
||||
|
||||
==== tests/cases/conformance/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring.ts (7 errors) ====
|
||||
class K {
|
||||
private priv;
|
||||
protected prot;
|
||||
private privateMethod() { }
|
||||
m() {
|
||||
let { priv: a, prot: b } = this; // ok
|
||||
let { priv, prot } = new K(); // ok
|
||||
}
|
||||
}
|
||||
class C extends K {
|
||||
m2() {
|
||||
let { priv: a } = this; // error
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2341: Property 'priv' is private and only accessible within class 'K'.
|
||||
let { prot: b } = this; // ok
|
||||
}
|
||||
}
|
||||
let k = new K();
|
||||
let { priv } = k; // error
|
||||
~~~~~~~~
|
||||
!!! error TS2341: Property 'priv' is private and only accessible within class 'K'.
|
||||
let { prot } = k; // error
|
||||
~~~~~~~~
|
||||
!!! error TS2445: Property 'prot' is protected and only accessible within class 'K' and its subclasses.
|
||||
let { privateMethod } = k; // error
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2341: Property 'privateMethod' is private and only accessible within class 'K'.
|
||||
let { priv: a, prot: b, privateMethod: f } = k; // error
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2341: Property 'priv' is private and only accessible within class 'K'.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2341: Property 'privateMethod' is private and only accessible within class 'K'.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2445: Property 'prot' is protected and only accessible within class 'K' and its subclasses.
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
//// [privateProtectedMembersAreNotAccessibleDestructuring.ts]
|
||||
class K {
|
||||
private priv;
|
||||
protected prot;
|
||||
private privateMethod() { }
|
||||
m() {
|
||||
let { priv: a, prot: b } = this; // ok
|
||||
let { priv, prot } = new K(); // ok
|
||||
}
|
||||
}
|
||||
class C extends K {
|
||||
m2() {
|
||||
let { priv: a } = this; // error
|
||||
let { prot: b } = this; // ok
|
||||
}
|
||||
}
|
||||
let k = new K();
|
||||
let { priv } = k; // error
|
||||
let { prot } = k; // error
|
||||
let { privateMethod } = k; // error
|
||||
let { priv: a, prot: b, privateMethod: f } = k; // error
|
||||
|
||||
|
||||
//// [privateProtectedMembersAreNotAccessibleDestructuring.js]
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
var K = (function () {
|
||||
function K() {
|
||||
}
|
||||
K.prototype.privateMethod = function () { };
|
||||
K.prototype.m = function () {
|
||||
var _a = this, a = _a.priv, b = _a.prot; // ok
|
||||
var _b = new K(), priv = _b.priv, prot = _b.prot; // ok
|
||||
};
|
||||
return K;
|
||||
}());
|
||||
var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
C.prototype.m2 = function () {
|
||||
var a = this.priv; // error
|
||||
var b = this.prot; // ok
|
||||
};
|
||||
return C;
|
||||
}(K));
|
||||
var k = new K();
|
||||
var priv = k.priv; // error
|
||||
var prot = k.prot; // error
|
||||
var privateMethod = k.privateMethod; // error
|
||||
var a = k.priv, b = k.prot, f = k.privateMethod; // error
|
||||
@ -0,0 +1,20 @@
|
||||
class K {
|
||||
private priv;
|
||||
protected prot;
|
||||
private privateMethod() { }
|
||||
m() {
|
||||
let { priv: a, prot: b } = this; // ok
|
||||
let { priv, prot } = new K(); // ok
|
||||
}
|
||||
}
|
||||
class C extends K {
|
||||
m2() {
|
||||
let { priv: a } = this; // error
|
||||
let { prot: b } = this; // ok
|
||||
}
|
||||
}
|
||||
let k = new K();
|
||||
let { priv } = k; // error
|
||||
let { prot } = k; // error
|
||||
let { privateMethod } = k; // error
|
||||
let { priv: a, prot: b, privateMethod: f } = k; // error
|
||||
Loading…
x
Reference in New Issue
Block a user