check descriptor before private field access (#12910)
* fix: check descriptor before private field access * add test cases
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
C.#p;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
C.#p = 0;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
for (C.#p of [0]);
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
@@ -0,0 +1,29 @@
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
C.#p;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to get private static field before its declaration/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
C.#p = 0;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to set private static field before its declaration/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
for (C.#p of [0]);
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to set private static field before its declaration/);
|
||||
Reference in New Issue
Block a user