inherit generator comments and add block hoisting - fixes #196

This commit is contained in:
Sebastian McKenzie
2014-11-20 15:09:07 +11:00
parent afaf3fb0c0
commit 4a1c393bdb
2 changed files with 12 additions and 7 deletions

View File

@@ -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]);

View File

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