Title: Bad esnext emit for static property that references another static property when the class has a decorator · Issue #44908 · microsoft/TypeScript · GitHub
Open Graph Title: Bad esnext emit for static property that references another static property when the class has a decorator · Issue #44908 · microsoft/TypeScript
X Title: Bad esnext emit for static property that references another static property when the class has a decorator · Issue #44908 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms decorator static usedefineforclassfields 🕗 Version & Regression Information In the Playground, this behaviour first appears in 3.7.5. ⏯ Playground Link Playground link with relevant code 💻 Code function foo(ctor...
Open Graph Description: Bug Report 🔎 Search Terms decorator static usedefineforclassfields 🕗 Version & Regression Information In the Playground, this behaviour first appears in 3.7.5. ⏯ Playground Link Playground link wit...
X Description: Bug Report 🔎 Search Terms decorator static usedefineforclassfields 🕗 Version & Regression Information In the Playground, this behaviour first appears in 3.7.5. ⏯ Playground Link Playground link...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/44908
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bad esnext emit for static property that references another static property when the class has a decorator","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n-->\r\n\r\n### 🔎 Search Terms\r\n\r\ndecorator static usedefineforclassfields\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n\u003c!-- When did you start seeing this bug occur?\r\n\r\n\"Bugs\" that have existed in TS for a long time are very likely to be FAQs; refer to\r\n https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs\r\n\r\nIf possible, please try testing the nightly version of TS to see if it's already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n\r\nNote: The TypeScript Playground can be used to try older versions of TypeScript.\r\n\r\nPlease keep and fill in the line that best applies:\r\n-->\r\n- In the Playground, this behaviour first appears in 3.7.5.\r\n\r\n### ⏯ Playground Link\r\n\r\n\u003c!--\r\n A link to a TypeScript Playground \"Share\" link which shows this behavior\r\n\r\n The TypeScript Workbench can be used for more complex setups, try\r\n https://www.typescriptlang.org/dev/bug-workbench/\r\n\r\n As a last resort, you can link to a repo, but these will be slower for us to investigate.\r\n-->\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?useDefineForClassFields=true&declaration=false&target=99&jsx=0&module=1&ts=3.7.5&strict=true&isolatedModules=false#code/GYVwdgxgLglg9mABMOcAU04CcBciBi408YAlIgN4C+AUAAIpw0QA2AhgM4eIDClNASA5Q2sCIgAaiALyIAjAG5Bw0THEBNGbwB0EpVSA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\nfunction foo(ctor: Function) {}\r\n@foo\r\nclass C {\r\n\tstatic X = 1;\r\n\tstatic Y = C.X;\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nWhen targeting `esnext`, the `useDefineForClassFields` option is set by default. Using this combination of options, class C is emitted as follows:\r\n```js\r\nlet C = C_1 = class C {\r\n static X = 1;\r\n static Y = C_1.X;\r\n};\r\n```\r\n\r\nThe name mangling to `C_1` causes the assignment to `Y` to fail at runtime.\r\n\r\nIf the decorator is removed, the emit becomes:\r\n```js\r\nclass C {\r\n static X = 1;\r\n static Y = C.X;\r\n}\r\n```\r\n\r\nwhich works fine.\r\n\r\nIf `useDefineForClassFields` is disabled, the property assignment gets moved outside the class definition, where the name mangling is correct.\r\n\r\n### 🙂 Expected behavior\r\n\r\nProbably just not performing the name mangling when emitting within the class.\r\n\r\nI appreciate the decorator functionality is unstable, so please consider this bug report purely informational.\r\n","author":{"url":"https://github.com/yseymour","@type":"Person","name":"yseymour"},"datePublished":"2021-07-06T07:30:21Z","url":"https://github.com/microsoft/TypeScript/issues/44908"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:983e1c06-8ea3-0e3b-69c0-538e833b4b6e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A464:1CEA6F:CCE11D:1101FE9:6B00F655 |
| html-safe-nonce | 84355ef266b9baadd4674485687d180f661ca1bfcf350d566cf7233d5d207c12 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDY0OjFDRUE2RjpDQ0UxMUQ6MTEwMUZFOTo2QjAwRjY1NSIsInZpc2l0b3JfaWQiOiI0ODE1MjE5NzgzMDMxMTI1NTg5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b30368732dc194ff8de5676ac536d4aff34c9ab6277b9114b7a71c9f1460631f |
| hovercard-subject-tag | issue:937601273 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/44908/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4e2a96f79ecf704f06f137b7ee7e06f903329e1e7002a972ddf2b8dfad8c999f/microsoft/TypeScript/issues/44908 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4e2a96f79ecf704f06f137b7ee7e06f903329e1e7002a972ddf2b8dfad8c999f/microsoft/TypeScript/issues/44908 |
| og:image:alt | Bug Report 🔎 Search Terms decorator static usedefineforclassfields 🕗 Version & Regression Information In the Playground, this behaviour first appears in 3.7.5. ⏯ Playground Link Playground link wit... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yseymour |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width