UNPKG

decaffeinate-parser

Version:

A better AST for CoffeeScript, inspired by CoffeeScriptRedux.

32 lines (31 loc) 1.2 kB
"use strict"; 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; }; exports.__esModule = true; var nodes_1 = require("decaffeinate-coffeescript2/lib/coffeescript/nodes"); var util_1 = require("util"); var isComparisonOperator_1 = require("./isComparisonOperator"); function unwindChainedComparison(node) { var operands = []; for (var link = node;;) { if (link instanceof nodes_1.Op && isComparisonOperator_1["default"](link)) { var first = link.first, second = link.second; if (!second) { throw new Error("unexpected unary operator inside chained comparison: " + util_1.inspect(node)); } operands = __spreadArrays([second], operands); link = first; } else { operands = __spreadArrays([link], operands); break; } } return operands; } exports["default"] = unwindChainedComparison;