decaffeinate-parser
Version:
A better AST for CoffeeScript, inspired by CoffeeScriptRedux.
13 lines (12 loc) • 811 B
JavaScript
import mapAny from '../mappers/mapAny';
import { Heregex, RegexFlags } from '../nodes';
import getTemplateLiteralComponents from './getTemplateLiteralComponents';
export default function makeHeregex(context, node, flags) {
var _a = getTemplateLiteralComponents(context, node), quasis = _a.quasis, unmappedExpressions = _a.unmappedExpressions, start = _a.start, end = _a.end;
var startLoc = context.linesAndColumns.locationForIndex(start);
if (!startLoc) {
throw new Error("Expected to find a location for index " + start + ".");
}
var raw = context.source.slice(start, end);
return new Heregex(startLoc.line + 1, startLoc.column + 1, start, end, raw, quasis, unmappedExpressions.map(function (expr) { return (expr ? mapAny(context, expr) : null); }), RegexFlags.parse(flags));
}