decaffeinate-parser
Version:
A better AST for CoffeeScript, inspired by CoffeeScriptRedux.
20 lines (19 loc) • 853 B
JavaScript
import { Block } from 'decaffeinate-coffeescript2/lib/coffeescript/nodes';
import { SeqOp } from '../nodes';
import isCommentOnlyNode from '../util/isCommentOnlyNode';
import mapAny from './mapAny';
export default function mapParens(context, node) {
if (!(node.body instanceof Block)) {
return mapAny(context, node.body);
}
var expressions = node.body.expressions;
expressions = expressions.filter(function (expr) { return !isCommentOnlyNode(expr); });
if (expressions.length === 1) {
return mapAny(context, expressions[0]);
}
return expressions
.map(function (expression) { return mapAny(context, expression); })
.reduceRight(function (right, left) {
return new SeqOp(left.line, left.column, left.start, right.end, context.source.slice(left.start, right.end), left, right);
});
}