Skip to content
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
Closed

TDZ issues #527

UltCombo opened this issue Jan 18, 2015 · 6 comments
Labels

Comments

@UltCombo
Copy link

@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.

@sebmck
Copy link
Contributor

@sebmck sebmck 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.

@sebmck sebmck closed this in ca41612 Jan 18, 2015
sebmck added a commit that referenced this issue Jan 18, 2015
@UltCombo
Copy link
Author

@UltCombo UltCombo commented Jan 18, 2015

Awesome, thanks!

@sebmck
Copy link
Contributor

@sebmck sebmck commented Jan 18, 2015

Woops, referenced the wrong issue with ca41612

@sebmck
Copy link
Contributor

@sebmck sebmck commented Jan 18, 2015

Released as of 2.13.2, thanks!

@Macil Macil mentioned this issue Sep 8, 2015
6 tasks
@stefanpenner
Copy link
Member

@stefanpenner 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
Copy link
Member

@hzoo 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.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants