diff --git a/lib/6to5/transformers/let-scoping.js b/lib/6to5/transformers/let-scoping.js index 238946cde5..7345cdd7a7 100644 --- a/lib/6to5/transformers/let-scoping.js +++ b/lib/6to5/transformers/let-scoping.js @@ -44,7 +44,7 @@ exports.VariableDeclaration = function (node, parent, file) { }; if (node.type === "FunctionDeclaration") { - node.type = "FunctionExpression"; + util.ensureExpressionType(node); var declar = b.variableDeclaration("var", [ b.variableDeclarator(node.id, callNode()) ]); diff --git a/lib/6to5/transformers/modules.js b/lib/6to5/transformers/modules.js index 4e445d50d6..e0af365ad7 100644 --- a/lib/6to5/transformers/modules.js +++ b/lib/6to5/transformers/modules.js @@ -72,11 +72,7 @@ var pushExportDeclaration = function (node, parent, nodes) { var declar = node.declaration; if (node.default) { - if (declar.type === "FunctionDeclaration") { - declar.type = "FunctionExpression"; - } else if (declar.type === "ClassDeclaration") { - declar.type = "ClassExpression"; - } + util.ensureExpressionType(declar); nodes.push(util.template("exports-default", { VALUE: declar diff --git a/lib/6to5/util.js b/lib/6to5/util.js index 5d23a33f78..bfef7374f6 100644 --- a/lib/6to5/util.js +++ b/lib/6to5/util.js @@ -24,6 +24,14 @@ exports.list = function (val) { return val ? val.split(",") : []; }; +exports.ensureExpressionType = function (node) { + node.type = { + FunctionDeclaration: "FunctionExpression", + ClassDeclaration: "ClassExpression" + }[node.type] || node.type; + return node; +}; + exports.getUid = function (parent, file) { var node;