Closed
Description
This is similar to #7477 and #8976, but occurs inside closures.
TypeScript Version:
1.9.0-dev.20160620-1.0
Code
const y = (() => x)();
const x = 3;
Expected behavior:
The compilation error "Block-scoped variable x
used before its declaration".
Actual behavior:
The code is compiled to:
var y = (function () { return x; })();
var x = 3;
This sets y
to undefined
.
Additional variants:
This also occurs when the access to the binding x
is in default argument value position:
const y = ((i: number = x) => i)();
const x = 3;
Comparison against spec behavior:
All of the following result in a ReferenceError
being thrown on Node 5.1:
(function() {
'use strict';
var y = (() => x)();
const x = 3;
return y;
})();
(function() {
'use strict';
const y = (() => x)();
const x = 3;
return y;
})();