UNPKG

siphon-cli

Version:

Simple bundler for web applications. 📦🔧🧡

93 lines (92 loc) • 3.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.gen_utils = void 0; var types_1 = require("../../../../types"); var gen_utils = (function () { function gen_utils() { this.state = ""; this.indentLevel = 0; this.global = this; this.lineLength = 0; this.verticalAlign = 0; } gen_utils.prototype.fail = function () { }; gen_utils.prototype.render = function (node) { var _a; this.global[(_a = node === null || node === void 0 ? void 0 : node.type) !== null && _a !== void 0 ? _a : "fail"](node); }; gen_utils.prototype.write = function (text) { this.state += text; this.lineLength += text.length; }; gen_utils.prototype.writeIf = function (text, condition) { if (condition) this.write(text); }; gen_utils.prototype.renderTopLevel = function (node) { if (node.type === "ExpressionStatement" && /Function|Object|Class/.test(node.expression.type)) { this.write("("); this.render(node.expression); this.write(")"); } else this.render(node); }; gen_utils.prototype.newline = function () { if (this.options.format) { this.write("\n"); this.lineLength = 0; for (var x = 0; x < this.indentLevel; x++) this.write(" "), (this.lineLength += 2); } }; gen_utils.prototype.comma = function (node, i) { if (i !== node.length - 1 && !(node[i] instanceof types_1.EmptyNode)) { this.write(","); this.space(); } }; gen_utils.prototype.space = function (inBetween) { if (this.options.format) this.state += " ".concat(inBetween ? "".concat(inBetween, " ") : ""); else if (inBetween) this.write(inBetween); }; gen_utils.prototype.sequence = function (list, type) { var _a; var i = 0; if (list.length > 2) { this.indentLevel++; if (type !== "VariableDeclaration" && type !== "SequenceExpression") this.newline(); } else if (((_a = list[0]) === null || _a === void 0 ? void 0 : _a.type) === "Property" && list[0].method) { this.indentLevel++; this.newline(); } for (i; list[i]; i++) { this.render(list[i]); this.comma(list, i); if (list.length > 2 && i !== list.length - 1 && list[i].type !== "EmptyNode") this.newline(); } if (list.length > 2) { this.indentLevel--; if (type !== "VariableDeclaration") this.newline(); } else if (type === "ObjectExpression" && list[0].method) { this.indentLevel--; this.newline(); } }; gen_utils.prototype.erase = function (length) { if (length === void 0) { length = 1; } this.state = this.state.slice(0, -length); }; return gen_utils; }()); exports.gen_utils = gen_utils;