Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check descriptor before private field access (#12910)
* fix: check descriptor before private field access * add test cases
- Loading branch information
Showing
6 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...n-proposal-class-properties/test/fixtures/private-loose/access-before-declaration/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/); |
29 changes: 29 additions & 0 deletions
29
...-plugin-proposal-class-properties/test/fixtures/private/access-before-declaration/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/); |
29 changes: 29 additions & 0 deletions
29
...al-private-methods/test/fixtures/static-accessors-loose/access-before-declaration/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
expect(() => { | ||
class C { | ||
static #_ = new C; | ||
static get #p() { return C }; | ||
constructor() { | ||
C.#p; | ||
} | ||
} | ||
}).toThrow(/attempted to use private field on non-instance/); | ||
|
||
expect(() => { | ||
class C { | ||
static #_ = new C; | ||
static set #p(v) {}; | ||
constructor() { | ||
C.#p = 0; | ||
} | ||
} | ||
}).toThrow(/attempted to use private field on non-instance/); | ||
|
||
expect(() => { | ||
class C { | ||
static #_ = new C; | ||
static set #p(v) {}; | ||
constructor() { | ||
for (C.#p of [0]); | ||
} | ||
} | ||
}).toThrow(/attempted to use private field on non-instance/); |
29 changes: 29 additions & 0 deletions
29
...est/fixtures/static-accessors-privateFieldsAsProperties/access-before-declaration/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
expect(() => { | ||
class C { | ||
static #_ = new C; | ||
static get #p() { return C }; | ||
constructor() { | ||
C.#p; | ||
} | ||
} | ||
}).toThrow(/attempted to use private field on non-instance/); | ||
|
||
expect(() => { | ||
class C { | ||
static #_ = new C; | ||
static set #p(v) {}; | ||
constructor() { | ||
C.#p = 0; | ||
} | ||
} | ||
}).toThrow(/attempted to use private field on non-instance/); | ||
|
||
expect(() => { | ||
class C { | ||
static #_ = new C; | ||
static set #p(v) {}; | ||
constructor() { | ||
for (C.#p of [0]); | ||
} | ||
} | ||
}).toThrow(/attempted to use private field on non-instance/); |
29 changes: 29 additions & 0 deletions
29
...proposal-private-methods/test/fixtures/static-accessors/access-before-declaration/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
expect(() => { | ||
class C { | ||
static #_ = new C; | ||
static get #p() { return C }; | ||
constructor() { | ||
C.#p; | ||
} | ||
} | ||
}).toThrow(/attempted to get private static field before its declaration/); | ||
|
||
expect(() => { | ||
class C { | ||
static #_ = new C; | ||
static set #p(v) {}; | ||
constructor() { | ||
C.#p = 0; | ||
} | ||
} | ||
}).toThrow(/attempted to set private static field before its declaration/); | ||
|
||
expect(() => { | ||
class C { | ||
static #_ = new C; | ||
static set #p(v) {}; | ||
constructor() { | ||
for (C.#p of [0]); | ||
} | ||
} | ||
}).toThrow(/attempted to set private static field before its declaration/); |