Siorki / RegPack

Self-contained packer for size-constrained JS code
Other
300 stars 14 forks source link

"Refactor with setInterval" doesn't work with strings #67

Open xem opened 7 years ago

xem commented 7 years ago

(Edited)

Ex: The setInterval feature works with:

a=0;setInterval(function(){a++,b=1},33)

or

a=0;setInterval(e=>{a++,b=1},33);

but not with:

a=0;setInterval("a++",33);

or with the very strange but still valid

a=0;setInterval`a++${33}b=1`;

Thanks!

Siorki commented 7 years ago

Right, the current code is only looking for function patterns, not strings. Getting it to work with your third example should not be too hard a=0;setInterval("a++",33);

For the last one, I give up until I get a good ES6 string parser :) Point made, if you want to use that feature from RegPack, don't golf the core loop into something cryptic, especially using tagged templates. BTW your string setInterval`a++${33}b=1` is equivalent to setInterval(["a++","b=1"],33)

xem commented 7 years ago

Indeed, we wrote an article about it :) It's useful for saving bytes, but not at all in the context of RegPacked code. Anyway, no rush here, I don't need RegPack to understand setInterval with strings to deliver my demos :D Thanks !