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

Static decorators are executed at the wrong time #8021

Open
jrandolf opened this issue Sep 28, 2023 · 2 comments · May be fixed by #8057
Open

Static decorators are executed at the wrong time #8021

jrandolf opened this issue Sep 28, 2023 · 2 comments · May be fixed by #8057
Labels
Milestone

Comments

@jrandolf
Copy link
Contributor

jrandolf commented Sep 28, 2023

Describe the bug

Decorators get hoisted before the class declaration which causes problems when a static function in a class is used to decorate a method.

Input code

class A {
  static test(a: any, b: any) {}

  @A.test()
  hi() {}
}

Config

{
  "$schema": "https://json.schemastore.org/swcrc",
  "module": {
    "type": "commonjs"
  },
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "target": "es2022",
    "transform": {
      "decoratorVersion": "2022-03"
    }
  }
}

Playground link

No response

SWC Info output

No response

Expected behavior

It should work.

Actual behavior

No response

Version

1.3.90

Additional context

No response

@jrandolf
Copy link
Contributor Author

jrandolf commented Sep 28, 2023

I don't have time to work on this more, so I'll leave a summary.

The PR doesn't work. I suspect this needs to be done outside the class, after it has been declared, similar to how TypeScript and the proposal encourage it.

Something like

let a = class A {}
(() => {
 ...do static stuff here
})
return a;

I suspect that would require a lot of change with the private methods and what not.

@jrandolf jrandolf closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2023
@kdy1 kdy1 added this to the Planned milestone Sep 29, 2023
@kdy1
Copy link
Member

kdy1 commented Sep 29, 2023

Reopening as I can work on this

@kdy1 kdy1 reopened this Sep 29, 2023
@kdy1 kdy1 self-assigned this Sep 29, 2023
@kdy1 kdy1 removed their assignment Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants