UNPKG

siphon-cli

Version:

Simple bundler for web applications. 📦🔧🧡

86 lines (85 loc) • 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var structures_1 = require("../../../structures"); var types_1 = require("../../../../types"); var utils_1 = require("../../../../utils"); var base_1 = require("./base"); base_1.ezra.group = function (context) { if (context === void 0) { context = "expression"; } var closure = this.belly.top(), groupBody = [], parentOps = this.operators, parentBelly = this.belly; this.contexts.push(context); this.outerspace(); this.operators = new structures_1.Stack(); this.belly = new structures_1.Stack(); while (!(this.text[this.i] === undefined) && this.text[this.i] !== utils_1.counterpart[closure]) { var statement = this.statement(context); if (statement !== undefined) groupBody.push(statement); this.outerspace(); if (this.text[this.i] === "/" && context === "JSX_attribute") break; } if (this.text[this.i] === undefined) this.raise("EXPECTED", utils_1.counterpart[closure]); else if (context !== "JSX_attribute") this.eat(utils_1.counterpart[closure]); this.operators = parentOps; this.belly = parentBelly; this.contexts.pop(); switch (context) { case "import": case "export": case "block": case "switch_block": case "for_params": case "object": case "parameters": case "array": case "class_body": case "JSX_attribute": return groupBody; case "call": return groupBody[0]; case "property": if (groupBody.length !== 1) this.raise("JS_COMMA_IN_COMPUTED_PROP"); if (groupBody[0].type !== "ExpressionStatement") { this.raise("EXPRESSION_EXPECTED"); } else return groupBody[0].expression; case "function": var args = []; if (groupBody.length > 1) this.raise("EXPRESSION_EXPECTED"); if (groupBody[0] instanceof types_1.ExpressionStatement) { var expression = groupBody[0].expression; if (expression instanceof types_1.SequenceExpression) { var expressions = expression.expressions; for (var i = 0; expressions[i]; i++) { args.push(expressions[i]); } } else args.push(expression); } else if (groupBody[0] !== undefined) this.raise("EXPRESSION_EXPECTED"); return args; case "expression": if (groupBody[0] === undefined) { var mark = this.i - 2; this.outerspace(); if (this.eat("=>")) return this.arrowFunctionExpression(undefined, mark); } default: if (groupBody.length > 1) { this.raise("EXPRESSION_EXPECTED"); } else return groupBody[0]; } return groupBody; };