You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Added support for private identifier methods.
* Added tests for private methods.
* Added check to only not allow private name method signatures in anything except classes.
Changes objects literal checking to not bail on first private name found in object literal.
* Added private accessors tests
* Transform private methods
Signed-off-by: Kubilay Kahveci <[email protected]>
* Rename shouldTransformPrivateFields
Signed-off-by: Kubilay Kahveci <[email protected]>
* Accept baseline
Signed-off-by: Kubilay Kahveci <[email protected]>
* Use a single WeakSet for brand-check
Signed-off-by: Kubilay Kahveci <[email protected]>
* Accept baseline
Signed-off-by: Kubilay Kahveci <[email protected]>
* Add a test for using private methods in static field initializers
Signed-off-by: Kubilay Kahveci <[email protected]>
* Add breaking checker test
Private methods inside class expressions should not error.
Signed-off-by: Kubilay Kahveci <[email protected]>
* Add to instances once per-instance
Signed-off-by: Kubilay Kahveci <[email protected]>
* Accept baseline
Signed-off-by: Kubilay Kahveci <[email protected]>
* fix: evaluate receiver and rhs expressions before throwing on readonly assignment
Signed-off-by: Kubilay Kahveci <[email protected]>
* Add a test for evaluating rhs before readonly assignment
Signed-off-by: Kubilay Kahveci <[email protected]>
* Transpile private accessors
Signed-off-by: Kubilay Kahveci <[email protected]>
* Accept baseline
Signed-off-by: Kubilay Kahveci <[email protected]>
* fix: handle readonly/writeonly accessors
Signed-off-by: Kubilay Kahveci <[email protected]>
* accept baseline
Signed-off-by: Kubilay Kahveci <[email protected]>
* add a test for private setter without a getter
Signed-off-by: Kubilay Kahveci <[email protected]>
* fix: getAllUnscopedEmitHelpers
Signed-off-by: Kubilay Kahveci <[email protected]>
* fix: better handling of duplicate names
Signed-off-by: Kubilay Kahveci <[email protected]>
* Fixed wrong error message for private methods in class expressions.
* change error message
Signed-off-by: Kubilay Kahveci <[email protected]>
* add a test for async private methods with a higher target
Signed-off-by: Kubilay Kahveci <[email protected]>
* fix: setter assignment returns rhs value
Signed-off-by: Kubilay Kahveci <[email protected]>
* add a test for setter assignment return value
Signed-off-by: Kubilay Kahveci <[email protected]>
* fix: handle duplicate accessors
Signed-off-by: Kubilay Kahveci <[email protected]>
* add tests for duplicate accessors
Signed-off-by: Kubilay Kahveci <[email protected]>
* docs: add missing parameter docs
Signed-off-by: Kubilay Kahveci <[email protected]>
* Fixed failing test.
* baseline-accept: ordering changes
Signed-off-by: Kubilay Kahveci <[email protected]>
* fix: attach weakSetName to property declaration
Signed-off-by: Kubilay Kahveci <[email protected]>
* add a test for nested private methods
Signed-off-by: Kubilay Kahveci <[email protected]>
* add a test with any
Signed-off-by: Kubilay Kahveci <[email protected]>
* Added support for static private fields accessors and methods.
* Added error message for private identifiers used with static decorators. There is no spec to go with this behavior as of yet.
* Fixed emit static bug that used private names outside of classes for initialization in esnext. Fixed issue where nested privates produce incorrect brand check.
* Added tests for private static fields methods and accessors.
* Fixed error messages and tests after merge.
* Accept new baseline.
* Improved duplicate identifier checks for static private class elements.
* Added error when using initializers with private static fields when useDefineForClassFields is not specified and target is esnext.
* Fixed code review issues.
* Removed semantically wrong emit on `useDefineForClassFields:true` with `target:esnext`
* Changed emit for uninitialized private static fields.
* Added runtime error in helper if a static private field is accessed before it was declared.
* Fixed code review comments for private identifier static class elements.
* add debug.assertNever for unknown node type (#53)
* Fixed code review issues.
* Fixed code review issues for private class elements.
* Fixes class shadowing when checking access to a private static class element.
* fix private methods/accessors in class expr inside a loop
* collapse switch case
* fix class name
* simplify getPrivateMethodsAndAccessors
* remove findPreviousAccessorInfo
* lazily create weakSetName identifier
* do not allocate a node if not needed in visitMehodDeclaration (#55)
* Removed all the emit helpers for private identifier methods accessors and modified the existing helpers for get and set fields to do the same job.
* Simplified emit for private identifier class elements.
* do not clone the receiver (#57)
* leave bad code in for #constructor and duplicate private names (#58)
* Added check for WeakSet collision.
* Added error for using a set only accessor.
* update keyof tests and ?? (#62)
* replace ?? with ||
* update keyof tests
* fix emit helpers comments
* produce an error if private field helpers are not up to date
* add tests
* fix setter-only compound assignment
* fix tests
* fix duplicated trailing comments (#64)
* clear receiver pos and setTextRange on helper calls
Co-authored-by: Kubilay Kahveci <[email protected]>
Copy file name to clipboardexpand all lines: src/compiler/diagnosticMessages.json
+24-8
Original file line number
Diff line number
Diff line change
@@ -3288,6 +3288,26 @@
3288
3288
"category": "Error",
3289
3289
"code": 2802
3290
3290
},
3291
+
"Cannot assign to private method '{0}'. Private methods are not writable.": {
3292
+
"category": "Error",
3293
+
"code": 2803
3294
+
},
3295
+
"Duplicate identifier '{0}'. Static and instance elements cannot share the same private name.": {
3296
+
"category": "Error",
3297
+
"code": 2804
3298
+
},
3299
+
"Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag.": {
3300
+
"category": "Error",
3301
+
"code": 2805
3302
+
},
3303
+
"Private accessor was defined without a getter.": {
3304
+
"category": "Error",
3305
+
"code": 2806
3306
+
},
3307
+
"This syntax requires an imported helper named '{1}' with {2} parameters, which is not compatible with the one in '{0}'. Consider upgrading your version of '{0}'.": {
3308
+
"category": "Error",
3309
+
"code": 2807
3310
+
},
3291
3311
3292
3312
"Import declaration '{0}' is using private name '{1}'.": {
3293
3313
"category": "Error",
@@ -6338,14 +6358,6 @@
6338
6358
"category": "Error",
6339
6359
"code": 18019
6340
6360
},
6341
-
"A method cannot be named with a private identifier.": {
6342
-
"category": "Error",
6343
-
"code": 18022
6344
-
},
6345
-
"An accessor cannot be named with a private identifier.": {
6346
-
"category": "Error",
6347
-
"code": 18023
6348
-
},
6349
6361
"An enum member cannot be named with a private identifier.": {
6350
6362
"category": "Error",
6351
6363
"code": 18024
@@ -6389,5 +6401,9 @@
6389
6401
"Invalid value for 'jsxFragmentFactory'. '{0}' is not a valid identifier or qualified-name.": {
6390
6402
"category": "Error",
6391
6403
"code": 18035
6404
+
},
6405
+
"Class decorators can't be used with static private identifier. Consider removing the experimental decorator.": {
* @param receiver — The object from which the private member will be read.
836
+
* @param state — One of the following:
837
+
* - A WeakMap used to read a private instance field.
838
+
* - A WeakSet used as an instance brand for private instance methods and accessors.
839
+
* - A function value that should be the undecorated class constructor used to brand check private static fields, methods, and accessors.
840
+
* @param kind — (optional pre TS 4.3, required for TS 4.3+) One of the following values:
841
+
* - undefined — Indicates a private instance field (pre TS 4.3).
842
+
* - "f" — Indicates a private field (instance or static).
843
+
* - "m" — Indicates a private method (instance or static).
844
+
* - "a" — Indicates a private accessor (instance or static).
845
+
* @param f — (optional pre TS 4.3) Depends on the arguments for state and kind:
846
+
* - If kind is "m", this should be the function corresponding to the static or instance method.
847
+
* - If kind is "a", this should be the function corresponding to the getter method, or undefined if the getter was not defined.
848
+
* - If kind is "f" and state is a function, this should be an object holding the value of a static field, or undefined if the static field declaration has not yet been evaluated.
849
+
* Usage:
850
+
* This helper will only ever be used by the compiler in the following ways:
851
+
*
852
+
* Reading from a private instance field (pre TS 4.3):
853
+
* __classPrivateFieldGet(<any>, <WeakMap>)
854
+
*
855
+
* Reading from a private instance field (TS 4.3+):
856
+
* __classPrivateFieldGet(<any>, <WeakMap>, "f")
857
+
*
858
+
* Reading from a private instance get accessor (when defined, TS 4.3+):
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
826
-
if (!privateMap.has(receiver)) {
827
-
throw new TypeError("attempted to get private field on non-instance");
828
-
}
829
-
return privateMap.get(receiver);
886
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
887
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
888
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
889
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
830
890
};`
831
891
};
832
892
893
+
/**
894
+
* Parameters:
895
+
* @param receiver — The object on which the private member will be set.
896
+
* @param state — One of the following:
897
+
* - A WeakMap used to store a private instance field.
898
+
* - A WeakSet used as an instance brand for private instance methods and accessors.
899
+
* - A function value that should be the undecorated class constructor used to brand check private static fields, methods, and accessors.
900
+
* @param value — The value to set.
901
+
* @param kind — (optional pre TS 4.3, required for TS 4.3+) One of the following values:
902
+
* - undefined — Indicates a private instance field (pre TS 4.3).
903
+
* - "f" — Indicates a private field (instance or static).
904
+
* - "m" — Indicates a private method (instance or static).
905
+
* - "a" — Indicates a private accessor (instance or static).
906
+
* @param f — (optional pre TS 4.3) Depends on the arguments for state and kind:
907
+
* - If kind is "m", this should be the function corresponding to the static or instance method.
908
+
* - If kind is "a", this should be the function corresponding to the setter method, or undefined if the setter was not defined.
909
+
* - If kind is "f" and state is a function, this should be an object holding the value of a static field, or undefined if the static field declaration has not yet been evaluated.
910
+
* Usage:
911
+
* This helper will only ever be used by the compiler in the following ways:
912
+
*
913
+
* Writing to a private instance field (pre TS 4.3):
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
839
-
if (!privateMap.has(receiver)) {
840
-
throw new TypeError("attempted to set private field on non-instance");
841
-
}
842
-
privateMap.set(receiver, value);
843
-
return value;
949
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
950
+
if (kind === "m") throw new TypeError("Private method is not writable");
951
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
952
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
953
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
0 commit comments