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]: Variable renaming when destructuring object that has a setter #6360

Open
p51lee opened this issue Nov 5, 2022 · 0 comments
Open

[Bug]: Variable renaming when destructuring object that has a setter #6360

p51lee opened this issue Nov 5, 2022 · 0 comments
Labels

Comments

@p51lee
Copy link

p51lee commented Nov 5, 2022

Describe the bug

When the input code has an object destructuring pattern with the object that has a setter with same parameter name,
then the variable is unnecessarily renamed in the output code.
I know that renaming variables will be okay in most cases, but it would be better to avoid such cases as much as possible, because there are some cases where renaming variable could results in inconsistent behavior, like accessing global variable using property access to globalThis.

Input code

var { x = 0 } = { set y ( x ) { } } ;
console.log(globalThis.x);

Config

No response

Playground link

https://play.swc.rs/?version=1.3.14&code=H4sIAAAAAAAAAytLLFKoVqhQsFUwUKgFktUKxaklCpUKGkAxTSCvVkEHiK25kvPzivNzUvVy8tM10nPykxJzQjIyi%2FUqNK0BODYeDEIAAAA%3D&config=H4sIAAAAAAAAA0WMTQrEIAxG75K1286id5hDBCctFv9IUhgR714tlu7C915ehUMsrBUyshCPS0pU%2FMMKZAOKZZcVTNf6tKEXagYUeScdiiyd%2BZSEJjUQXHRbGSWbQmYSeRHG3T9m66GQfucYKmjJdAc%2F0N7G%2FHPynaLySe0Cj9ke9LUAAAA%3D

Expected behavior

I am using V8 engine to demonstrate the expected result instead of NodeJS.
Since NodeJS is not an engine but a runtime, the behavior of this in NodeJS does not follow ECMAScript specification.


The value of globalThis.x in the input code is 0:

$ d8
V8 version 10.9.0
$ d8 input.js
0

Actual behavior

The variable x is renamed to _$x, and the value of globalThis.x in the output code is undefined:

$ d8 output.js
undefined

Version

1.3.14 (default SWC playground)

Additional context

No response

@p51lee p51lee added the C-bug label Nov 5, 2022
@kdy1 kdy1 added this to the Planned milestone Nov 5, 2022
@kdy1 kdy1 removed this from the Planned milestone Jan 17, 2023
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