Rich-Harris / butternut

The fast, future-friendly minifier
https://butternut.now.sh
MIT License
1.17k stars 17 forks source link

Same identifier in two `for-let-of` loops throws error. #33

Closed Conduitry closed 7 years ago

Conduitry commented 7 years ago
for (let x of a) {}
for (let x of a) {}

x is already declared

If one of the loops is a regular for loop, the exception is still thrown. If both are regular for loops, everything works fine.

Conduitry commented 7 years ago

Something I bumped into while I was narrowing down this error case -

for (let x of a);

This by itself seems to get minified fine. With check: true, it says it generated invalid JS, but it looks valid to me.

Conduitry commented 7 years ago

Actually,

for (let x;;) {}
for (let x;;) {}

minifies as

for(let x;;){}for(x;;){}

which is no good.

I was poking around a bit and I saw a createdScope value on various elements that some code is trying to use, but I don't actually see where it's set. If that's always undefined (falsy) that feels like it could be related to this behavior.

Rich-Harris commented 7 years ago

Thanks – fixed in #37. The short answer for why mysterious properties like createdScope are in the codebase is that I forked it from Bublé several months ago as an experiment for a talk, then left it to gather dust until a few days ago. I'm still trying to figure out my way around it tbh!

Conduitry commented 7 years ago

:+1: The issues with for and for-of loops that I was seeing look fixed in your PR.

I took another look at what I mentioned in my second comment here - there does actually seem to be a code generation error here. I'll open another ticket for that, but it really is a bit of an edge case.