Incorrectly converted spread operator on string
- Dominant language
- JavaScript
- Stars
- 874
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
I see there are a number of other issues related to the spread operator which have been reported, but I think this one dealing with strings is a separate case.
I had a function in my code that was meant to transform a base64-encoded string into a Uint8Array:
`base64 => new Uint8Array([...atob(base64)].map(char => char.charCodeAt(0)));`
Buble unfortunately converts the above code into this:
`function (base64) { return new Uint8Array([].concat( atob(base64) ).map(function (char) { return char.charCodeAt(0); })); };`
Instead of splitting the string value `atob(base64)` up into an array of individual characters, all that was produced was an array of length one, with the entire unbroken string inside the array as the single element. The result was that no matter how long the base64 input was, only a single-byte array would be produced.
I was able to work around the problem by changing the original code to this:
`base64 => new Uint8Array(atob(base64).split('').map(char => char.charCodeAt(0)));`
Even though I have a workaround for now, I thought you might want to know about this bug.
Contributor guide
No contributing guide indexed for this repository
Research direction
No source file or test is named in the issue. Start by reproducing the arrow-function example and tracing Buble's spread-operator transformation; done means the generated code expands a string into individual characters and a regression test covers the reported Uint8Array case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100