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

Various transform bugs with the JavaScript decorators proposal #8922

Open
evanw opened this issue May 6, 2024 · 0 comments · May be fixed by #8970
Open

Various transform bugs with the JavaScript decorators proposal #8922

evanw opened this issue May 6, 2024 · 0 comments · May be fixed by #8970
Assignees
Labels
Milestone

Comments

@evanw
Copy link

evanw commented May 6, 2024

Describe the bug

I'm writing tests for the JavaScript decorators proposal as part of esbuild's implementation: https://github.com/evanw/decorator-tests. This issue is mainly to let you know about the tests, which you may find useful. There are over 200 test failures so I'm not going to list them all out here. In certain cases, SWC generates code with syntax errors when transforming code containing JavaScript decorators. These syntax error bugs are reported below. There are also many behavioral bugs that are not reported here but that can be found in the test suite.

Input code

// SWC turns this into code with a syntax error
class Foo {
    accessor foo;
    static accessor foo;
}

// SWC turns this into code with a syntax error
@dec class Bar extends (await Bar) {
    @dec static field;
}

// SWC fails to transform this decorator at all
class Baz {
    accessor foo = @dec class {}
}

Config

{
  "jsc": {
    "target": "es2022",
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "transform": {
      "decoratorVersion": "2022-03"
    }
  }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.5.4&code=H4sIAAAAAAAAA5WPTQrCQAxG93OKb6mrHkAEUfACLlyH6ZQOjBNIIq2W3t2xrVDEjVl%2B%2BXkvVYXL9QS7S1ZYGxUxG8NzHdBFa0HQRzbqEURYnE%2BkijMzBodS5H1QZUHDvJsSNbLovxqjc9WfpEMdPGbckQSht5BrxYY6ivaOtovCNLhQmxhSvcY1FFPBMUwoa8Nym9llh4Ws%2BJGBUnIf0vPHY9hjZTOM5f4LT6dv4DgBAAA%3D&config=H4sIAAAAAAAAA02OsQrDMAxE93yF0ZxCcLd8SHfhqiGF2uakQkPIv1duQuggkO7eHVq7EOipicaw%2BuqHMSYxv0k0DjFSv%2BuVoYKTc0WXbPxppC1VNGGudtDu3iUVsBWoE4a3%2FIztaDNw1kfB67%2FwjNwEOpfcqtsLl%2BFKe7prs30BOXCfLbUAAAA%3D

SWC Info output

No response

Expected behavior

When given valid JavaScript code as input, SWC should never generate code containing syntax errors.

Actual behavior

No response

Version

1.5.4 (the latest on the playground)

Additional context

No response

@evanw evanw added the C-bug label May 6, 2024
@kdy1 kdy1 self-assigned this May 6, 2024
@kdy1 kdy1 added this to the Planned milestone May 6, 2024
@kdy1 kdy1 linked a pull request May 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants