Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decorated and regular class properties are translated in a wrong order #6951

Closed
Qireel opened this issue Feb 16, 2023 · 1 comment · Fixed by #6972
Closed

Decorated and regular class properties are translated in a wrong order #6951

Qireel opened this issue Feb 16, 2023 · 1 comment · Fixed by #6972
Labels
Milestone

Comments

@Qireel
Copy link

Qireel commented Feb 16, 2023

Describe the bug

According to Playground demo, swc breaks the definition order of class fields: all the undecorated fields go first, and the decorated ones go last. This behavior leads to some problems if the undecorated field depends on the decorated field value in its class constructor.

TSC compiler doesn't change the order of fields in a constructor.

Input code

No response

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": true
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.35&code=H4sIAAAAAAAAA0vOSSwuVnBUqOZSUHDITypOLSpLTMpJVUhUsFUoKSpNteYCSiQBOWmJOcUQXnJ%2BXjFQKrkkv0hDE6yxlquWCwBWMAoXSQAAAA%3D%3D&config=H4sIAAAAAAAAA02Ouw6DMAxF%2F8Uzazswd%2BUjrGBQqiSObCM1Qvx7Ex6lm%2BV77mOFtzroV8goStIuLcnwAz1YyaROfDbowLS%2BJgxKHYzkWNBYFHqThbYqo8xk1UT6qHRgVvrx0Sc%2FlZbtOGYh1VvCNIeLbDmCSSeW2OhAM7ryutqOsr%2F6gQxHNDxXVHvkcWlx6z5%2Bn%2FOE7V5wtnodTnA3fgHD3DNVBQEAAA%3D%3D

Expected behavior

Fields are translated in an order they were declared.

Actual behavior

Order of fields is changed.

Version

1.3.35

Additional context

No response

@Qireel Qireel added the C-bug label Feb 16, 2023
@kdy1 kdy1 added this to the Planned milestone Feb 22, 2023
kdy1 pushed a commit that referenced this issue Feb 23, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.37 Feb 28, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Mar 30, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Mar 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants