Title: Downlevel static properties initializer to be contained within the class IIFE to aid Uglify in dead code removal · Issue #15857 · microsoft/TypeScript · GitHub
Open Graph Title: Downlevel static properties initializer to be contained within the class IIFE to aid Uglify in dead code removal · Issue #15857 · microsoft/TypeScript
X Title: Downlevel static properties initializer to be contained within the class IIFE to aid Uglify in dead code removal · Issue #15857 · microsoft/TypeScript
Description: TypeScript currently down-levels classes with static property initializers being outside of the class IIFE when targeting ES5. This prevents Uglify 2.8+ from removing the class from the final application bundle (after the class IIFEs hav...
Open Graph Description: TypeScript currently down-levels classes with static property initializers being outside of the class IIFE when targeting ES5. This prevents Uglify 2.8+ from removing the class from the final appli...
X Description: TypeScript currently down-levels classes with static property initializers being outside of the class IIFE when targeting ES5. This prevents Uglify 2.8+ from removing the class from the final appli...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/15857
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Downlevel static properties initializer to be contained within the class IIFE to aid Uglify in dead code removal","articleBody":"TypeScript currently down-levels classes with static property initializers being outside of the class IIFE when targeting ES5. This prevents Uglify 2.8+ from removing the class from the final application bundle (after the class IIFEs have been independently annotated with the `/*#__PURE__*/` annotation (see #13721) and there are no other references to the class).\r\n\r\nChanging the down-leveling to keep the assignment within the IIFE just as static methods are down-leveled would resolve this problem and make lots of code eligible for dead code elimination by uglify (after the IIFEs have been marked with the pure annotation).\r\n\r\nThe change should be backwards compatible unless the current down-leveling approach was intentional to deal with some unusual corner-case that I'm not aware of.\r\n\r\n\r\n**TypeScript Version:** 2.2.1 / nightly (2.2.0-dev.201xxxxx)\r\n\r\n**Code**\r\n\r\n```ts\r\nclass MyHappyClass {\r\n static myStaticProp = 'this is a simple static prop';\r\n static myStaticMethod() { return 'static method' };\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n```js\r\nvar MyHappyClass = (function () {\r\n function MyHappyClass() {\r\n }\r\n MyHappyClass.myStaticMethod = function () { return 'static method'; };\r\n MyHappyClass.myStaticProp = 'this is a simple static prop';\r\n return MyHappyClass;\r\n}());\r\n```\r\n\r\n**Actual behavior:**\r\n\r\nThe code above downlevels to the static prop being initialized\r\n```js\r\nvar MyHappyClass = (function () {\r\n function MyHappyClass() {\r\n }\r\n MyHappyClass.myStaticMethod = function () { return 'static method'; };\r\n ;\r\n return MyHappyClass;\r\n}());\r\nMyHappyClass.myStaticProp = 'this is a simple static prop';\r\n```\r\n\r\n[Playground link](https://www.typescriptlang.org/play/index.html#src=class%20MyHappyClass%20%7B%0A%20%20constructor(something%3A%20string)%20%7B%7D%0A%0A%20%20myProperty%20%3D%20'simple%20property'%3B%0A%20%20myMethod()%20%7B%20return%20'simple%20method'%20%7D%3B%0A%0A%20%20static%20myStaticProp%20%3D%20'this%20is%20a%20simple%20static%20prop'%0A%20%20static%20myStaticMethod()%20%7B%20return%20'static%20method'%20%7D%3B%0A%20%20%0A%20%20get%20myGetterSetter()%20%7B%20return%20'getter'%20%7D%0A%20%20set%20myGetterSetter(val)%20%7B%20this.myProperty%20%3D%20val%3B%20%7D%0A%0A%20%20static%20get%20myStaticGetterSetter()%20%7B%20return%20'static%20getter'%20%7D%0A%20%20static%20set%20myStaticGetterSetter(x)%20%7B%20this.myStaticProp%20%3D%20x%20%7D%0A%7D)","author":{"url":"https://github.com/IgorMinar","@type":"Person","name":"IgorMinar"},"datePublished":"2017-05-15T22:05:43Z","url":"https://github.com/microsoft/TypeScript/issues/15857"}
| 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:3962aafa-4d86-2091-f719-ac2044f4fc22 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8F0E:1D20B7:21AA757:2AAFCC0:6B01AEB9 |
| html-safe-nonce | 39bdf98a257d13cc5486a1d7c6d066c7c3d61a33c9537d6b9623100805665cbd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjBFOjFEMjBCNzoyMUFBNzU3OjJBQUZDQzA6NkIwMUFFQjkiLCJ2aXNpdG9yX2lkIjoiNjY4NDUxMzU4NDYxMDkxMzk3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d740d17125752b303e864be0a3e77ae95d603b2da1f28d87e664ce38a6ff6b2d |
| hovercard-subject-tag | issue:228859951 |
| 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/15857/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8304b7a49ee1c64e84fd3b6edda8279d66f9c3a7f725c3adf7a696bf9ad781d1/microsoft/TypeScript/issues/15857 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8304b7a49ee1c64e84fd3b6edda8279d66f9c3a7f725c3adf7a696bf9ad781d1/microsoft/TypeScript/issues/15857 |
| og:image:alt | TypeScript currently down-levels classes with static property initializers being outside of the class IIFE when targeting ES5. This prevents Uglify 2.8+ from removing the class from the final appli... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | IgorMinar |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width