add block scoped functions - fixes #514
This commit is contained in:
@@ -44,6 +44,7 @@ transform.moduleFormatters = {
|
||||
_.each({
|
||||
specNoForInOfAssignment: require("./transformers/spec-no-for-in-of-assignment"),
|
||||
specSetters: require("./transformers/spec-setters"),
|
||||
specBlockScopedFunctions: require("./transformers/spec-block-scoped-functions"),
|
||||
|
||||
// playground
|
||||
malletOperator: require("./transformers/playground-mallet-operator"),
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports.FunctionDeclaration = function (node, parent) {
|
||||
if (t.isProgram(parent) || t.isExportDeclaration(parent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
]);
|
||||
|
||||
// hoist it up above everything else
|
||||
declar._blockHoist = 2;
|
||||
|
||||
// todo: name this
|
||||
node.id = null;
|
||||
|
||||
return declar;
|
||||
};
|
||||
Reference in New Issue
Block a user