UNPKG

ts-budgie

Version:

Converts TypeScript code to Budgie.

62 lines 3.03 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); 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; }; Object.defineProperty(exports, "__esModule", { value: true }); var budgie_1 = require("budgie"); var tsutils = require("tsutils"); var budgieLine_1 = require("../../output/budgieLine"); var transformation_1 = require("../../output/transformation"); var unsupported_1 = require("../../output/unsupported"); var lists_1 = require("../../parsing/lists"); var visitor_1 = require("../visitor"); var ForOfStatementVisitor = /** @class */ (function (_super) { __extends(ForOfStatementVisitor, _super); function ForOfStatementVisitor() { return _super !== null && _super.apply(this, arguments) || this; } ForOfStatementVisitor.prototype.visit = function (node) { return [transformation_1.Transformation.fromNode(node, this.sourceFile, this.getTransformationContents(node))]; }; ForOfStatementVisitor.prototype.getTransformationContents = function (node) { var expressionType = this.aliaser.getFriendlyTypeName(node.expression); if (expressionType === undefined) { return [unsupported_1.createUnsupportedTypeBudgieLine()]; } var bodyNodes = this.router.recurseIntoNode(node.statement); var container = this.router.recurseIntoValue(node.expression); var valueType = lists_1.getListValueType(expressionType); var value = this.getContainer(node.initializer); return __spreadArrays([ new budgieLine_1.BudgieLine(budgie_1.CommandNames.ForEachStart, container, valueType, value) ], bodyNodes, [ new budgieLine_1.BudgieLine(budgie_1.CommandNames.ForEachEnd), ]); }; ForOfStatementVisitor.prototype.getContainer = function (initializer) { if (tsutils.isExpression(initializer)) { return initializer.getText(this.sourceFile); } return initializer.declarations[0].getText(this.sourceFile); }; return ForOfStatementVisitor; }(visitor_1.NodeVisitor)); exports.ForOfStatementVisitor = ForOfStatementVisitor; //# sourceMappingURL=forOfStatementVisitor.js.map