UNPKG

decaffeinate-parser

Version:

A better AST for CoffeeScript, inspired by CoffeeScriptRedux.

29 lines (28 loc) 1.09 kB
var __spreadArrays = (this && this.__spreadArrays) || function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; import { Op } from 'decaffeinate-coffeescript2/lib/coffeescript/nodes'; import { inspect } from 'util'; import isComparisonOperator from './isComparisonOperator'; export default function unwindChainedComparison(node) { var operands = []; for (var link = node;;) { if (link instanceof Op && isComparisonOperator(link)) { var first = link.first, second = link.second; if (!second) { throw new Error("unexpected unary operator inside chained comparison: " + inspect(node)); } operands = __spreadArrays([second], operands); link = first; } else { operands = __spreadArrays([link], operands); break; } } return operands; }