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

[Bug]: "Decorator arguments must be moved inside parentheses:.." #4261

Open
markkelsall opened this issue Jan 30, 2024 · 3 comments
Open

[Bug]: "Decorator arguments must be moved inside parentheses:.." #4261

markkelsall opened this issue Jan 30, 2024 · 3 comments

Comments

@markkelsall
Copy link

Version

29.1.2

Steps to reproduce

Building an Express app using razzlejs that uses babel & the required babel plugins to support decorators in TS5 (not experimental)

Application builds, runs great, just can't use jest to test with following output:

I have the following dependencies:
ts-jest: 29.1.2
babel-jest: 29.7.0
typescript: 5.3.2

jest config for ts-jest:
transform = {
"ts-jest",
{
tsConfig: "tsconfig.json",
babelConfig: "babel.config.js",
},
}

babel config:

presets: [['@babel/preset-env', {targets: {node: 'current'}}], "@babel/preset-react", "@babel/preset-typescript"],
    plugins: [
        ["@babel/plugin-proposal-decorators", { version: "2023-05" }],
        [
            "@babel/plugin-proposal-class-properties",
            {
                loose: true,
            },
        ],
        [
            "@babel/plugin-transform-runtime",
            {
                regenerator: true,
            },
        ],
        ["@babel/plugin-proposal-private-methods", { loose: true }],
        ["@babel/plugin-proposal-private-property-in-object", { loose: true }],
        "@babel/plugin-proposal-object-rest-spread",
        "@babel/plugin-proposal-optional-chaining",
        "@babel/plugin-proposal-nullish-coalescing-operator",
        "@babel/plugin-transform-async-to-generator",
        "@babel/plugin-syntax-class-properties",
        "@babel/plugin-syntax-object-rest-spread",
        "@babel/plugin-transform-react-inline-elements",
        "@babel/plugin-transform-react-constant-elements",
        "@babel/plugin-syntax-dynamic-import",
    ],

Get the following output:
SyntaxError: /path/to/controllers/Controller.ts: Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'. (7:49)

If I remove the ts-jest config that points to babelConfig then it falls over saying to add the babel decorators plugin, so I know it's picking up my working babel config. However it seems to using an old/different way of compiling the decorators in the build. Does it support that stage of the decorators proposal? 202305?

Thanks

Expected behavior

Expect compiled output to be aligned with the specified version of decorators so that jest can read the file correctly

Actual behavior

SyntaxError: /path/to/controllers/Controller.ts: Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'. (7:49)

Debug log

Will attach after created

Additional context

No response

Environment

System:
    OS: macOS 14.1.2
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.17 - ~/.yarn/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
@markkelsall
Copy link
Author

ts-jest.log

@markkelsall
Copy link
Author

Also found this stackoverflow but not found a resolution - https://stackoverflow.com/questions/76136892/unexpected-token-for-typescript-decorator

@markkelsall
Copy link
Author

Update: Switching the transform pattern match of .ts files to use babel-jest works, but not with ts-jest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant