bublejs / buble

https://buble.surge.sh
MIT License
871 stars 67 forks source link

IE11 does not support const in for..in #144

Closed tschaub closed 6 years ago

tschaub commented 6 years ago

Unfortunately, IE 11 does not support const (or let) in for..in loops (see the kangax compat table). With buble, const is not transformed to var for --target ie:11. So this kind of code breaks:

$ echo 'for (const foo in bar) {}' > input.js
$ npx buble input.js --target ie:11
for (const foo in bar) {}

The most conservative change would be to flip the letConst bit for IE 11. For example:

diff --git a/src/support.js b/src/support.js
index 2183032..7076329 100644
--- a/src/support.js
+++ b/src/support.js
@@ -46,7 +46,7 @@ export const matrix = {
                     8: 0b00000000000000000000,
                     9: 0b01000000000000000000,
                    10: 0b01000000000000000000,
-                   11: 0b01000000000100000000
+                   11: 0b01000000000000000000 // no let/const in for loops
        },
        edge: {
                    12: 0b01001010100101001101,

I'd be happy to propose a PR if this or another solution would be accepted.

adrianheine commented 6 years ago

Yes, please prepare a patch for this!

tschaub commented 6 years ago

@adrianheine see #154 for the PR.