UNPKG

siphon-cli

Version:

Simple bundler for web applications. 📦🔧🧡

163 lines (162 loc) • 5.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var types_1 = require("../../../../types"); var base_1 = require("./base"); base_1.ezra.importDeclaration = function () { var _a, _b; if (this.contexts.top() !== "global" || this.scope.body.find(function (node) { return node.type !== "ImportDeclaration"; })) { this.raise("JS_ILLEGAL_IMPORT"); } var importdec = new types_1.ImportDeclaration(this.i - 6); if (this.eat("{")) { var importspecs = this.group("import"); if (importspecs === undefined) this.raise("IDENTIFIER_EXPECTED"); else (_a = importdec.specifiers).push.apply(_a, importspecs); } else if (this.text[this.i] === "*") { var namespce = new types_1.ImportNamespaceSpecifier(this.i); this.i++; this.outerspace(); if (!this.match("as")) this.raise("EXPECTED", "as"); this.outerspace(); namespce.local = this.identifier(); namespce.loc.end = namespce.local.loc.end; importdec.specifiers.push(namespce); } else if (/'|"/.test(this.text[this.i])) { importdec.source = this.stringLiteral(); importdec.loc.end = this.i; this.outerspace(); this.eat(";"); return importdec; } else { var defaultdec = new types_1.ImportDefaultSpecifier(this.i); defaultdec.local = this.identifier(); defaultdec.loc.end = defaultdec.local.loc.end; importdec.specifiers.push(defaultdec); this.outerspace(); if (this.eat(",")) { this.outerspace(); if (!this.eat("{")) this.raise("OPEN_CURLY_EXPECTED"); else { var importspecs = this.group("import"); if (importspecs === undefined) this.raise("IDENTIFIER_EXPECTED"); else (_b = importdec.specifiers).push.apply(_b, importspecs); } } } this.outerspace(); if (this.match("from")) { this.outerspace(); if (!/'|"/.test(this.text[this.i])) this.raise("JS_UNEXPECTED_TOKEN"); importdec.source = this.stringLiteral(); } else this.raise("EXPECTED", "from"); importdec.loc.end = this.i; this.outerspace(); this.eat(";"); return importdec; }; base_1.ezra.importSpecifier = function () { var importspec = new types_1.ImportSpecifier(this.i - 1); this.outerspace(); importspec.imported = this.identifier(); this.outerspace(); switch (true) { case this.text[this.i] === ",": default: importspec.local = importspec.imported; break; case this.match("as"): this.outerspace(); importspec.local = this.identifier(); this.outerspace(); break; } importspec.loc.end = this.i; if (this.text[this.i] !== "}") this.i++; return importspec; }; base_1.ezra.exportDeclaration = function () { var _a, _b; var start = this.i - 6; this.outerspace(); if (this.match("default")) { var exportDefDec = new types_1.ExportDefaultDeclaration(start); this.outerspace(); exportDefDec.declaration = this.expression(); exportDefDec.loc.end = exportDefDec.declaration.loc.end; this.outerspace(); this.eat(";"); return exportDefDec; } else if (this.text[this.i] === "*") { this.i++; this.outerspace(); var expAll = new types_1.ExportAllDeclaration(start); if (this.match("as")) { this.outerspace(); expAll.exported = this.identifier(); this.outerspace(); } else expAll.exported = null; if (this.match("from")) { this.outerspace(); expAll.source = this.stringLiteral(); expAll.loc.end = expAll.source.loc.end; } else this.raise("EXPECTED", "from"); this.outerspace(); this.eat(";"); return expAll; } else { var exportDec = new types_1.ExportNamedDeclaration(start); if (this.eat("{")) { exportDec.specifiers = this.group("export"); exportDec.loc.end = this.i; this.outerspace(); if (this.match("from")) { this.outerspace(); exportDec.source = this.stringLiteral(); exportDec.loc.end = this.i; } else exportDec.source = null; } else { exportDec.declaration = this.statement(); if (!(exportDec.declaration instanceof types_1.FunctionDeclaration) && !(exportDec.declaration instanceof types_1.VariableDeclaration) && !(exportDec.declaration instanceof types_1.ClassDeclaration)) { this.raise("JS_DEC_OR_STATEMENT_EXPECTED", this.text[this.i], (_a = exportDec.declaration) === null || _a === void 0 ? void 0 : _a.loc.start); } exportDec.source = null; exportDec.loc.end = (_b = exportDec.declaration) === null || _b === void 0 ? void 0 : _b.loc.end; } this.outerspace(); this.eat(";"); return exportDec; } }; base_1.ezra.exportSpecifier = function () { var expSpec = new types_1.ExportSpecifier(this.i); var mirror = this.importSpecifier(); expSpec.local = mirror.imported; expSpec.exported = mirror.local; expSpec.loc.end = mirror.loc.end; return expSpec; };