You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug in the __rest helper function for numeric properties #38299
Search Terms: namespace rest export number numeric object destructuring pattern
Code
namespaceFoo{exportlet{0: a, ...b}=[0,1]console.log(JSON.stringify({a, b}))}
Expected behavior:
I expect this to log {"a":0,"b":{"1":1}} because that's what you get when you run the following JavaScript natively:
let{0: a, ...b}=[0,1];console.log(JSON.stringify({a, b}))
Actual behavior:
This actually logs {"a":0,"b":{"0":0,"1":1}}.
I'm working on my own TypeScript parser for esbuild, a JavaScript bundler, and I noticed that the code TypeScript generates for destructuring object properties has this bug. The generated code for the sample above looks like this:
The problem is that the numeric property is passed to __rest as a number, not as a string, but __rest is implemented using indexOf which doesn't consider 0 and "0" to be equal.
I think the most straightforward fix would be for the compiler to emit __rest(_a, ["0"]) instead of __rest(_a, [0]).
Activity