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

Class fields named 'export' not allowed when using decorators #5276

Closed
maclockard opened this issue Jul 22, 2022 · 1 comment · Fixed by #8739
Closed

Class fields named 'export' not allowed when using decorators #5276

maclockard opened this issue Jul 22, 2022 · 1 comment · Fixed by #8739
Assignees
Labels
Milestone

Comments

@maclockard
Copy link

Describe the bug

When using the option "decorators": true, using the name export for class fields and methods is no longer allowed, returning this error:

  × `export` is not allowed here
   ╭─[file.js:3:3]
 3 │ export = true;
   · ──────
   ╰────


Caused by:
    0: failed to process input file
    1: Syntax Error
Error: Failed to compile 1 file with swc.
    at Object.assertCompilationResult (/Users/maclockard/workspace/hex-inc/hex/node_modules/@swc/cli/lib/swc/util.js:113:15)
    at files (/Users/maclockard/workspace/hex-inc/hex/node_modules/@swc/cli/lib/swc/file.js:173:18)
    at async _default (/Users/maclockard/workspace/hex-inc/hex/node_modules/@swc/cli/lib/swc/file.js:192:9)

This error occurs for both syntax "ecmascript" and "typescript". Also worth noting with the same config, the name export is allowed if there is not a decorator on the field.

Input code

export class MyClass {
  @MyDecorator()
  export = true;
}

Config

{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "decorators": true
    }
  }
}

Playground link

https://play.swc.rs/?version=1.2.218&code=H4sIAAAAAAAAA0utKMgvKlFIzkksLlbwrXQG09VcCgoOvpUuqcn5RYkl%2BUUamkCBVIhKW4WSotJUa65aAJrlKr86AAAA&config=H4sIAAAAAAAAA0WOQQoDIQxF75K123bhHXqI4GQGy2gkyUBFvHu1WGYX%2Fn%2F%2FkQZvDeAbFBQlmZfWbPgBDxQSapBYDBxsFFjQWBS8yUVuDAe046nUHRjKQTZH%2Bhj0yay0Wgcp5rjX6Q6cipDqXWE%2Bzj%2FZhyjxds2ggdVCP%2BET%2Bu1Yu6ivBc5n%2BhejSMoXxwAAAA%3D%3D

Expected behavior

I would expect swc to be able to compile a class that uses the word export as a field name or method name when using decorators.

Actual behavior

No response

Version

1.2.218

Additional context

Here's an example of typescript compiling the exact same code: playground link (ignore the type error for now, its just because I'm not defining the decorator to keep the code snippet short).

@kdy1 kdy1 added this to the Planned milestone Jul 23, 2022
kdy1 added a commit to kdy1/swc that referenced this issue Aug 29, 2022
@kdy1 kdy1 modified the milestone: Planned Apr 20, 2023
@kdy1 kdy1 self-assigned this Mar 12, 2024
kdy1 added a commit that referenced this issue Mar 14, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.4.8 Mar 15, 2024
@swc-bot
Copy link
Collaborator

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