decaffeinate-parser
Version:
A better AST for CoffeeScript, inspired by CoffeeScriptRedux.
35 lines (34 loc) • 1.58 kB
JavaScript
;
exports.__esModule = true;
var nodes_1 = require("../nodes");
var getLocation_1 = require("../util/getLocation");
var mapAny_1 = require("./mapAny");
var mapPossiblyEmptyBlock_1 = require("./mapPossiblyEmptyBlock");
function mapFor(context, node) {
var _a = getLocation_1["default"](context, node), line = _a.line, column = _a.column, start = _a.start, end = _a.end, raw = _a.raw;
var keyAssignee = node.index ? mapAny_1["default"](context, node.index) : null;
var valAssignee = node.name ? mapAny_1["default"](context, node.name) : null;
var body = mapPossiblyEmptyBlock_1["default"](context, node.body);
var target = mapAny_1["default"](context, node.source);
var filter = node.guard ? mapAny_1["default"](context, node.guard) : null;
if (body && body.start < target.start) {
body = body.withInline(true);
}
if (node.object) {
var isOwn = node.own;
return new nodes_1.ForOf(line, column, start, end, raw, keyAssignee, valAssignee, target, filter, body, isOwn);
}
else {
if (node.from) {
if (keyAssignee) {
throw new Error('Unexpected key assignee in for...from.');
}
return new nodes_1.ForFrom(line, column, start, end, raw, valAssignee, target, filter, body);
}
else {
var step = node.step ? mapAny_1["default"](context, node.step) : null;
return new nodes_1.ForIn(line, column, start, end, raw, keyAssignee, valAssignee, target, filter, body, step);
}
}
}
exports["default"] = mapFor;