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: ObjectPat Syntax Error for { a } = { a: 1 } #8945

Closed
caoccao opened this issue May 12, 2024 · 2 comments
Closed

Bug: ObjectPat Syntax Error for { a } = { a: 1 } #8945

caoccao opened this issue May 12, 2024 · 2 comments
Labels

Comments

@caoccao
Copy link

caoccao commented May 12, 2024

Describe the bug

Problem

{ a } = { a: 1 } works in Node.js well, but fails to be parsed by SWC.

Result in Node.js

Welcome to Node.js v20.8.0.
Type ".help" for more information.
> let a
undefined
> { a } = { a: 1 }
{ a: 1 }
> a
1
>

Result in SWC

  x Expression expected
   ,----
 1 | { a } = { a: 1 }
   :       ^
   `----


Caused by:
    0: failed to parse code
    1: Syntax Error

Input code

{ a } = { a: 1 }

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2020",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": false
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.5.5&code=H4sIAAAAAAAAA6tWSFSoVbBVqFZItFIwVKgFABuN%2F0gQAAAA&config=H4sIAAAAAAAAA1VPOw6DMAzdOUXkuQNi6NA79BBWalBQfopTqRHi7g350LL5%2FfzsbRACVpbwEFseM%2FAYmMKJM8PJRvxkBkgaZBmUj3Dr6sqHNKNmKtReFYgYFoolxdM4jS0B2jmmnmicUVbN6b9TOuMDMV%2BNhxXtounaOLRWMO71LmL7JSZP9YI7%2FEy97FwMip89WdfuX4b2MUIYAQAA

SWC Info output

1.5.5

Expected behavior

{ a } = { a: 1 } should pass the syntax check.

Actual behavior

No response

Version

1.5.5

Additional context

No response

@caoccao caoccao added the C-bug label May 12, 2024
@caoccao caoccao changed the title Bug: ObjectLit Syntax Error for { a } = { a: 1 } Bug: ObjectPat Syntax Error for { a } = { a: 1 } May 12, 2024
@kdy1
Copy link
Member

kdy1 commented May 12, 2024

image

It's invalid syntax. nodeREPL parses it as an expression, but it's not a valid statement. The specification says it's a block statement if a line starts with {

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2024
@caoccao
Copy link
Author

caoccao commented May 12, 2024

Thank you for the quick response. You are right.

I just tried in d8 and got an syntax error.

V8 version 12.5.227.6
d8> let a
undefined
d8> { a } = { a: 1 }
(d8):1: SyntaxError: Unexpected token '='
{ a } = { a: 1 }
      ^
SyntaxError: Unexpected token '='

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

No branches or pull requests

2 participants