René's URL Explorer Experiment


Title: SES compatibility for '--emitDecoratorMetadata' · Issue #43463 · microsoft/TypeScript · GitHub

Open Graph Title: SES compatibility for '--emitDecoratorMetadata' · Issue #43463 · microsoft/TypeScript

X Title: SES compatibility for '--emitDecoratorMetadata' · Issue #43463 · microsoft/TypeScript

Description: Suggestion 🔍 Search Terms ses reflect metadata decorator emitDecoratorMetadata experimentalDecorators ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn't change the runtime behavi...

Open Graph Description: Suggestion 🔍 Search Terms ses reflect metadata decorator emitDecoratorMetadata experimentalDecorators ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code...

X Description: Suggestion 🔍 Search Terms ses reflect metadata decorator emitDecoratorMetadata experimentalDecorators ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript ...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/43463

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SES compatibility for '--emitDecoratorMetadata'","articleBody":"# Suggestion\r\n\r\n## 🔍 Search Terms\r\n\r\nses reflect metadata decorator emitDecoratorMetadata experimentalDecorators\r\n\r\n## ✅ Viability Checklist\r\n\r\n* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [ ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)\r\n* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n\r\n## ❗ Problem\r\n\r\nSES (Secure ECMAScript) is an initiative to create a locked-down and sandboxed JavaScript execution environment. One of the tenets of SES is that \"primordials\" (built-in/native ECMAScript global objects, prototypes, functions, etc.) should be immutable and be locked down to a specific set of APIs. This set of APIs includes those specified in the ECMAScript standard and other \"blessed\" APIs depending on the runtime environment. \r\n\r\nA longstanding package used by many in the community is [`reflect-metadata`](https://github.com/rbuckton/reflect-metadata), which is used with TypeScript's `--emitDecoratorMetadata` compiler flag and the `__metadata` helper:\r\n\r\n**Example:**\r\n```bash\r\ntsc example.ts \\\r\n  --target esnext \\\r\n  --experimentalDecorators \\\r\n  --emitDecoratorMetadata\r\n```\r\n\r\n*example.ts*\r\n```ts\r\ndeclare const dec: any;\r\n@dec\r\nclass C {\r\n  constructor(x: int) {\r\n  }\r\n}\r\n```\r\n\r\n*example.js*\r\n```js\r\nvar __decorate = ...\r\nvar __metadata = (this && this.__metadata) || function (k, v) {\r\n    if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\r\n};\r\nlet C = class C {\r\n  constructor(x) {\r\n  }\r\n};\r\nC = __decorate([\r\n  dec,\r\n  __metadata(\"design:paramtypes\", [Number])\r\n], C);\r\n```\r\n\r\nThe issue is that the `__metadata` helper function explicitly relies on an early draft of a [proposal](https://rbuckton.github.io/reflect-metadata/) that has not yet been brought to committee (as it depends on the decorators proposal, which has not yet reached Stage 3). Unfortunately, `reflect-metadata` mutates the global `Reflect` object to shim its API, which violates SES. This was recently brought up in https://github.com/endojs/endo/issues/612 and brought to my attention by @erights. \r\n\r\nAlternatives to `reflect-metadata` exist that do not rely on global mutation, such as https://esfx.js.org/esfx/api/metadata.html. However, they cannot be easily used with TypeScript's `--emitDecoratorMetadata` since our helper is hardcoded to check for the specific global. While it is possible to overwrite the helper locally by providing your own `__metadata` helper, this is behavior is intentionally undocumented and is also burdensome on developers.\r\n\r\n## ⭐ Suggestion\r\n\r\nI am proposing that we add two new compiler options to control how we emit decorator metadata:\r\n\r\n- `--metadataDecorator \u003cstring>` — Accepts a valid `EntityName` that should be used as the decorator in place of `__metadata`\r\n  - This option can only be specified if both `--experimentalDecorators` and `--emitDecoratorMetadata` are set.\r\n- `--metadataDecoratorImportSource \u003cstring>` — A module specifier used to import the provided metadata decorator.\r\n  - This option can only be specified if `--experimentalDecorators`, `--emitDecoratorMetadata`, and `--metadataDecorator` are set.\r\n\r\n***NOTE:** These two options are somewhat analogous to our existing `--jsxFactory` and `--jsxImportSource` options.*\r\n\r\n### `--metadataDecorator` option\r\n\r\nIf the `--metadataDecorator` option is set without specifying `--metadataDecoratorImportSource`, then the following occurs:\r\n- During command line validation we verify that the provided option is a valid `EntityName`.\r\n- During check we verify that the provided name can be resolved to a value that can be called as a decorator appropriate to the element on which it would appear as a result of `--emitDecoratorMetadata`.\r\n- During emit, we would emit the provided `EntityName` in place of `__metadata`.\r\n\r\n***NOTE:** This scenario assumes that the provided metadata decorator exists as a global, or is manually imported into any module.*\r\n\r\n**Example**:\r\n\r\n```bash\r\ntsc example.ts \\\r\n  --target esnext \\\r\n  --experimentalDecorators \\\r\n  --emitDecoratorMetadata \\\r\n  --metadataDecorator myCustomMetadata\r\n```\r\n\r\n*example.ts*\r\n```ts\r\ndeclare const dec: any;\r\n\r\n@dec\r\nclass C {\r\n  constructor(x: number) {}\r\n}\r\n```\r\n\r\n*example.js*\r\n```\r\nvar __decorate = ...\r\nlet C = class C {\r\n  constructor(x) {\r\n  }\r\n}\r\nC = __decorate([\r\n  dec,\r\n  myCustomMetadata(\"design:paramtypes\", [Number])\r\n], C);\r\n```\r\n\r\n### `--metadataDecoratorImportSource` option\r\n\r\nIf the `--metadataDecoratorImportSource` option is set along with `--metadataDecorator`, then the following occurs:\r\n- During command line validation we verify that the provided option is a valid `EntityName`.\r\n- During check we verify that the provided import source can be resolved as a module.\r\n- During check we verify that the first identifier in the provided `EntityName` is an export of the import source.\r\n- During check we verify that the remainder of the provided `EntityName` can be resolved to a value relative to the imported binding above, that can be called as a decorator appropriate to the element on which it would appear as a result of `--emitDecoratorMetadata`.\r\n- During emit, we would emit a synthetic `import` statement for the import source.\r\n- During emit, we would emit the provided `EntityName` in place of `__metadata`.\r\n\r\n**Example**:\r\n\r\n```bash\r\ntsc example.ts \\\r\n  --target esnext \\\r\n  --experimentalDecorators \\\r\n  --emitDecoratorMetadata \\\r\n  --metadataDecorator myCustomMetadata \\\r\n  --metadataDecoratorImportSource my-custom-metadata\r\n```\r\n\r\n*example.ts*\r\n```ts\r\ndeclare const dec: any;\r\n\r\n@dec\r\nexport export class C {\r\n  constructor(x: number) {}\r\n}\r\n```\r\n\r\n*example.js*\r\n```js\r\nvar __decorate = ...\r\nimport { myCustomMetadata } from \"my-custom-metadata\"\r\nlet C = class C {\r\n  constructor(x) {\r\n  }\r\n}\r\nC = __decorate([\r\n  dec,\r\n  myCustomMetadata(\"design:paramtypes\", [Number])\r\n], C);\r\nexport { C }\r\n```\r\n\r\n## Caveats\r\n\r\nSpecifying `--metadataDecoratorImportSource` implies that the custom metadata decorator can only be reached from within a module, therefore any source file that expects metadata must have at least one `import` or `export` declaration, or the `--isolatedModules` option must be set. If a file is not determined to be a module, we will fall back to the existing `__metadata` helper (which is essentially a no-op if the `Reflect.metadata` function does not exist at runtime).\r\n\r\n## Out-of-scope\r\n\r\n- Further changes to type metadata emit related to `--emitDecoratorMetadata` are out of scope. This is only intended to address an ecosystem concern brought to us by those involved with SES.\r\n- Changes to decorator emit related to the ongoing work in the Decorators proposal are out of scope. We do not intend to make any substantial changes to our decorator support until that proposal has reached Stage 3.\r\n\r\n## Related Issues\r\n\r\n- #43450 — ES5 class rewriting incompatible with frozen intrinsics\r\n","author":{"url":"https://github.com/rbuckton","@type":"Person","name":"rbuckton"},"datePublished":"2021-03-31T18:53:20Z","url":"https://github.com/microsoft/TypeScript/issues/43463"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:a6800564-1096-9470-ba4f-08614a0d381b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE836:E03FE:1B025A:239724:6B016511
html-safe-nonce436999f80a885fd3dcef73a7db89b6f9acf5b599376c159ceb4e722ed16db102
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODM2OkUwM0ZFOjFCMDI1QToyMzk3MjQ6NkIwMTY1MTEiLCJ2aXNpdG9yX2lkIjoiMjc4NzE3NDQ4NTQyODYyNjcwNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaccb12805bdcd33b67526621dacfef0a55c231eba56239a26c1ec3bb871e3d82d1
hovercard-subject-tagissue:847137963
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/43463/issue_layout
twitter:imagehttps://opengraph.githubassets.com/81cd9ec1c18d8420128deef88144699ddc4288555b9625d367d949b6240c00c8/microsoft/TypeScript/issues/43463
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/81cd9ec1c18d8420128deef88144699ddc4288555b9625d367d949b6240c00c8/microsoft/TypeScript/issues/43463
og:image:altSuggestion 🔍 Search Terms ses reflect metadata decorator emitDecoratorMetadata experimentalDecorators ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerbuckton
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/43463#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F43463
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F43463
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/43463
Reloadhttps://github.com/microsoft/TypeScript/issues/43463
Reloadhttps://github.com/microsoft/TypeScript/issues/43463
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests312 (312)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/43463
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/43463
SES compatibility for '--emitDecoratorMetadata'https://github.com/microsoft/TypeScript/issues/43463#top
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/rbuckton
Ron Buckton (rbuckton)https://github.com/rbuckton
on Mar 31, 2021https://github.com/microsoft/TypeScript/issues/43463#issue-847137963
TypeScript's Design Goalshttps://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
reflect-metadatahttps://github.com/rbuckton/reflect-metadata
proposalhttps://rbuckton.github.io/reflect-metadata/
endojs/endo#612https://github.com/endojs/endo/issues/612
Mark S. Miller (@erights)https://github.com/erights
https://esfx.js.org/esfx/api/metadata.htmlhttps://esfx.js.org/esfx/api/metadata.html
ES5 class rewriting incompatible with frozen intrinsics #43450https://github.com/microsoft/TypeScript/issues/43450
https://github.com/erights
Mark S. Miller (erights)https://github.com/erights
on Mar 31, 2021https://github.com/microsoft/TypeScript/issues/43463#issuecomment-811381256
Ron Buckton (@rbuckton)https://github.com/rbuckton
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
on Apr 1, 2021https://github.com/microsoft/TypeScript/issues/43463#event-4542368126
https://github.com/DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
on Apr 7, 2021https://github.com/microsoft/TypeScript/issues/43463#issuecomment-815298512
npm and Yarn's selective dependency resolutions/overrides (i.e. the resolutions field in package.json)https://classic.yarnpkg.com/en/docs/selective-version-resolutions/
https://github.com/erights
Mark S. Miller (erights)https://github.com/erights
on Jun 9, 2021https://github.com/microsoft/TypeScript/issues/43463#issuecomment-857398892
Ron Buckton (@rbuckton)https://github.com/rbuckton
Daniel Rosenwasser (@DanielRosenwasser)https://github.com/DanielRosenwasser
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/43463
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/43463
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.