babel/lib/6to5/transformers/arrow-functions.js
Sebastian McKenzie c97696c224 first commit
2014-09-28 23:39:22 +10:00

28 lines
573 B
JavaScript

var traverse = require("../traverse");
var util = require("../util");
exports.ArrowFunctionExpression = function (node) {
var body = node.body;
if (body.type !== "BlockStatement") {
body = {
type: "BlockStatement",
body: [{
type: "ReturnStatement",
argument: body
}]
};
}
node.expression = false;
node.body = body;
node.type = "FunctionExpression";
if (traverse.hasType(node, "ThisExpression")) {
return util.template("function-bind-this", {
FUNCTION: node
});
} else {
return node;
}
};