diff --git a/lib/6to5/transformation/transformers/generators/visit.js b/lib/6to5/transformation/transformers/generators/visit.js index 1c31a3e5a3..b26177103d 100644 --- a/lib/6to5/transformation/transformers/generators/visit.js +++ b/lib/6to5/transformation/transformers/generators/visit.js @@ -9,6 +9,7 @@ */ var runtimeProperty = require("./util").runtimeProperty; +var traverse = require("../../../traverse"); var Emitter = require("./emit").Emitter; var hoist = require("./hoist").hoist; var types = require("ast-types"); @@ -156,12 +157,12 @@ var visitor = types.PathVisitor.fromMethodsObject({ ) ]); - if (node.comments) { - // Copy any comments preceding the function declaration to the - // variable declaration, to avoid weird formatting consequences. - varDecl.comments = node.comments; - node.comments = null; - } + // Copy any comments preceding the function declaration to the + // variable declaration, to avoid weird formatting consequences. + t.inheritsComments(varDecl, node); + t.removeComments(node); + + varDecl._blockHoist = true; var bodyPath = pp.get("body"); var bodyLen = bodyPath.value.length; @@ -175,7 +176,6 @@ var visitor = types.PathVisitor.fromMethodsObject({ } bodyPath.push(varDecl); - } else { t.assertFunctionExpression(node); return t.callExpression(runtimeMarkMethod, [node]); diff --git a/lib/6to5/types/index.js b/lib/6to5/types/index.js index 3e13d640e0..2699529fbd 100644 --- a/lib/6to5/types/index.js +++ b/lib/6to5/types/index.js @@ -250,6 +250,11 @@ t.inheritsComments = function (child, parent) { return child; }; +t.removeComments = function (node) { + delete node.leadingComments; + delete node.trailingComments; +}; + t.inherits = function (child, parent) { child.loc = parent.loc; child.end = parent.end;