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

Cannot implement decorator as a private method #9429

Closed
bryfox opened this issue Aug 14, 2024 · 1 comment · Fixed by #9535
Closed

Cannot implement decorator as a private method #9429

bryfox opened this issue Aug 14, 2024 · 1 comment · Fixed by #9535
Assignees
Labels
Milestone

Comments

@bryfox
Copy link

bryfox commented Aug 14, 2024

Describe the bug

SWC does not appear to support defining a decorator with a private method

Input code

See playground link

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true,
      "decoratorsBeforeExport": true
    },
    "transform": {
      "legacyDecorator": true
    },
    "target": "es2022"
  },
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.11&code=H4sIAAAAAAAAA3WSz0rEMBDG7%2FsU43pJoeQBun9QEC8iiHgTkWw77QazSUimrkX67k7abl2FvaTpzJfffDNJaVSMcO8cfC8AIinSJVwb1zRYPSLtXbW%2BDU0E%2FCK0VYTWflh3tK9vOTwjbQUfAnj3wZGjzmMBaXV1Iso5ms8qj4G6B%2BwKLhW0bcZMhbEM2pMLBbywvnqalHdzYi1or2ORuDlIKRWbKiBZy2CzBT5w0BHXydM2QbOhH4DS2UhwGDqBzVkl%2BalMi1erfwbGMCvr1paknQUxVTsRASh0836s4AxKnplY7rB2AZfZak4HpDbYyYFU3ptuaCWHAXoS9lBrq4y5SFY1YfgF98O3T7%2F9gpcbkSb%2B5%2BIyDvt2Z%2FhCm4BIIitA2e5sMDN8r0dyv2DYOLKan8QGLB7TyAVnOSAnzuoH9oK%2FCzYCAAA%3D&config=H4sIAAAAAAAAA1VPuw6DMAzc%2BQrkuUOVoUP%2FoR8RBYOCyEO2kYoQ%2F94EkrTd7LvznW%2Fv%2Bh5mNvDs9zSmJWpipLYnhDcv%2Bp0QkC0iG7JR4FZZ4UwJrdigAU0gLYG4MCdxXDyIpgkl2yGru1LFCpYQGBM86oWLFzjr7bj9PmOCi4TM%2F8Is1X5a2v2V2JVUcGFYT7KUzEWuDx7wFdWwZgyWX%2FXy7HF8AF26uLkwAQAA

SWC Info output

No response

Expected behavior

No error when running the emitted code; decorator executes as expected.

tsc output for comparison:

class Foo {
    // ...
    static {
        __decorate([
            (Foo.#loggedMethod)
        ], Foo.prototype, "greet", null);
    }
}

Actual behavior

Emitted code references the private method outside the class

Uncaught SyntaxError: Private field '#loggedMethod' must be declared in an enclosing class

_ts_decorate([
    Foo.#loggedMethod
], Foo.prototype, "greet", null);

Version

1.7.11

Additional context

No response

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 9, 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 Oct 9, 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.

5 participants