Title: [Bug]: Order of constructor parameter properties vs class properties initializers - Discrepency between typescript and bable · Issue #13779 · babel/babel · GitHub
Open Graph Title: [Bug]: Order of constructor parameter properties vs class properties initializers - Discrepency between typescript and bable · Issue #13779 · babel/babel
X Title: [Bug]: Order of constructor parameter properties vs class properties initializers - Discrepency between typescript and bable · Issue #13779 · babel/babel
Description: 💻 Would you like to work on a fix? How are you using Babel? @rollup/plugin-babel Input code Original Code: class Dashboard { name = 'stats' + this.amount; constructor( readonly amount ) { } } Babel Emit: "use strict"; function _definePro...
Open Graph Description: 💻 Would you like to work on a fix? How are you using Babel? @rollup/plugin-babel Input code Original Code: class Dashboard { name = 'stats' + this.amount; constructor( readonly amount ) { } } Babel...
X Description: 💻 Would you like to work on a fix? How are you using Babel? @rollup/plugin-babel Input code Original Code: class Dashboard { name = 'stats' + this.amount; constructor( readonly amount ) { }...
Opengraph URL: https://github.com/babel/babel/issues/13779
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Order of constructor parameter properties vs class properties initializers - Discrepency between typescript and bable ","articleBody":"### 💻\n\n- [ ] Would you like to work on a fix?\n\n### How are you using Babel?\n\n@rollup/plugin-babel\n\n### Input code\n\nOriginal Code: \r\n\r\n```js\r\nclass Dashboard {\r\n name = 'stats' + this.amount;\r\n\r\n constructor(\r\n readonly amount\r\n ) { \r\n }\r\n}\r\n```\r\n\r\nBabel Emit:\r\n\r\n```js\r\n\"use strict\";\r\n\r\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\r\n\r\nclass Dashboard {\r\n constructor(amount) {\r\n _defineProperty(this, \"name\", 'stats' + this.amount);\r\n\r\n this.amount = amount;\r\n }\r\n}\r\n```\r\n\r\nTypescript emits:\r\n\r\n```js\r\nclass Dashboard {\r\n constructor(amount) {\r\n this.amount = amount;\r\n this.name = 'stats' + this.amount;\r\n }\r\n}\r\n```\r\n\n\n### Configuration file name\n\nbabel.config.js\n\n### Configuration\n\nFor reproduction I've used the Babel online repl with Env stage 2 preset and Typescript preset. \r\n[link](https://babeljs.io/repl/#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.6&spec=false&loose=false&code_lz=MYGwhgzhAEAikAsBGB7MAnAJtA3gKGkOgDswBbAU2gF5oByCAFzEYjugGppGEBLCAHTkUAV2KMA3HgJFgKYk3QjgjFOgAUMokXQUwmeSACe0YWMZboASlzRLAXzz2gA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Creact%2Cstage-2%2Ctypescript&prettier=false&targets=&version=7.15.7&externalPlugins=&assumptions=%7B%7D)\r\n\r\nFor typescript reproduction I've used Typescript playground.\r\n[link](https://www.typescriptlang.org/play?ssl=9&ssc=2&pln=1&pc=1#code/MYGwhgzhAEAikAsBGB7MAnAJtA3gKGkOgDswBbAU2gF5oByCAFzEYjugGppGEBLCAHTkUAV2KMA3HgJFgKYk3QjgjFOgAUMokXQUwmeSACe0YWMYAuEiLJIK6ADRboASlzTtAXzyegA)\n\n### Current and expected behavior\n\nCurrent Behavior - Babel puts parameter properties in the constructor after class properties assignment. Typescript puts them before.\r\n\r\nExpected Behavior - Its a discrepancy. Not sure if Babel is the responsible or Typescript. Typescript behavior is more preferable to me because it makes writing shorter for me.\n\n### Environment\n\n- Babel - 7.15.7\r\n- Typescript - 4.4.2\n\n### Possible solution\n\nNot sure. I've found some issues talking about plugin orders but I'm not sure.\n\n### Additional context\n\n_No response_","author":{"url":"https://github.com/elpddev","@type":"Person","name":"elpddev"},"datePublished":"2021-09-21T09:30:24Z","url":"https://github.com/babel/babel/issues/13779"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:330dd88b-d8e7-5b6d-a7ef-63f91960caf9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E990:12F69A:144B49F:1A9E87C:6AED775E |
| html-safe-nonce | 2366e5a7c651a3c0380b2bb2e3c0f9938c72ff9b5578f51ec9f898fe5c7df3d8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOTkwOjEyRjY5QToxNDRCNDlGOjFBOUU4N0M6NkFFRDc3NUUiLCJ2aXNpdG9yX2lkIjoiNTQyMDYyODc0ODA1MjI5NzU2NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e2b113fe1f45265eb2ba64db448fbb8957efc73dd2ce5eb413be70bb7ebc40bc |
| hovercard-subject-tag | issue:1002113189 |
| 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/babel/babel/13779/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8e6486a5fb9cbf630beb59a3b8923f1e60ded597159803983d453574a5ed9e6f/babel/babel/issues/13779 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8e6486a5fb9cbf630beb59a3b8923f1e60ded597159803983d453574a5ed9e6f/babel/babel/issues/13779 |
| og:image:alt | 💻 Would you like to work on a fix? How are you using Babel? @rollup/plugin-babel Input code Original Code: class Dashboard { name = 'stats' + this.amount; constructor( readonly amount ) { } } Babel... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | elpddev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11 |
| turbo-cache-control | no-preview |
| go-import | github.com/babel/babel git https://github.com/babel/babel.git |
| octolytics-dimension-user_id | 9637642 |
| octolytics-dimension-user_login | babel |
| octolytics-dimension-repository_id | 24560307 |
| octolytics-dimension-repository_nwo | babel/babel |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24560307 |
| octolytics-dimension-repository_network_root_nwo | babel/babel |
| 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 | 9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width