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

2022-03 Decorator not working in an exported class #7358

Closed
lolopinto opened this issue May 5, 2023 · 3 comments · Fixed by #7363
Closed

2022-03 Decorator not working in an exported class #7358

lolopinto opened this issue May 5, 2023 · 3 comments · Fixed by #7363
Assignees
Labels
Milestone

Comments

@lolopinto
Copy link

Describe the bug

parse error trying to use decorator in an exported class

Input code

@decorate()
export class Foo {

  @decorate()
  get name() {
    return "hello"
  }

  @decorate()
  sayHi() {
    return "hello"
  }
}

function decorate() {
  return function(target, {kind}) {
    console.log(target, kind)
  }
}

Config

{
    "test": ".*.tsx?$",
    "jsc": {
        "parser": {
            "syntax": "typescript",
            "decorators": true
        },
        "target": "es2020",
        "transform": {
            "decoratorVersion": "2022-03"
        }
    }
}

Playground link

https://play.swc.rs/?version=1.3.56&code=H4sIAAAAAAAAA32OQQrCQAxF93OKT1ctiGfoSrzGMI11cExkJgWl9O6NrVVBMLvkv%2FdJ21GQ7JXqxtH9JlkRki8FBxGMzgHtFwH0pGB%2FtcVS2GTSITOqM6UklZ2mX6n4xzH%2BM8w5DRw0CuNjLvyL3uJafbYfdhgvkbtp6wzCRRLtk%2FRv4gk0a%2F0M7hpWieYAAAA%3D&config=H4sIAAAAAAAAA1WOwQqDMBBE7%2FkK2XMLwUIP%2FYdeew%2B6KSmayO4KDeK%2Fd43V2tvOvJllJlNV8OIGbtWkp4rBESPtWh3OUdxbHZA8IDcUBoHTRltsEjlJxJoQGrGAeeUg5CL7RP3x4V55IHFIcXld27o%2B2wuY%2F7qjJ8rCkTVhwXwZ9KkdO%2FzNXqatueshFGLwWW3vOsZiBb5vzTJ2%2FgCck9nlAgEAAA%3D%3D

Expected behavior

decorator works, same as in node

ts-node src/index.ts                              
[Function: get name] getter
[Function: sayHi] method
[class Foo] class
hello
hello

Actual behavior

SWCRC=true node -r @swc-node/register src/index.ts
/Users/ola/code/swc-jest-example/src/foo.ts:376
@decorate()
^

SyntaxError: Invalid or unexpected token
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._compile (/Users/ola/code/swc-jest-example/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.newLoader [as .ts] (/Users/ola/code/swc-jest-example/node_modules/pirates/lib/index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)

Node.js v18.16.0

Version

1.3.56

Additional context

No response

@lolopinto lolopinto added the C-bug label May 5, 2023
@kdy1 kdy1 added this to the Planned milestone May 5, 2023
@kdy1 kdy1 self-assigned this May 8, 2023
@kdy1 kdy1 closed this as completed in #7363 May 8, 2023
kdy1 added a commit that referenced this issue May 8, 2023
@lolopinto
Copy link
Author

is it possible to get a new @swc/core version with this fix?

@kdy1 kdy1 modified the milestones: Planned, v1.3.57 May 9, 2023
lolopinto added a commit to lolopinto/ent that referenced this issue May 10, 2023
uses https://github.com/swc-project/swc-node

fixes #792

cannot use ts-node anymore because it doesn't provide an option for .swcrc
TypeStrong/ts-node#1856

TODO: depends on swc-project/swc#7358 to actually be used

TODO: remove swc-node in examples/simple

TODO: move .swcrc write in generate_ts_code.go into central location
@Tjerk-Haaye-Henricus

This comment has been minimized.

@swc-bot
Copy link
Collaborator

swc-bot commented Jul 4, 2023

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 Jul 4, 2023
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