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

decorator of method in hoc lead to runtime error after compilation #9350

Closed
Mumujianguang opened this issue Jul 31, 2024 · 4 comments · Fixed by #9375
Closed

decorator of method in hoc lead to runtime error after compilation #9350

Mumujianguang opened this issue Jul 31, 2024 · 4 comments · Fixed by #9375
Assignees
Labels
Milestone

Comments

@Mumujianguang
Copy link

Describe the bug

the Design.prototype parameter of _ts_decorate method is undefined in scope

export default function design(base) {
    var _class;
    return _class = class Design extends base {
        copy() {
            console.log("copy");
        }
        render() {
            super.render();
            console.log("design render");
        }
    }, _ts_decorate([
        registerHook('beforeRender'),
        registerHook('afterRender')
    ], Design.prototype, "render", null), _class;
}

the compiled code can not run in browser
image

Input code

function registerHook(key) {
    return (...args) => console.log(args)
}

export default function design(base: typeof Component) {
    return class Design extends base {
        copy() {
            console.log("copy");
        }

        @registerHook('beforeRender')
        @registerHook('afterRender')
        render() {
            super.render();
            console.log("design render");
        }
    }
}

Config

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

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.3&code=H4sIAAAAAAAAA3WQTY7CMAyF9z2FxYZkkwOAGI00LFhzg9C%2BVBWdOLJTiQpxd%2FpDZ4ZBeGFZL5%2FtF4culrnhSIK60Qw5MJ%2FNGb2la0FDCHInkYxzzkutlnYfVHJUbuFars0kFreiwCWxZKoQfNdmCsvgCtrU0Zy8YkO5T%2BBAX%2FydOCLmf1vK1qvSfuogXDJipTR2PrAxSk69sX%2BEWfx1tBqJld3%2BAIO5pfx8%2Bub6hMCC47AGsrbvKB%2BG8gWSSXhxol2CuOVx%2B97lfJfHmGe7c77dAYePf1ucAQAA&config=H4sIAAAAAAAAA1VPOw6DMAzdOUXkuUPbgaF36CGiYFAqSCLbSEWIu5NAkpbNfh8%2Fv7VRCj5s4KXWOMYlaGKkukeEFyf6GxGQJSAbskHgVtgOjSctnjgqhGasjHAy9XpkPKDtZEA0DSjpHvLz%2FmjzLRi9ZyyOjE3W2X75%2F8b4KRAyX4VJqt0w4jWxyakw%2BW4%2ByNwyNTk%2FaOEnKmH1MFh%2BF2fq1mw7L9dvyDEBAAA%3D

SWC Info output

No response

Expected behavior

the compiled code should be as below

export default function design(base) {
    var _class;
    return _class = class Design extends base {
        copy() {
            console.log("copy");
        }
        render() {
            super.render();
            console.log("design render");
        }
    }, _ts_decorate([
        registerHook('beforeRender'),
        registerHook('afterRender')
    ], _class.prototype, "render", null), _class;
}

Actual behavior

No response

Version

1.7.3

Additional context

No response

@Mumujianguang
Copy link
Author

Mumujianguang commented Aug 5, 2024

@kdy1 @magic-akari I‘m using v1.7.6 of swc in the playground,the compiled code still has not changed
image

@magic-akari
Copy link
Member

All crates depending on swc_ecma_transforms_proposal need to be updated, but swc_core has not been updated. @kdy1

@kdy1
Copy link
Member

kdy1 commented Aug 8, 2024

I verified that it's applied in the SWC playground

@swc-bot
Copy link
Collaborator

swc-bot commented Sep 7, 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 Sep 7, 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