decaffeinate-parser
Version:
A better AST for CoffeeScript, inspired by CoffeeScriptRedux.
28 lines (27 loc) • 1.51 kB
JavaScript
;
exports.__esModule = true;
var SourceType_1 = require("coffee-lex/dist/SourceType");
var nodes_1 = require("../nodes");
var getLocation_1 = require("../util/getLocation");
var mapAny_1 = require("./mapAny");
function mapIn(context, node) {
// We don't use the `negated` flag on `node` because it gets set to
// `true` when a parent `If` is an `unless`.
var _a = getLocation_1["default"](context, node), line = _a.line, column = _a.column, start = _a.start, end = _a.end, raw = _a.raw;
var left = mapAny_1["default"](context, node.object);
var right = mapAny_1["default"](context, node.array);
var isNot = false;
var lastTokenIndexOfLeft = context.sourceTokens.indexOfTokenEndingAtSourceIndex(left.end);
var firstTokenIndexOfRight = context.sourceTokens.indexOfTokenStartingAtSourceIndex(right.start);
var relationTokenIndex = context.sourceTokens.indexOfTokenMatchingPredicate(function (token) { return token.type === SourceType_1["default"].RELATION; }, lastTokenIndexOfLeft, firstTokenIndexOfRight);
if (relationTokenIndex) {
var relationToken = context.sourceTokens.tokenAtIndex(relationTokenIndex);
if (relationToken) {
isNot =
context.source.slice(relationToken.start, relationToken.end) !== 'in';
return new nodes_1.InOp(line, column, start, end, raw, left, right, isNot);
}
}
throw new Error("unable to find RELATION token between operands");
}
exports["default"] = mapIn;