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 not working correctly for default exported classes #8681

Closed
benStre opened this issue Mar 2, 2024 · 1 comment · Fixed by #8691
Closed

Decorators not working correctly for default exported classes #8681

benStre opened this issue Mar 2, 2024 · 1 comment · Fixed by #8691
Assignees
Labels
Milestone

Comments

@benStre
Copy link

benStre commented Mar 2, 2024

Describe the bug

When a decorator is applied to a class that is exported as a default export, the default export contains the original class and not the new value returned from the class decorator.
This works as expected for normal exports.

Input code

@decorator
export default class Example {}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "target": "es2022",
    "transform": {
      "decoratorVersion": "2022-03"
    }
  }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.4.3-nightly-20240301.1&code=H4sIAAAAAAAAA3NISU3OL0osyS%2FiSq0oyC8qUUhJTUsszSlRSM5JLC5WcK1IzC3ISVWorgUAU7BXiCoAAAA%3D&config=H4sIAAAAAAAAA02NsQrDMAxE93yF0ZxCcLd8SHfhqiGF2uakQkPIv1duSOgg0N3pndYuBHpqojGsvrqoDBWc2h1dsvHHHbKliibM1ag%2F0rukArYC9QvDW37BtudkjEmssaJxiJEOH5z1UfD6f3RW3QQ6l9ywBl2GK%2B2tXZvtC1n9TOu1AAAA

SWC Info output

No response

Expected behavior

The class should first be decorated and then exported, like this:

let _Example;
class Example {
    static{
        ({ c: [_Example, _initClass] } = _apply_decs_2203_r(this, [], [
            decorator
        ]));
    }
    static{
        _initClass();
    }
}
export default _Example;

Actual behavior

SWC compiles to

var _initClass, _Example;
export default class Example {
    static{
        ({ c: [_Example, _initClass] } = _apply_decs_2203_r(this, [], [
            decorator
        ]));
    }
    static{
        _initClass();
    }
}

Outside the module, only the original class is accessible, not the decorated version.

Version

1.4.3

Additional context

Might be related to #8515

@benStre benStre added the C-bug label Mar 2, 2024
@kdy1 kdy1 added this to the Planned milestone Mar 3, 2024
@magic-akari magic-akari self-assigned this Mar 4, 2024
@kdy1 kdy1 closed this as completed in #8691 Mar 4, 2024
kdy1 pushed a commit that referenced this issue Mar 4, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.4.3 Mar 5, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Apr 4, 2024

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 Apr 4, 2024
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.

4 participants