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

Decorators for symbol property are compiled incorrectly #5189

Closed
dko-slapdash opened this issue Jul 12, 2022 · 2 comments · Fixed by #5964
Closed

Decorators for symbol property are compiled incorrectly #5189

dko-slapdash opened this issue Jul 12, 2022 · 2 comments · Fixed by #5964
Assignees
Milestone

Comments

@dko-slapdash
Copy link

Describe the bug

When using a @decorator for a symbol property, the compiler generates a wrong output.

Input code

const sym = Symbol("sym");

class Cls {
  @Memoize()
  [sym]() {}
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "target": "es2020"
  },
  "module": {
    "type": "commonjs"
  }
}

Playground link

https://play.swc.rs/?version=1.2.212&code=H4sIAAAAAAAAA0vOzysuUSiuzFWwVQiuzE3Kz9FQAvKUNK25uJJzEouLFZxzihWquRQUHHxTc%2FMzq1I1NIGcaKCaWA1NheparloAlz70DEMAAAA%3D&config=H4sIAAAAAAAAAxWMQQrAIAwE%2F7JnD8WjvxENpaU2kkSoiH%2Bv3padnR24NSEM1ChKspP21%2BKHAOuVNMlVDQ6ZEks0FkUwaTQdLMpJtoak%2FvAHVlU4t4f2y5YXSlwKv7dizh8GxEdwawAAAA%3D%3D

Expected behavior

It should define _key before defining the class.

Actual behavior

_key is undefined, so the property does not define. Compiled result:

...
const sym = Symbol("sym");
var _key;
class Cls {
    [_key]() {}
}
_key = sym; // <--- This must be BEFORE the class definition
__decorate([
    Memoize()
], Cls.prototype, _key, null);

Version

1.2.212

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone Jul 12, 2022
@CMCDragonkai

This comment was marked as spam.

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 30, 2022

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 Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.

4 participants