babel: Block scoping temporal dead zones

Basically, in ES6 lets don’t hoist, but with 6to5, they do. This leads to this innocent snippet:

    i
    let i;

Working fine in 6to5, but actually being a ticking time bomb when you move to a real ES6 environment where it throws a “Reference Error not defined” and takes down the entire script because lets don’t hoist. This seems particularly bad because its not a feature not working that then does work, but quite the opposite, a feature working that then crashes.

I haven’t thought about it deeply yet, but I think its actually syntactically apparent when the variable is in the “temporal dead zone”, and could simply be syntactically replaced with a throw:

    i
    let i;

—>

    throw "ReferenceError"
    var i;

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 17 (15 by maintainers)

Most upvoted comments

I have kind of two competing feelings on this. On the one hand I agree that if its not default it probably won’t get used (especially with an issue that is subtle, as opposed to turning on some crazy cool feature).

My other feeling is that this unfortunately is the intersection of “very easy error to make”, and “potentially catastrophic when moving to ES6/iojs/whatever”. That is to say, everyone is so used to hoisting that its totally reasonable to use this like a var, so given the promise that this will definitely get you ready to switch to ES6 when its ready, it would be very frustrating to have your node app then crash immediately on launch.

For the record, I’m not asking for it. I think your time is better spent on other issues. However, if it were available, then I’d add that optional transform to development builds.