bublejs / buble

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

Function declarations within blocks are transpiled into code that breaks on some pre-ES2015 targets #257

Open anttikissa opened 4 years ago

anttikissa commented 4 years ago

Prior to ES2015, function declarations within blocks were forbidden in strict mode (See MDN web docs):

(function() {
  'use strict';
  if (1) {
    function x() {
      // This results in "Strict mode does not allow function declarations in a
      // lexically nested statement" or a similar error in some older browsers
    }
  }
})();

(Sorry, I didn't have the weapons to test this myself, just consulted the and trust my colleague's report.)

We ran into this issue when we saw some some buble-transformed code crash on iOS 9 Safari.

Would it be within Bublé's scope to transform this into equivalent code that works? E.g.:

(function() {
  'use strict';
  if (1) {
    var x = function x() {
      // Tada!
    }
  }
})();