Repository navigation
Added support for static private fields accessors and methods. #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dragomirtitian
merged 47 commits into
es-private-methods-and-accessors
from
es-private-static-fields-methods-and-accessors
Mar 17, 2021
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
5ebb3d6
Added support for static private fields accessors and methods.
dragomirtitian 7006c09
Added error message for private identifiers used with static decorato…
dragomirtitian b876613
Fixed emit static bug that used private names outside of classes for …
dragomirtitian 31a8c00
Added tests for private static fields methods and accessors.
dragomirtitian 5a27a32
Merge remote-tracking branch 'remotes/bloomberg/es-private-methods-an…
dragomirtitian d2ab6fc
Merge branch 'es-private-methods-and-accessors' into es-private-stati…
dragomirtitian 23f6c67
Accept new baseline.
dragomirtitian 374e6f3
Improved duplicate identifier checks for static private class elements.
dragomirtitian 62b4f2f
Added error when using initializers with private static fields when u…
dragomirtitian b2a692d
Fixed code review issues.
dragomirtitian 363041e
Removed semantically wrong emit on `useDefineForClassFields:true` wit…
dragomirtitian 64757e0
Changed emit for uninitialized private static fields.
dragomirtitian 68a7f80
Added runtime error in helper if a static private field is accessed b…
dragomirtitian 7e7b0b1
Fixed code review comments for private identifier static class elements.
dragomirtitian 2834737
typo (#42899)
pushkine 82de139
Fixed typo error. (#42816)
0b337f1
Update project.ts (#42900)
pushkine 3d1c6e8
fix(42765): require should not work in ts files (#42792)
Zzzen c497b48
Add undefined to Symbol.valueDeclaration (#43033)
sandersn f1c911b
fix(43006): skip trivia in a function name (#43021)
a-tarasyuk 5dbb110
Baseline completions and signature help (#43049)
sandersn 0cf834c
Move fixed chunk size polling as a watch option and move it out of se…
sheetalkamat 6cd87d0
Delete old, different-case name of quickInfoJSDocTags.baseline (#43052)
sandersn 652199a
Added tests
armanio123 a8742e3
Update package-lock.json
typescript-bot 09a5aae
Merge branch 'es-private-methods-and-accessors' into es-private-stati…
dragomirtitian 497e47f
Fixed code review issues for private class elements.
dragomirtitian 7751ecb
fix receiver on calls of imported and exported functions (#35877)
ajafff 8a81a67
Merge pull request #43055 from armanio123/FixDefineForClassFields
armanio123 15e69ac
capture thisArg of optionalChaining in parens (#35494)
ajafff 3e05aa6
Update package-lock.json
typescript-bot 1f6a8d7
Do a shallow clone for Docker tests. (#42966)
DanielRosenwasser e234f0c
Update the DOM: March 03, 2021 (#43070)
sandersn 38fdce9
Expose 'reservedInNestedScopes' option when creating temp and loop va…
rbuckton ca8d9e4
fix(39836): allow type declaration/unknown type in catch arguments in…
a-tarasyuk 9862b03
Relax requirements on index signatures to 'any' when a type also cont…
DanielRosenwasser f0a72e2
Update package-lock.json
typescript-bot 408c804
Properly instantiate inferred constraints in conditional types (#42747)
ahejlsberg 25375a2
Unnecessary elaboration about not being assignable to type parameters…
jonhue 612a96e
Update parseInt parameter name and jsdoc (#42756)
sangxxh 7394efc
Update package-lock.json
typescript-bot ba56fca
Remove undefined from optional properties when inferring to index sig…
ahejlsberg f918bd9
Exclude enum/number compatibility rule from comparable relation (#42472)
ahejlsberg f7cd702
Update package-lock.json
typescript-bot 4d50624
Update package-lock.json
typescript-bot 294cc48
Fixes class shadowing when checking access to a private static class …
dragomirtitian 027bdb3
Merge remote-tracking branch 'remotes/origin/master' into es-private-…
dragomirtitian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added tests for private static fields methods and accessors.
- Loading branch information
commit 31a8c00fe6e574dff301a9430299f02d5068202c
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/privateNameStaticAccessors.errors.txt
This file contains hidden or 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,20 @@ | ||
| tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts(9,12): error TS2540: Cannot assign to '#roProp' because it is a read-only property. | ||
|
|
||
|
|
||
| ==== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts (1 errors) ==== | ||
| class A1 { | ||
| static get #prop() { return ""; } | ||
| static set #prop(param: string) { } | ||
|
|
||
| static get #roProp() { return ""; } | ||
|
|
||
| constructor(name: string) { | ||
| A1.#prop = ""; | ||
| A1.#roProp = ""; // Error | ||
| ~~~~~~~ | ||
| !!! error TS2540: Cannot assign to '#roProp' because it is a read-only property. | ||
| console.log(A1.#prop); | ||
| console.log(A1.#roProp); | ||
| } | ||
| } | ||
|
|
This file contains hidden or 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,44 @@ | ||
| //// [privateNameStaticAccessors.ts] | ||
| class A1 { | ||
| static get #prop() { return ""; } | ||
| static set #prop(param: string) { } | ||
|
|
||
| static get #roProp() { return ""; } | ||
|
|
||
| constructor(name: string) { | ||
| A1.#prop = ""; | ||
| A1.#roProp = ""; // Error | ||
| console.log(A1.#prop); | ||
| console.log(A1.#roProp); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| //// [privateNameStaticAccessors.js] | ||
| "use strict"; | ||
| var __classStaticPrivateAccessorSet = (this && this.__classStaticPrivateAccessorSet) || function (receiver, classConstructor, fn, value) { | ||
| if (receiver !== classConstructor) { | ||
| throw new TypeError("Private static access of wrong provenance"); | ||
| } | ||
| fn.call(receiver, value); | ||
| return value; | ||
| }; | ||
| var __classStaticPrivateReadonly = (this && this.__classStaticPrivateReadonly) || function () { | ||
| throw new TypeError("Private static element is not writable"); | ||
| }; | ||
| var __classStaticPrivateAccessorGet = (this && this.__classStaticPrivateAccessorGet) || function (receiver, classConstructor, fn) { | ||
| if (receiver !== classConstructor) { | ||
| throw new TypeError("Private static access of wrong provenance"); | ||
| } | ||
| return fn.call(receiver); | ||
| }; | ||
| var _A1_prop_get, _A1_prop_set, _A1_roProp_get; | ||
| class A1 { | ||
| constructor(name) { | ||
| __classStaticPrivateAccessorSet(A1, A1, _A1_prop_set, ""); | ||
| __classStaticPrivateReadonly(A1, ""); // Error | ||
| console.log(__classStaticPrivateAccessorGet(A1, A1, _A1_prop_get)); | ||
| console.log(__classStaticPrivateAccessorGet(A1, A1, _A1_roProp_get)); | ||
| } | ||
| } | ||
| _A1_prop_get = function _A1_prop_get() { return ""; }, _A1_prop_set = function _A1_prop_set(param) { }, _A1_roProp_get = function _A1_roProp_get() { return ""; }; | ||
41 changes: 41 additions & 0 deletions
41
tests/baselines/reference/privateNameStaticAccessors.symbols
This file contains hidden or 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,41 @@ | ||
| === tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts === | ||
| class A1 { | ||
| >A1 : Symbol(A1, Decl(privateNameStaticAccessors.ts, 0, 0)) | ||
|
|
||
| static get #prop() { return ""; } | ||
| >#prop : Symbol(A1.#prop, Decl(privateNameStaticAccessors.ts, 0, 10), Decl(privateNameStaticAccessors.ts, 1, 37)) | ||
|
|
||
| static set #prop(param: string) { } | ||
| >#prop : Symbol(A1.#prop, Decl(privateNameStaticAccessors.ts, 0, 10), Decl(privateNameStaticAccessors.ts, 1, 37)) | ||
| >param : Symbol(param, Decl(privateNameStaticAccessors.ts, 2, 21)) | ||
|
|
||
| static get #roProp() { return ""; } | ||
| >#roProp : Symbol(A1.#roProp, Decl(privateNameStaticAccessors.ts, 2, 39)) | ||
|
|
||
| constructor(name: string) { | ||
| >name : Symbol(name, Decl(privateNameStaticAccessors.ts, 6, 16)) | ||
|
|
||
| A1.#prop = ""; | ||
| >A1.#prop : Symbol(A1.#prop, Decl(privateNameStaticAccessors.ts, 0, 10), Decl(privateNameStaticAccessors.ts, 1, 37)) | ||
| >A1 : Symbol(A1, Decl(privateNameStaticAccessors.ts, 0, 0)) | ||
|
|
||
| A1.#roProp = ""; // Error | ||
| >A1.#roProp : Symbol(A1.#roProp, Decl(privateNameStaticAccessors.ts, 2, 39)) | ||
| >A1 : Symbol(A1, Decl(privateNameStaticAccessors.ts, 0, 0)) | ||
|
|
||
| console.log(A1.#prop); | ||
| >console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
| >console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
| >log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
| >A1.#prop : Symbol(A1.#prop, Decl(privateNameStaticAccessors.ts, 0, 10), Decl(privateNameStaticAccessors.ts, 1, 37)) | ||
| >A1 : Symbol(A1, Decl(privateNameStaticAccessors.ts, 0, 0)) | ||
|
|
||
| console.log(A1.#roProp); | ||
| >console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
| >console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
| >log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
| >A1.#roProp : Symbol(A1.#roProp, Decl(privateNameStaticAccessors.ts, 2, 39)) | ||
| >A1 : Symbol(A1, Decl(privateNameStaticAccessors.ts, 0, 0)) | ||
| } | ||
| } | ||
|
|
49 changes: 49 additions & 0 deletions
49
tests/baselines/reference/privateNameStaticAccessors.types
This file contains hidden or 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,49 @@ | ||
| === tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts === | ||
| class A1 { | ||
| >A1 : A1 | ||
|
|
||
| static get #prop() { return ""; } | ||
| >#prop : string | ||
| >"" : "" | ||
|
|
||
| static set #prop(param: string) { } | ||
| >#prop : string | ||
| >param : string | ||
|
|
||
| static get #roProp() { return ""; } | ||
| >#roProp : string | ||
| >"" : "" | ||
|
|
||
| constructor(name: string) { | ||
| >name : string | ||
|
|
||
| A1.#prop = ""; | ||
| >A1.#prop = "" : "" | ||
| >A1.#prop : string | ||
| >A1 : typeof A1 | ||
| >"" : "" | ||
|
|
||
| A1.#roProp = ""; // Error | ||
| >A1.#roProp = "" : "" | ||
| >A1.#roProp : any | ||
| >A1 : typeof A1 | ||
| >"" : "" | ||
|
|
||
| console.log(A1.#prop); | ||
| >console.log(A1.#prop) : void | ||
| >console.log : (...data: any[]) => void | ||
| >console : Console | ||
| >log : (...data: any[]) => void | ||
| >A1.#prop : string | ||
| >A1 : typeof A1 | ||
|
|
||
| console.log(A1.#roProp); | ||
| >console.log(A1.#roProp) : void | ||
| >console.log : (...data: any[]) => void | ||
| >console : Console | ||
| >log : (...data: any[]) => void | ||
| >A1.#roProp : string | ||
| >A1 : typeof A1 | ||
| } | ||
| } | ||
|
|
39 changes: 39 additions & 0 deletions
39
tests/baselines/reference/privateNameStaticAccessorsAccess.errors.txt
This file contains hidden or 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,39 @@ | ||
| tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts(16,4): error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. | ||
| tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts(19,8): error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. | ||
| tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts(24,12): error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. | ||
|
|
||
|
|
||
| ==== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts (3 errors) ==== | ||
| export {} | ||
| class A2 { | ||
| static get #prop() { return ""; } | ||
| static set #prop(param: string) { } | ||
|
|
||
| constructor() { | ||
| console.log(A2.#prop); | ||
| let a: typeof A2 = A2; | ||
| a.#prop; | ||
| function foo (){ | ||
| a.#prop; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| A2.#prop; // Error | ||
| ~~~~~ | ||
| !!! error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. | ||
|
|
||
| function foo (){ | ||
| A2.#prop; // Error | ||
| ~~~~~ | ||
| !!! error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. | ||
| } | ||
|
|
||
| class B2 { | ||
| m() { | ||
| A2.#prop; | ||
| ~~~~~ | ||
| !!! error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.