UNPKG

decaffeinate-parser

Version:

A better AST for CoffeeScript, inspired by CoffeeScriptRedux.

24 lines (23 loc) 1.31 kB
"use strict"; exports.__esModule = true; var coffee_lex_1 = require("coffee-lex"); var nodes_1 = require("../nodes"); var getLocation_1 = require("../util/getLocation"); var mapAny_1 = require("./mapAny"); var mapPossiblyEmptyBlock_1 = require("./mapPossiblyEmptyBlock"); function mapWhile(context, node) { var _a = getLocation_1["default"](context, node), line = _a.line, column = _a.column, start = _a.start, end = _a.end, raw = _a.raw; var startTokenIndex = context.sourceTokens.indexOfTokenStartingAtSourceIndex(start); var startToken = startTokenIndex && context.sourceTokens.tokenAtIndex(startTokenIndex); if (startToken && startToken.type === coffee_lex_1.SourceType.LOOP) { return new nodes_1.Loop(line, column, start, end, raw, mapPossiblyEmptyBlock_1["default"](context, node.body)); } var condition = mapAny_1["default"](context, node.condition); var guard = node.guard ? mapAny_1["default"](context, node.guard) : null; var body = mapPossiblyEmptyBlock_1["default"](context, node.body); if (body instanceof nodes_1.Block && body.start < condition.start) { body = body.withInline(true); } return new nodes_1.While(line, column, start, end, raw, condition, guard, body, node.condition.inverted === true); } exports["default"] = mapWhile;