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

var to let/const with empty destructuring #350

Open
pionxzh opened this issue Oct 1, 2023 · 5 comments · May be fixed by #351
Open

var to let/const with empty destructuring #350

pionxzh opened this issue Oct 1, 2023 · 5 comments · May be fixed by #351

Comments

@pionxzh
Copy link
Contributor

pionxzh commented Oct 1, 2023

The rule var to let/const will not transform empty destructuring.

This is not the code that an average human would write. I noticed this pattern from babel's test case and my codemod test.

Input

var arr = [1,2]
var obj = { name: 'John' }

var [] = arr;
var [first, second] = arr
var {} = obj;
var { name } = obj

Actual Output

const arr = [1,2];
const obj = { name: 'John' };

var [] = arr;
const [first, second] = arr;
var {} = obj;
const { name } = obj;

Expected Output

const arr = [1,2];
const obj = { name: 'John' };

const [] = arr;
const [first, second] = arr;
const {} = obj;
const { name } = obj;
@wirekang
Copy link

What is the reason of the empty destructing? Type assertion?

@pionxzh
Copy link
Contributor Author

pionxzh commented Oct 27, 2023

I think the main reason why it exist is just because we can, it valid syntax 😮‍💨 And you cannot simply remove the statement as the statement will trigger a [get].

@wirekang
Copy link

wirekang commented Oct 27, 2023

I didn't mean to be aggressive. I'm wondering why someone/something writes those statements.

@wirekang
Copy link

Oh I get a sense that it's a testing for the syntax itself not for specific logic/side-effect, is that correct?

@pionxzh
Copy link
Contributor Author

pionxzh commented Oct 27, 2023

yes

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

Successfully merging a pull request may close this issue.

2 participants