Title: ES5 class rewriting incompatible with frozen intrinsics · Issue #43450 · microsoft/TypeScript · GitHub
Open Graph Title: ES5 class rewriting incompatible with frozen intrinsics · Issue #43450 · microsoft/TypeScript
X Title: ES5 class rewriting incompatible with frozen intrinsics · Issue #43450 · microsoft/TypeScript
Description: Bug Report When TSC targets ES5, classes that extend other classes generate JS that throws a Cannot assign to read only property 'constructor' of object TypeError when the intrinsics, particularly the Function.prototype, are frozen. This...
Open Graph Description: Bug Report When TSC targets ES5, classes that extend other classes generate JS that throws a Cannot assign to read only property 'constructor' of object TypeError when the intrinsics, particularly ...
X Description: Bug Report When TSC targets ES5, classes that extend other classes generate JS that throws a Cannot assign to read only property 'constructor' of object TypeError when the intrinsics, parti...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/43450
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ES5 class rewriting incompatible with frozen intrinsics","articleBody":"# Bug Report\r\n\r\nWhen TSC targets ES5, classes that extend other classes generate JS that throws a `Cannot assign to read only property 'constructor' of object` TypeError when the intrinsics, particularly the `Function.prototype`, are frozen. This affects programs that are freezing their intrinsics to protect against supply chain attacks, particularly using SES.\r\n\r\n### 🔎 Search Terms\r\n\r\n* constructor\r\n* frozen\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nI identified this issue in the published code of `external-editor` 3.1.0, which is using TypeScript 3.5.2 https://github.com/mrkmg/node-external-editor/blob/e1070a8295b8ebbafa7b29802ae0e2da0fad47c0/tsconfig.json\r\n\r\nIn the playground, the output is consistent for the very oldest and very newest versions of TypeScript when targeting ES5.\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?target=1&ts=4.2.3#code/PIIwVgpgxgLgdAMwE4QgLwgCgGIFcB2sAlgPb4CUA3AFCiSyIrpZ6Eyn5wAOSJMfATy4Qq1KABsAhgGdpAAmwkScgN7U5GuVDLSYSXLBJJM5Ves0BfalYkz5AIUlI5EAB4wI+ACbzFytZpaOnoG-MamAZbWQA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\nObject.freeze(Function);\r\nObject.freeze(Function.prototype);\r\nclass Foo {\r\n constructor() {\r\n }\r\n}\r\nclass Bar extends Foo {\r\n constructor() {\r\n }\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nThis code throws an exception like:\r\n\r\n`TypeError: Cannot assign to read only property 'constructor' of object ''`\r\n\r\n### 🙂 Expected behavior\r\n\r\nThis should not throw an exception. This can be achieved by using `Object.defineProperty(prototype, 'constructor', {value: constructor})` instead of `prototype.constructor = constructor`. This is a symptom of the so-called property override mistake, in the design of ES5.","author":{"url":"https://github.com/kriskowal","@type":"Person","name":"kriskowal"},"datePublished":"2021-03-30T23:22:59Z","url":"https://github.com/microsoft/TypeScript/issues/43450"}
| 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:f880d1aa-257b-5e32-df68-b8a482b09b61 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD6E:266B67:4EB44C:67F590:6B017A03 |
| html-safe-nonce | edfa728592598693387228b87b88a45daefc166b12c21ffb9560ab5e73a3cc2d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDZFOjI2NkI2Nzo0RUI0NEM6NjdGNTkwOjZCMDE3QTAzIiwidmlzaXRvcl9pZCI6IjM0MDM0Mzg3OTU2MDgxMjgwMDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ccd41addfc07a29cad3a66e280bdf9181e8b5485f8122322d22f2f2347aed9da |
| hovercard-subject-tag | issue:845451234 |
| 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/43450/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0cb8b146a0ae85343f9660add65cdfea1c5e3ec9c5a25b4222970c5cdc37658d/microsoft/TypeScript/issues/43450 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0cb8b146a0ae85343f9660add65cdfea1c5e3ec9c5a25b4222970c5cdc37658d/microsoft/TypeScript/issues/43450 |
| og:image:alt | Bug Report When TSC targets ES5, classes that extend other classes generate JS that throws a Cannot assign to read only property 'constructor' of object TypeError when the intrinsics, particularly ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kriskowal |
| 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