-
Notifications
You must be signed in to change notification settings - Fork 581
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
let block bindings not enforcing TDZ errors #1382
Comments
Ideally this |
Traceur does not yet support TDZ as commented by @arv in some other issue. I also hope TDZ to throw errors during compilation when it is implemented. |
There are some static checks that can be done but to fully handle it you would need dynamic checks. Due to function hoisting you cannot do this statically. let a = f();
const b = 2;
function f() { return b; } One option is to add a guard on all lookups but that is pretty expensive. function assertInitialized(v) {
if (v === UNITIALIZED) throw new ReferenceError();
return v;
}
var a = UNITIALIZED;
a = 1;
f();
var b = UNITIALIZED;
b = 2;
function f() {
return assertInitialized(b);
} but combining this with some static analysis we could probably remove most of them. |
@arv consider this code: let x;
x; // undefined Accessing Also your example above doesn't make much sense to me. The return value of |
I guess the first part of my comment above can be solved by explicitly assigning |
@UltCombo That was mostly illustrative. It has errors and is incomplete. The compiled output should be something more along the lines of: $traceurRuntime.UNITIALIZED = {};
$traceurRuntime.assertInitialized = function(v) {
if (v === UNITIALIZED) throw new ReferenceError();
return v;
}; var a = $traceurRuntime.UNITIALIZED;
var b = $traceurRuntime.UNITIALIZED;
a = f();
b = 2;
function f() {
return $traceurRuntime.assertInitialized(b);
} On the second point. |
@arv makes perfect sense, thanks. |
My sample didn't show that we need to test assignment too. |
Example:
The spec says that an error should happen on line 2. But currently traceur is transpiling that snippet to:
And thus no such error is occurring as it should.
Will traceur change its transpiling to enforce such errors? Or will it statically find them and report errors during compilation?
The text was updated successfully, but these errors were encountered: