- Notifications
You must be signed in to change notification settings - Fork13.2k
ES private class elements#42458
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
e3a3fb84ab27a26977b9fbc8c07e2760ed804af85df048d72f8cfb814aa4c3b0ac12717da5bd9e133f60aa5dd8aa3889a78952caadee87bbaec7e9bf3bbf0fa1b59cd6b74498d51f6cdc1757704301af53a056b295df2d1590124e219ea8325da8caa2228beff4f737704727c73925dc67fd38d45c2a41356b91db3914645ebb3d67006c09b87661331a8c009219e995a27a32964fc27d2ab6fc23f6c67374e6f362b4f2fb2a692d363041e64757e068a7f807e7b0b130c7f69c924058e65116f4748c8709a5aae497e47f294cc48027bdb37bbc944dd526e7f6ecfab6c3f661ef69c6c2a646edd8136f7fbd749cf96eafe2de8a437490a36c2732581addbb3c461b92a61fd5f89f746aff24636a60e429f5816ab3b62d3c7d8a2b9d0d205593a7ca36da2cdd30805b78d77a8e8078ae0File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Diff view
Diff view
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -32,8 +32,8 @@ namespace ts { | ||
| createImportDefaultHelper(expression: Expression): Expression; | ||
| createExportStarHelper(moduleExpression: Expression, exportsExpression?: Expression): Expression; | ||
| // Class Fields Helpers | ||
| createClassPrivateFieldGetHelper(receiver: Expression,state: Identifier, kind: PrivateIdentifierKind, f: Identifier | undefined): Expression; | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. We may need a test in checker that verifies the parameter count of Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I see Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Added this in7d8a2b9. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
That's precisely what I was describing, yes. | ||
| createClassPrivateFieldSetHelper(receiver: Expression,state: Identifier, value: Expression, kind: PrivateIdentifierKind, f: Identifier | undefined): Expression; | ||
| } | ||
| export function createEmitHelperFactory(context: TransformationContext): EmitHelperFactory { | ||
| @@ -368,15 +368,30 @@ namespace ts { | ||
| // Class Fields Helpers | ||
| function createClassPrivateFieldGetHelper(receiver: Expression,state: Identifier, kind: PrivateIdentifierKind, f: Identifier | undefined) { | ||
| context.requestEmitHelper(classPrivateFieldGetHelper); | ||
| let args; | ||
| if (!f) { | ||
| args = [receiver, state, factory.createStringLiteral(kind)]; | ||
| } | ||
| else { | ||
| args = [receiver, state, factory.createStringLiteral(kind), f]; | ||
| } | ||
| return factory.createCallExpression(getUnscopedHelperName("__classPrivateFieldGet"), /*typeArguments*/ undefined, args); | ||
| } | ||
| function createClassPrivateFieldSetHelper(receiver: Expression,state: Identifier, value: Expression, kind: PrivateIdentifierKind, f: Identifier | undefined) { | ||
| context.requestEmitHelper(classPrivateFieldSetHelper); | ||
| let args; | ||
| if (!f) { | ||
| args = [receiver, state, value, factory.createStringLiteral(kind)]; | ||
| } | ||
| else { | ||
| args = [receiver, state, value, factory.createStringLiteral(kind), f]; | ||
| } | ||
| return factory.createCallExpression(getUnscopedHelperName("__classPrivateFieldSet"), /*typeArguments*/ undefined, args); | ||
| } | ||
| } | ||
| /* @internal */ | ||
| @@ -803,7 +818,6 @@ namespace ts { | ||
| };` | ||
| }; | ||
| export const exportStarHelper: UnscopedEmitHelper = { | ||
| name: "typescript:export-star", | ||
| importName: "__exportStar", | ||
| @@ -816,31 +830,127 @@ namespace ts { | ||
| };` | ||
| }; | ||
| /** | ||
| * Parameters: | ||
| * @param receiver — The object from which the private member will be read. | ||
| * @param state — One of the following: | ||
| * - A WeakMap used to read a private instance field. | ||
| * - A WeakSet used as an instance brand for private instance methods and accessors. | ||
| * - A function value that should be the undecorated class constructor used to brand check private static fields, methods, and accessors. | ||
| * @param kind — (optional pre TS 4.3, required for TS 4.3+) One of the following values: | ||
| * - undefined — Indicates a private instance field (pre TS 4.3). | ||
| * - "f" — Indicates a private field (instance or static). | ||
| * - "m" — Indicates a private method (instance or static). | ||
| * - "a" — Indicates a private accessor (instance or static). | ||
| * @param f — (optional pre TS 4.3) Depends on the arguments for state and kind: | ||
| * - If kind is "m", this should be the function corresponding to the static or instance method. | ||
| * - If kind is "a", this should be the function corresponding to the getter method, or undefined if the getter was not defined. | ||
| * - 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. | ||
| * Usage: | ||
| * This helper will only ever be used by the compiler in the following ways: | ||
| * | ||
| * Reading from a private instance field (pre TS 4.3): | ||
| * __classPrivateFieldGet(<any>, <WeakMap>) | ||
| * | ||
| * Reading from a private instance field (TS 4.3+): | ||
| * __classPrivateFieldGet(<any>, <WeakMap>, "f") | ||
| * | ||
| * Reading from a private instance get accessor (when defined, TS 4.3+): | ||
| * __classPrivateFieldGet(<any>, <WeakSet>, "a", <function>) | ||
| * | ||
| * Reading from a private instance get accessor (when not defined, TS 4.3+): | ||
| * __classPrivateFieldGet(<any>, <WeakSet>, "a", void 0) | ||
| * NOTE: This always results in a runtime error. | ||
| * | ||
| * Reading from a private instance method (TS 4.3+): | ||
| * __classPrivateFieldGet(<any>, <WeakSet>, "m", <function>) | ||
| * | ||
| * Reading from a private static field (TS 4.3+): | ||
| * __classPrivateFieldGet(<any>, <constructor>, "f", <{ value: any }>) | ||
| * | ||
| * Reading from a private static get accessor (when defined, TS 4.3+): | ||
| * __classPrivateFieldGet(<any>, <constructor>, "a", <function>) | ||
| * | ||
| * Reading from a private static get accessor (when not defined, TS 4.3+): | ||
| * __classPrivateFieldGet(<any>, <constructor>, "a", void 0) | ||
| * NOTE: This always results in a runtime error. | ||
| * | ||
| * Reading from a private static method (TS 4.3+): | ||
| * __classPrivateFieldGet(<any>, <constructor>, "m", <function>) | ||
| */ | ||
| export const classPrivateFieldGetHelper: UnscopedEmitHelper = { | ||
| name: "typescript:classPrivateFieldGet", | ||
| importName: "__classPrivateFieldGet", | ||
| scoped: false, | ||
| text: ` | ||
| var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
| if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
| 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"); | ||
| return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
| };` | ||
| }; | ||
| /** | ||
| * Parameters: | ||
| * @param receiver — The object on which the private member will be set. | ||
| * @param state — One of the following: | ||
| * - A WeakMap used to store a private instance field. | ||
| * - A WeakSet used as an instance brand for private instance methods and accessors. | ||
| * - A function value that should be the undecorated class constructor used to brand check private static fields, methods, and accessors. | ||
| * @param value — The value to set. | ||
| * @param kind — (optional pre TS 4.3, required for TS 4.3+) One of the following values: | ||
| * - undefined — Indicates a private instance field (pre TS 4.3). | ||
| * - "f" — Indicates a private field (instance or static). | ||
| * - "m" — Indicates a private method (instance or static). | ||
| * - "a" — Indicates a private accessor (instance or static). | ||
| * @param f — (optional pre TS 4.3) Depends on the arguments for state and kind: | ||
| * - If kind is "m", this should be the function corresponding to the static or instance method. | ||
| * - If kind is "a", this should be the function corresponding to the setter method, or undefined if the setter was not defined. | ||
| * - 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. | ||
| * Usage: | ||
| * This helper will only ever be used by the compiler in the following ways: | ||
| * | ||
| * Writing to a private instance field (pre TS 4.3): | ||
| * __classPrivateFieldSet(<any>, <WeakMap>, <any>) | ||
| * | ||
| * Writing to a private instance field (TS 4.3+): | ||
| * __classPrivateFieldSet(<any>, <WeakMap>, <any>, "f") | ||
| * | ||
| * Writing to a private instance set accessor (when defined, TS 4.3+): | ||
| * __classPrivateFieldSet(<any>, <WeakSet>, <any>, "a", <function>) | ||
| * | ||
| * Writing to a private instance set accessor (when not defined, TS 4.3+): | ||
| * __classPrivateFieldSet(<any>, <WeakSet>, <any>, "a", void 0) | ||
| * NOTE: This always results in a runtime error. | ||
| * | ||
| * Writing to a private instance method (TS 4.3+): | ||
| * __classPrivateFieldSet(<any>, <WeakSet>, <any>, "m", <function>) | ||
| * NOTE: This always results in a runtime error. | ||
| * | ||
| * Writing to a private static field (TS 4.3+): | ||
| * __classPrivateFieldSet(<any>, <constructor>, <any>, "f", <{ value: any }>) | ||
| * | ||
| * Writing to a private static set accessor (when defined, TS 4.3+): | ||
| * __classPrivateFieldSet(<any>, <constructor>, <any>, "a", <function>) | ||
| * | ||
| * Writing to a private static set accessor (when not defined, TS 4.3+): | ||
| * __classPrivateFieldSet(<any>, <constructor>, <any>, "a", void 0) | ||
| * NOTE: This always results in a runtime error. | ||
| * | ||
| * Writing to a private static method (TS 4.3+): | ||
| * __classPrivateFieldSet(<any>, <constructor>, <any>, "m", <function>) | ||
| * NOTE: This always results in a runtime error. | ||
| */ | ||
| export const classPrivateFieldSetHelper: UnscopedEmitHelper = { | ||
| name: "typescript:classPrivateFieldSet", | ||
| importName: "__classPrivateFieldSet", | ||
| scoped: false, | ||
| text: ` | ||
| var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
| if (kind === "m") throw new TypeError("Private method is not writable"); | ||
| if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
| 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"); | ||
| return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
| };` | ||
| }; | ||
| @@ -897,4 +1007,4 @@ namespace ts { | ||
| && (getEmitFlags(firstSegment.expression) & EmitFlags.HelperName) | ||
| && firstSegment.expression.escapedText === helperName; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading.Please reload this page.