add block scoped functions - fixes #514

This commit is contained in:
Sebastian McKenzie
2015-01-18 18:23:03 +11:00
parent 436c488ee3
commit 26395a86fa
2 changed files with 20 additions and 0 deletions

View File

@@ -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"),

View File

@@ -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;
};