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

Wrong code generation when class method decorator is before a jsdoc comment #4311

Closed
viceice opened this issue Apr 12, 2022 · 1 comment · Fixed by #8575
Closed

Wrong code generation when class method decorator is before a jsdoc comment #4311

viceice opened this issue Apr 12, 2022 · 1 comment · Fixed by #8575
Assignees
Labels
Milestone

Comments

@viceice
Copy link

viceice commented Apr 12, 2022

Describe the bug

Wrong code generation when a async class method has a decorator before a jsdoc comment. It compiles the aync keyword wrongly before the method name.

Input code

const printMemberName = (target: any, memberName: string) => {
    console.log(memberName);
  };

class TestClass {


  // moving the decorator below the comment works as expected

  @printMemberName
  /**
   * some tsdoc comments
   * 
   * Some more comments
   * over
   * multiple
   * lines
   */
  async run(): Promise<boolean> {
    return await Promise.resolve(true);
  }
}

export { TestClass };

Config

{
    "sourceMaps": true,
    "jsc": {
      "parser": {
        "syntax": "typescript",
        "decorators": true,
        "dynamicImport": false,
        "keepClassNames": true
      },
      "transform": null,
      "target": "es2020",
      // TODO: fails, file bug
      "preserveAllComments": true
    },
    "module": {
      "type": "commonjs"
    }
  }

Playground link

https://play.swc.rs/?version=1.2.157&code=H4sIAAAAAAAAA11Qy0rEQBC8B%2FIPfUyCbO7RFcGzIugPTCZNDM5Mh%2B7OxiXsvzsTk1V2DtOPKoqushREYeQh6Av6FvnVeIQjFGq4R23AhPMd%2BCvUgGgk9yUcH2HJM4jPRg1yeHDUF3%2FM8j6hl%2FjnmXVGBD5Q9HntlrRMcF2Dp1PUA%2F1E6NASGyWGFh3N686S9xgUZuIvASOA3yNaxe5X4Onm9FW0qtbDKhCKZlQ6sruObMhW3hPBE%2BMtTifkrfWT02F0uI1uCLix6lSMnIMFnkJRNvDG5AfBh5ZiICZcI2LUiQOY2Qy6kw6MMbYTFsrTnlaeXZKv6JFYYfkXWQryB8N5v3OtAQAA&config=H4sIAAAAAAAAA0WOMQ6DMAxF7%2BKZATGyVcztHSIwKDSJI9tURYi710EUNit5%2F%2F2%2FwSw9tBtkx4JcLlmTui%2B0oGtG6dlnhQoG7ImdEgu0ygtWoGLQ6ILY%2FUbMXXAiLxfxJHZDHE%2BopkJp6qY2TWa0mg8%2BQugoRkx6%2BQKR4GWMPvlxLXt6iiUl95dLU%2FiTu9VEGpbysB2Trc4ikdIssN%2BiM%2BzledLHxh%2BMYVykAAEAAA%3D%3D

Expected behavior

the async keyword should stay before the method name

Actual behavior

The async keyword is compiled before the jsdoc comment.

Version

1.2.165

Additional context

comments are required for istanbul coverage collector.

https://github.com/renovate-reproductions/swc-jest#swc-jest

@viceice viceice added the C-bug label Apr 12, 2022
@kdy1 kdy1 added this to the Planned milestone Apr 12, 2022
@kdy1 kdy1 modified the milestones: Planned, v1.2.199 Jun 11, 2022
@kdy1 kdy1 self-assigned this Dec 22, 2022
kdy1 added a commit that referenced this issue Jan 31, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.4.0 Feb 5, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Mar 6, 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 Mar 6, 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.

3 participants