google / google/closure-compiler

Create empty array using destructuring

Open
#3,294 4 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.