Error transpiling spread Array factory
- Dominant language
- JavaScript
- Stars
- 874
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
Bublé parses `[ ...Array(length) ]` as `[].concat( Array(length) )` witch is not equivalent.
Spreading `Array` factory returns an array with undefined values.
```js
[ ...Array(2) ] === [undefined, undefined]
[ ...Array(2) ].length === 2
```
Concating `Array` factory returns an empty array with defined length.
```js
[].concat( Array(2) ) === []
[].concat( Array(2) ).length === 2
```
#### What I get?
```js
[].concat( Array(length) )
```
#### What I expected?
```js
Array.apply( null, Array(length) )
```
OR
```js
Array.prototype.concat.apply( [], Array(length) )
```
OR
```js
[].concat.apply( [], Array(length) )
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the spread-expression transpilation path that turns `[ ...Array(length) ]` into a concat call, then reproduce the issue with the examples in this report. Done means the transpiled result preserves the source array's undefined elements and length rather than producing an empty sparse array.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100