google / google/closure-compiler
Create empty array using destructuring
Open
internal-issue-created
triage-done
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Closure Compiler does not create empty iterable arrays using destructuring.
`[...Array(3)]`
### Given the input:
```
const html =
`${[...Array(3)].reduce((acc, _, i) => acc +=
`${i}`, '')}
`
console.log(html)
```
### A) We would expect the output to be:
`'012'`
https://jsfiddle.net/v9m7fzrd/
### B) Instead, what we're getting is:
`''`
You can solve this issue in Closure Compiler using `Array(3).fill()` instead of [...Array(3)]
Closure Compiler does not warn you or gives you an error. We noticed this while checking the user interface.
Contributor guide
Assessment
This issue has not been assessed yet.