UNPKG

siphon-cli

Version:

Simple bundler for web applications. 📦🔧🧡

388 lines (387 loc) • 11.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var base_1 = require("./base"); base_1.ezra.FunctionDeclaration = function (node) { if (node.async) this.write("async "); this.write("function"); if (node.generator) { this.write("*"); this.space(); } else this.write(" "); this.write(node.id.name); this.space(); this.write("("); this.sequence(node.params); this.write(")"); this.space(); this.render(node.body); }; base_1.ezra.VariableDeclaration = function (node) { this.write(node.kind + " "); this.sequence(node.declarations, node.type); this.write(";"); }; base_1.ezra.VariableDeclarator = function (node) { var _a, _b; this.render(node.id); if (node.init !== null) { this.space("="); if ((_a = node.init) === null || _a === void 0 ? void 0 : _a.type.startsWith("Sequence")) this.write("("); this.render(node.init); if ((_b = node.init) === null || _b === void 0 ? void 0 : _b.type.startsWith("Sequence")) this.write(")"); } }; base_1.ezra.ExpressionStatement = function (node) { this.render(node.expression); this.write(";"); }; base_1.ezra.ClassDeclaration = function (node) { this.write("class "); this.render(node.id); if (node.superClass !== null) { this.write(" extends "); this.render(node.superClass); } this.space(); this.render(node.body); }; base_1.ezra.ClassBody = function (node) { this.write("{"); if (node.body.length === 0) { this.write("}"); return; } this.indentLevel++; this.newline(); for (var i = 0; node.body[i]; i++) { this.render(node.body[i]); this.write(";"); if (i !== node.body.length - 1) this.newline(); } this.indentLevel--; this.newline(); this.write("}"); }; base_1.ezra.MethodDefinition = function (node) { if (node.static) this.write("static "); if (node.computed) this.write("["); if (/get|set/.test(node.kind)) this.write(node.kind + " "); this.render(node.key); if (node.computed) this.write("]"); this.space(); this.write("("); this.sequence(node.value.params); this.write(")"); this.space(); this.render(node.value.body); }; base_1.ezra.PropertyDefinition = function (node) { if (node.static) this.write("static "); if (node.computed) this.write("["); this.render(node.key); if (node.computed) this.write("]"); if (node.value !== null) { this.space("="); this.render(node.value); } }; base_1.ezra.Super = function () { this.write("super"); }; base_1.ezra.BlockStatement = function (node) { this.write("{"); if (node.body.length === 0) { this.write("}"); return; } this.indentLevel++; this.newline(); this.generate(node, this.options); this.indentLevel--; this.newline(); this.write("}"); }; base_1.ezra.ImportDeclaration = function (node) { var _a; var _default = false; this.write("import "); if ((_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.length) { switch (node.specifiers[0].type) { case "ImportDefaultSpecifier": _default = true; this.render(node.specifiers[0]); if (node.specifiers.length > 1) { this.write(", { "); this.sequence(node.specifiers.slice(1)); this.write(" }"); } break; case "ImportNamespaceSpecifier": this.write("* as "); this.render(node.specifiers[0]); break; default: this.write("{ "); this.sequence(node.specifiers); this.write(" }"); } this.write(" from "); } this.render(node.source); this.write(";"); }; base_1.ezra.ImportDefaultSpecifier = function (node) { this.write(node.local.name); }; base_1.ezra.ImportNamespaceSpecifier = function (node) { this.write(node.local.name); }; base_1.ezra.ImportSpecifier = function (node) { this.write(node.imported.name); if (node.local.name !== node.imported.name) { this.write(" as "); this.write(node.local.name); } }; base_1.ezra.ExportNamedDeclaration = function (node) { this.write("export "); if (node.declaration === null) { this.write("{ "); this.sequence(node.specifiers); this.write(" }"); } else { this.render(node.declaration); return; } if (node.source !== null) { this.write(" from "); this.render(node.source); } this.write(";"); }; base_1.ezra.ExportDefaultDeclaration = function (node) { this.write("export default "); this.render(node.declaration); this.write(";"); }; base_1.ezra.ExportSpecifier = function (node) { this.write(node.local.name); if (node.local.name !== node.exported.name) { this.write(" as "); this.write(node.exported.name); } }; base_1.ezra.ExportAllDeclaration = function (node) { this.write("export *"); if (node.exported !== null) { this.write(" as "); this.render(node.exported); } this.write(" from "); this.render(node.source); }; base_1.ezra.LabeledStatement = function (node) { this.write(node.label.name + ":"); this.space(); this.renderTopLevel(node.body); }; base_1.ezra.EmptyStatement = function (node) { this.write(";"); }; base_1.ezra.IfStatement = function (node) { var _a, _b, _c, _d; this.write("if"); this.space(); this.write("("); this.render(node.test); this.write(")"); this.space(); if ((this.lineLength >= 25 && ((_a = node.consequent) === null || _a === void 0 ? void 0 : _a.type) !== "BlockStatement") || !["ExpressionStatement", "BlockStatement"].includes((_c = (_b = node.consequent) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : "")) { this.indentLevel++; this.newline(); this.renderTopLevel(node.consequent); this.indentLevel--; } else this.renderTopLevel(node.consequent); if (node.alternate !== null) { if (((_d = node.consequent) === null || _d === void 0 ? void 0 : _d.type) !== "BlockStatement") this.newline(); else this.space(); this.write("else "); this.renderTopLevel(node.alternate); } }; base_1.ezra.WhileStatement = function (node) { this.write("while"); this.space(); this.write("("); this.render(node.test); this.write(")"); this.space(); this.renderTopLevel(node.body); }; base_1.ezra.DoWhileStatement = function (node) { var _a; this.write("do "); this.renderTopLevel(node.body); if (((_a = node.body) === null || _a === void 0 ? void 0 : _a.type) !== "BlockStatement") this.newline(); else this.space(); this.write("while"); this.space(); this.write("("); this.render(node.test); this.write(");"); }; base_1.ezra.SwitchStatement = function (node) { this.write("switch"); this.space(); this.write("("); this.render(node.discriminant); this.write(")"); this.space(); this.write("{"); if (node.cases.length) { this.indentLevel++; this.newline(); for (var i = 0; node.cases[i]; i++) { this.render(node.cases[i]); if (i !== node.cases.length - 1) this.newline(); } this.indentLevel--; this.newline(); } this.write("}"); }; base_1.ezra.SwitchCase = function (node) { if (node.test !== null) { this.write("case "); this.render(node.test); this.write(":"); } else this.write("default:"); if (node.consequent.length) { this.indentLevel++; this.newline(); for (var i = 0; node.consequent[i]; i++) { this.renderTopLevel(node.consequent[i]); if (i !== node.consequent.length - 1) this.newline(); } this.indentLevel--; } }; base_1.ezra.ForStatement = function (node) { this.write("for"); this.space(); this.write("("); if (node.init !== null) { this.render(node.init); if (node.init.type.endsWith("Expression")) this.write(";"); } else this.write(";"); this.space(); if (node.test !== null) this.render(node.test); this.write(";"); this.space(); if (node.update !== null) this.render(node.update); this.write(")"); this.space(); this.renderTopLevel(node.body); }; base_1.ezra.ForOfStatement = function (node) { this.write("for"); if (node.await) this.write(" await"); this.space(); this.write("("); this.render(node.left); if (node.left.type === "VariableDeclaration") this.erase(); this.write(" of "); this.render(node.right); this.write(")"); this.space(); this.renderTopLevel(node.body); }; base_1.ezra.ForInStatement = function (node) { this.write("for"); this.space(); this.write("("); this.render(node.left); if (node.left.type === "VariableDeclaration") this.erase(); this.write(" in "); this.render(node.right); this.write(")"); this.space(); this.renderTopLevel(node.body); }; base_1.ezra.BreakStatement = function (node) { this.write("break;"); }; base_1.ezra.ContinueStatement = function (node) { this.write("continue"); if (node.label !== null) this.write(" " + node.label.name); this.write(";"); }; base_1.ezra.ReturnStatement = function (node) { this.write("return"); if (node.argument !== null) { this.write(" "); this.render(node.argument); } this.write(";"); }; base_1.ezra.ThrowStatement = function (node) { this.write("throw "); this.render(node.argument); this.write(";"); }; base_1.ezra.TryStatement = function (node) { this.write("try "); this.render(node.block); if (node.handler !== null) { this.space(); this.write("catch"); this.space(); if (node.handler.param !== null) { this.write("("); this.write(node.handler.param.name); this.write(")"); this.space(); } this.render(node.handler.body); } if (node.finalizer !== null) { this.space(); this.write("finally"); this.space(); this.render(node.finalizer); } };