better block scoped functions
This commit is contained in:
parent
5436e95c9a
commit
faba02afd4
@ -2,23 +2,28 @@
|
||||
|
||||
var t = require("../../types");
|
||||
|
||||
exports.FunctionDeclaration = function (node, parent) {
|
||||
if (t.isProgram(parent) || t.isExportDeclaration(parent)) {
|
||||
exports.BlockStatement = function (node, parent) {
|
||||
if (t.isFunction(parent) || t.isExportDeclaration(parent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// this is to avoid triggering the TDZ detection
|
||||
node.id.loc = null;
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var func = node.body[i];
|
||||
if (!t.isFunctionDeclaration(i)) continue;
|
||||
|
||||
var declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
]);
|
||||
// this is to avoid triggering the TDZ detection
|
||||
func.id.loc = null;
|
||||
|
||||
// hoist it up above everything else
|
||||
declar._blockHoist = 2;
|
||||
var declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(func.id, t.toExpression(func))
|
||||
]);
|
||||
|
||||
// todo: name this
|
||||
node.id = null;
|
||||
// hoist it up above everything else
|
||||
declar._blockHoist = 2;
|
||||
|
||||
return declar;
|
||||
// todo: name this
|
||||
func.id = null;
|
||||
|
||||
func.body[i] = declar;
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user