New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDZ issues #527

Closed
UltCombo opened this Issue Jan 18, 2015 · 6 comments

Comments

Projects
None yet
4 participants
@UltCombo

UltCombo commented Jan 18, 2015

So 6to5 v2.13.1 started checking for early TDZ errors regarding block bindings, which is very nice!

However, here are some issues I've found:

Should throw:

let x = x;

Should throw:

f();
let x;
function f() {
    x;
}

Should not throw:

function f() {
    x;
}
let x;
f();

All of the above test cases are currently failing in v2.13.1. Naive static analysis comparing line/col numbers such as implemented in 7c47017 is rather error-prone as seen in the examples above, even to the point of giving false positives which is a huge issue IMO.

To cover all the cases above properly, we'd need runtime assertions. My suggestion would to split TDZ checking from the default block binding transformer, and have an option to enable runtime TDZ assertions.

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Jan 18, 2015

Member

I kind of shoehorned them in there because it was requested in the gitter chat, probably should have left it out until it was more solid.

Member

kittens commented Jan 18, 2015

I kind of shoehorned them in there because it was requested in the gitter chat, probably should have left it out until it was more solid.

@kittens kittens closed this in ca41612 Jan 18, 2015

kittens added a commit that referenced this issue Jan 18, 2015

@UltCombo

This comment has been minimized.

Show comment
Hide comment
@UltCombo

UltCombo Jan 18, 2015

Awesome, thanks!

UltCombo commented Jan 18, 2015

Awesome, thanks!

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Jan 18, 2015

Member

Woops, referenced the wrong issue with ca41612

Member

kittens commented Jan 18, 2015

Woops, referenced the wrong issue with ca41612

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Jan 18, 2015

Member

Released as of 2.13.2, thanks!

Member

kittens commented Jan 18, 2015

Released as of 2.13.2, thanks!

@Macil Macil referenced this issue Sep 8, 2015

Closed

let/const #784

5 of 6 tasks complete
@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Oct 26, 2016

Member

As this issue is closed, should I expected correct TDZ semantics in babel today?

in v8:

let x = x;
Uncaught ReferenceError:  x is not defined

via babel transpile:

var x = x; // output, and no TDZ error
Member

stefanpenner commented Oct 26, 2016

As this issue is closed, should I expected correct TDZ semantics in babel today?

in v8:

let x = x;
Uncaught ReferenceError:  x is not defined

via babel transpile:

var x = x; // output, and no TDZ error
@hzoo

This comment has been minimized.

Show comment
Hide comment
@hzoo

hzoo Oct 26, 2016

Member

@stefanpenner sorry this should be better documented but it was a separate transform ^. In babel 6 it's under an option

{
  "presets": [],
  "plugins": [
    ["transform-es2015-block-scoping", { "tdz": true }]
  ]
}
  throw new ReferenceError("x is not defined - temporal dead zone");
  ^

ReferenceError: x is not defined - temporal dead zone
Member

hzoo commented Oct 26, 2016

@stefanpenner sorry this should be better documented but it was a separate transform ^. In babel 6 it's under an option

{
  "presets": [],
  "plugins": [
    ["transform-es2015-block-scoping", { "tdz": true }]
  ]
}
  throw new ReferenceError("x is not defined - temporal dead zone");
  ^

ReferenceError: x is not defined - temporal dead zone

@lock lock bot added the outdated label May 6, 2018

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.