UNPKG

siphon-cli

Version:

Simple bundler for web applications. 📦🔧🧡

143 lines (142 loc) • 5.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var types_1 = require("../../../../types"); var utils_1 = require("../../../../utils"); var base_1 = require("./base"); base_1.ezra.numberLiteral = function () { var _a; var numlit = new types_1.Literal(this.i); numlit.kind = "number"; if (this.belly.pop() === ".") { numlit.raw += "." + this.count(); if ((0, utils_1.isAlphabetic)(this.text[this.i]) || /\./.test(this.text[this.i])) { this.raise("ID_FOLLOWS_LITERAL"); } numlit.value = parseFloat(numlit.raw); } else if (this.taste("0x")) { numlit.raw = "Ox" + this.count(16); if ((0, utils_1.isAlphabetic)(this.text[this.i])) this.raise("ID_FOLLOWS_LITERAL"); numlit.value = parseInt(numlit.raw.slice(2), 16); } else if (this.taste("0b")) { numlit.raw = "Ob" + this.count(2); if ((0, utils_1.isAlphaNumeric)(this.text[this.i])) this.raise("JS_UNEXPECTED_TOKEN", this.text[this.i]); numlit.value = parseInt(numlit.raw.slice(2), 2); } else if (this.eat("0o")) { numlit.raw = "Oo" + this.count(8); if ((0, utils_1.isAlphaNumeric)(this.text[this.i])) this.raise("JS_UNEXPECTED_TOKEN", this.text[this.i]); numlit.value = parseInt(numlit.raw.slice(2), 8); } else { numlit.raw += this.count(); if (this.text[this.i] === "n") { numlit.kind = "bigint"; numlit.bigint = numlit.raw; numlit.raw += "n"; this.i++; } else if (this.text[this.i] === ".") { this.i++; numlit.raw += "." + this.count(); } if (this.eat("e") || this.eat("E")) { numlit.raw += this.belly.pop(); if (this.taste("-")) numlit.raw += "-"; numlit.raw += this.count(); } if (this.text[this.i] === "n") this.raise("BIGINT_DECIMAL"); else if ((0, utils_1.isAlphabetic)(this.text[this.i])) this.raise("ID_FOLLOWS_LITERAL"); numlit.value = parseFloat((_a = numlit.raw) !== null && _a !== void 0 ? _a : ""); } numlit.loc.end = this.i; return numlit; }; base_1.ezra.stringLiteral = function () { var strlit = new types_1.Literal(this.i); var str = this.read(this.i); strlit.kind = "string"; strlit.raw = str.value; strlit.value = eval(str.value); this.i = str.end + 1; strlit.loc.end = this.i; return strlit; }; base_1.ezra.templateLiteral = function () { this.i++; var template = new types_1.TemplateLiteral(this.i); template.expressions = []; template.quasis = []; var raw = ""; var start = this.i, end = start; while (!(this.text[this.i] === undefined) && !/`/.test(this.text[this.i])) { if (this.text[this.i] === "\\") (raw += "\\".concat((this.i++, this.text[this.i]))), this.i++; else if (this.taste("${")) { end = this.i - 2; this.belly.push("{"); var expression = this.group("expression"); if (expression === undefined) this.raise("EXPRESSION_EXPECTED", undefined, this.i - 1); template.expressions.push(expression); if (raw !== "") { var element = new types_1.TemplateElement(start); element.value = { raw: raw, cooked: raw }; element.tail = false; element.loc.end = end; template.quasis.push(element); raw = ""; } start = this.i; } else { raw += this.text[this.i]; this.i++; } } if (this.text[this.i] === undefined) this.raise("UNTERMINATED_STRING_LITERAL"); if (raw !== "") { var element = new types_1.TemplateElement(start); element.value = { raw: raw, cooked: raw }; element.tail = true; element.loc.end = this.i; template.quasis.push(element); } template.loc.end = this.i; this.i++; return template; }; base_1.ezra.booleanLiteral = function () { var boollit = new types_1.Literal(this.i - this.belly.top().length); boollit.kind = "boolean"; boollit.raw = this.belly.top(); boollit.value = eval(this.belly.top()); boollit.loc.end = this.i; return boollit; }; base_1.ezra.regexLiteral = function () { var regexlit = new types_1.Literal(this.i - 1); regexlit.kind = "regex"; var reg = this.regex(this.i); regexlit.raw = eval("/" + reg.value + "/").toString(); regexlit.regex = { pattern: regexlit.raw.slice(1, -1), flags: reg.flags }; regexlit.value = new RegExp(regexlit.raw.slice(1, -1), reg.flags.length > 0 ? reg.flags : undefined); this.i = reg.end; regexlit.loc.end = this.i; return regexlit; }; base_1.ezra.nullLiteral = function () { var nulllit = new types_1.Literal(this.i - 4); nulllit.kind = nulllit.raw = "null"; nulllit.value = null; nulllit.loc.end = this.i; return nulllit; };