From f53fc95d47352ce54cd3a15627b0335949554bc7 Mon Sep 17 00:00:00 2001 From: Ben Gubler Date: Sat, 4 Jan 2020 15:31:25 -0700 Subject: [PATCH] Add try-catch, Escape, other stuff --- README.md | 12 +-- dist/browser/es/squirrelly.dev.js | 135 +++++++++++++++++++----- dist/browser/es/squirrelly.dev.js.map | 2 +- dist/browser/es/squirrelly.min.js | 2 +- dist/browser/es/squirrelly.min.js.map | 2 +- dist/browser/squirrelly.dev.js | 145 ++++++++++++++++++++------ dist/browser/squirrelly.dev.js.map | 2 +- dist/browser/squirrelly.min.js | 2 +- dist/browser/squirrelly.min.js.map | 2 +- dist/squirrelly.cjs.js | 145 ++++++++++++++++++++------ dist/squirrelly.cjs.js.map | 2 +- dist/squirrelly.es.js | 135 +++++++++++++++++++----- dist/squirrelly.es.js.map | 2 +- dist/types/browser.d.ts | 6 -- dist/types/compile-string.d.ts | 7 +- dist/types/compile.d.ts | 2 +- dist/types/config.d.ts | 19 +++- dist/types/index.d.ts | 4 +- dist/types/parse.d.ts | 3 +- dist/types/render.d.ts | 5 +- dist/types/utils.d.ts | 3 +- examples/conditionals.ts | 4 +- examples/trycatch.ts | 19 ++++ rollup.config.ts | 2 +- src/browser.ts | 18 ---- src/compile-string.ts | 33 +++--- src/compile.ts | 6 +- src/config.ts | 57 ++++++++-- src/containers.ts | 59 ++++++++++- src/index.ts | 10 +- src/parse.ts | 8 +- src/render.ts | 25 ++++- src/storage.ts | 1 + src/utils.ts | 31 +----- 34 files changed, 665 insertions(+), 245 deletions(-) delete mode 100644 dist/types/browser.d.ts create mode 100644 examples/trycatch.ts delete mode 100644 src/browser.ts diff --git a/README.md b/README.md index 2192101a..2119942c 100644 --- a/README.md +++ b/README.md @@ -27,19 +27,19 @@ Simply put, Squirrelly is super lightweight, super fast, super powerful, and sup ### 🌟 Features -- :wrench: Custom helpers -- :wrench: Custom filters +- 🔧 Custom helpers +- 🔧 Custom filters - :package: 0 dependencies - :hammer: Conditionals - :zap: Exports ES Modules as well as UMD - :hammer: Loops -- :wrench: Custom delimeters +- 🔧 Custom delimeters - :pencil2: Easy template syntax -- :wrench: Precompilation +- 🔧 Precompilation - :hammer: Partials -- :wrench: Inline JavaScript +- 🔧 Inline JavaScript - :hammer: Comments -- :wrench: Caching +- 🔧 Caching - :rocket: SUPER fast (look at the performance benchmarks [here](https://github.com/nebrelbug/squirrelly-benchmarks)) ## :scroll: Docs diff --git a/dist/browser/es/squirrelly.dev.js b/dist/browser/es/squirrelly.dev.js index c23ee3c6..4ac921fb 100644 --- a/dist/browser/es/squirrelly.dev.js +++ b/dist/browser/es/squirrelly.dev.js @@ -94,7 +94,7 @@ function trimRight(str, type) { } // Version 1.0.32 -function Parse(str, tagOpen, tagClose) { +function Parse(str, tagOpen, tagClose, env) { var powerchars = new RegExp('([|()]|=>)|' + '\'(?:\\\\[\\s\\w"\'\\\\`]|[^\\n\\r\'\\\\])*?\'|`(?:\\\\[\\s\\w"\'\\\\`]|[^\\\\`])*?`|"(?:\\\\[\\s\\w"\'\\\\`]|[^\\n\\r"\\\\])*?"' + // matches strings '|\\/\\*[^]*?\\*\\/|((\\/)?(-|_)?' + @@ -300,6 +300,7 @@ var Cacher = /** @class */ (function () { Cacher.prototype.get = function (key) { // string | array. // TODO: allow array of keys to look down + // TODO: create plugin to allow referencing helpers, filters with dot notation return this.cache[key]; }; Cacher.prototype.remove = function (key) { @@ -339,31 +340,67 @@ var Helpers = new Cacher({ } }); var NativeHelpers = new Cacher({ - if: function (buffer) { + if: function (buffer, env) { if (buffer.f && buffer.f.length) { throw SqrlErr("native helper 'if' can't have filters"); } - var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d) + '}'; + var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d, env) + '}'; if (buffer.b) { for (var i = 0; i < buffer.b.length; i++) { var currentBlock = buffer.b[i]; if (currentBlock.n === 'else') { - returnStr += 'else{' + ParseScope(currentBlock.d) + '}'; + returnStr += 'else{' + ParseScope(currentBlock.d, env) + '}'; } else if (currentBlock.n === 'elif') { - returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d) + '}'; + returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d, env) + '}'; } } } return returnStr; + }, + try: function (buffer, env) { + if (buffer.f && buffer.f.length) { + throw SqrlErr("native helper 'try' can't have filters"); + } + if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') { + throw SqrlErr("native helper 'try' only accepts 1 block, 'catch'"); + } + var returnStr = 'try{' + ParseScope(buffer.d, env) + '}'; + var currentBlock = buffer.b[0]; + returnStr += + 'catch' + + (currentBlock.res ? '(' + currentBlock.res + ')' : '') + + '{' + + ParseScope(currentBlock.d, env) + + '}'; + return returnStr; } }); -var Filters = new Cacher({}); +var escMap = { + '&': '&', + '<': '<', + '"': '"', + "'": ''' +}; +function replaceChar(s) { + return escMap[s]; +} +function XMLEscape(str) { + // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized. + var newStr = String(str); + if (/[&<"']/.test(newStr)) { + return newStr.replace(/[&<"']/g, replaceChar); + } + else { + return newStr; + } +} +var Filters = new Cacher({ e: XMLEscape }); -function CompileToString(str, tagOpen, tagClose) { +function CompileToString(str, tagOpen, tagClose, env) { var buffer = Parse(str, tagOpen, tagClose); return ("var tR='';" + - ParseScope(buffer) + ParseScope(buffer, env) .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') + 'return tR'); @@ -371,19 +408,19 @@ function CompileToString(str, tagOpen, tagClose) { // TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc. // TODO: Use type intersections for TemplateObject, etc. // so I don't have to make properties mandatory -function parseHelper(res, descendants, params, name) { - var ret = '{exec:' + ParseScopeIntoFunction(descendants, res) + ',params:[' + params + ']'; +function parseHelper(env, res, descendants, params, name) { + var ret = '{exec:' + ParseScopeIntoFunction(descendants, res, env) + ',params:[' + params + ']'; if (name) { ret += ",name:'" + name + "'"; } ret += '}'; return ret; } -function parseBlocks(blocks) { +function parseBlocks(blocks, env) { var ret = '['; for (var i = 0; i < blocks.length; i++) { var block = blocks[i]; - ret += parseHelper(block.res || '', block.d || [], block.p || '', block.n || ''); + ret += parseHelper(env, block.res || '', block.d || [], block.p || '', block.n || ''); if (i < blocks.length) { ret += ','; } @@ -391,10 +428,10 @@ function parseBlocks(blocks) { ret += ']'; return ret; } -function ParseScopeIntoFunction(buff, res) { - return 'function(' + res + "){var tR='';" + ParseScope(buff) + 'return tR}'; +function ParseScopeIntoFunction(buff, res, env) { + return 'function(' + res + "){var tR='';" + ParseScope(buff, env) + 'return tR}'; } -function ParseScope(buff) { +function ParseScope(buff, env) { var i = 0; var buffLength = buff.length; var returnStr = ''; @@ -423,12 +460,12 @@ function ParseScope(buff) { // helper // TODO: native helpers if (NativeHelpers.get(name)) { - returnStr += NativeHelpers.get(name)(currentBlock); + returnStr += NativeHelpers.get(name)(currentBlock, env); } else { - var helperReturn = "Sqrl.H.get('" + name + "')(" + parseHelper(res, currentBlock.d, params); + var helperReturn = "Sqrl.H.get('" + name + "')(" + parseHelper(env, res, currentBlock.d, params); if (blocks) { - helperReturn += ',' + parseBlocks(blocks); + helperReturn += ',' + parseBlocks(blocks, env); } helperReturn += ')'; helperReturn = filter(helperReturn, filters); @@ -460,18 +497,62 @@ function filter(str, filters) { return str; } -function Compile(str, tagOpen, tagClose) { - return new Function('it', 'Sqrl', CompileToString(str, tagOpen, tagClose)); // eslint-disable-line no-new-func +var defaultConfig = { + varName: 'it', + autoTrim: false, + autoEscape: true, + defaultFilter: false +}; +var Env = { + cache: { + default: defaultConfig + }, + define: function (key, newConfig) { + if (!this.cache[key]) { + this.cache[key] = defaultConfig; + } + for (var attrname in newConfig) { + this.cache[key][attrname] = newConfig[attrname]; + } + }, + get: function (key) { + // string | array. + // TODO: allow array of keys to look down + return this.cache[key]; + }, + remove: function (key) { + delete this.cache[key]; + }, + clear: function () { + this.cache = {}; + }, + load: function (cacheObj) { + this.cache = cacheObj; + } +}; +// Have different envs. Sqrl.Render, Compile, etc. all use default env +// Use class for env + +function Compile(str, tagOpen, tagClose, envName) { + var SqrlEnv = Env.get(envName || 'default'); + return new Function(SqrlEnv.varName, 'Sqrl', CompileToString(str, tagOpen, tagClose, SqrlEnv)); // eslint-disable-line no-new-func } // console.log(Compile('hi {{this}} hey', '{{', '}}').toString()) -function Render(template, options) { - var templateFunc = Compile(template, '{{', '}}'); - return templateFunc(options, { H: Helpers, F: Filters }); -} - -function Config(key, val) { +function Render(template, data, env, options) { + if (!env) { + env = 'default'; + } + else if (typeof env === 'function') { + env = env(options); // this can be used to dynamically pick an env based on name, etc. + } + if (typeof template === 'function') { + return template(data, { H: Helpers, F: Filters }); + } + // else + var templateFunc = Compile(template, '{{', '}}', env); + return templateFunc(data, { H: Helpers, F: Filters }); } -export { Compile, CompileToString, Config, Filters as F, Helpers as H, Layouts as L, NativeHelpers as NH, Partials as P, Parse, ParseScope, ParseScopeIntoFunction, Render }; +export { Compile, CompileToString, Env, Filters, Helpers, Layouts, NativeHelpers, Parse, ParseScope, ParseScopeIntoFunction, Partials, Render }; //# sourceMappingURL=squirrelly.dev.js.map diff --git a/dist/browser/es/squirrelly.dev.js.map b/dist/browser/es/squirrelly.dev.js.map index 8c851461..b7e598ea 100644 --- a/dist/browser/es/squirrelly.dev.js.map +++ b/dist/browser/es/squirrelly.dev.js.map @@ -1 +1 @@ -{"version":3,"file":"squirrelly.dev.js","sources":["../../../src/err.ts","../../../src/utils.ts","../../../src/parse.ts","../../../src/storage.ts","../../../src/containers.ts","../../../src/compile-string.ts","../../../src/compile.ts","../../../src/render.ts","../../../src/config.ts"],"sourcesContent":["// v 1.0.32\n\nfunction setPrototypeOf (obj: any, proto: any) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(obj, proto)\n } else {\n obj.__proto__ = proto\n }\n}\n\nexport default function SqrlErr (message: string) {\n var err = new Error(message)\n setPrototypeOf(err, SqrlErr.prototype)\n return err\n}\n\nSqrlErr.prototype = Object.create(Error.prototype, {\n name: { value: 'Squirrelly Error', enumerable: false }\n})\n\n// TODO: Class transpilation adds a lot to the bundle size\n\nexport function ParseErr (message: string, str: string, indx: number) {\n var whitespace = str\n .slice(0, indx) // +2 because of {{\n .split(/\\n/)\n\n // console.log('whitespace: \\n' + JSON.stringify(whitespace))\n var lineNo = whitespace.length\n var colNo = whitespace[lineNo - 1].length + 1\n message +=\n ' at line ' +\n lineNo +\n ' col ' +\n colNo +\n ':\\n\\n' +\n ' ' +\n str.split(/\\n/)[lineNo - 1] +\n '\\n' +\n ' ' +\n Array(colNo).join(' ') +\n '^'\n throw SqrlErr(message)\n}\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nexport { trimLeft, trimRight, XMLEscape }\n","// Version 1.0.32\nimport { ParseErr } from './err'\nimport { trimLeft, trimRight } from './utils'\n\nexport type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's'\nexport type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err'\nexport type TemplateObjectAttribute = 'c' | 'p' | 'n' | 'res'\n\nexport type AstObject = string | TemplateObject\n\nexport type Filter = [string, string | undefined]\n\nexport interface TemplateObject {\n n?: string\n t?: string\n f: Array\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (str: string, tagOpen: string, tagClose: string): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d) + '}'\n }\n }\n }\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\nvar Filters = new Cacher({})\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string) {\n var buffer: Array = Parse(str, tagOpen, tagClose)\n return (\n \"var tR='';\" +\n ParseScope(buffer)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (res: string, descendants: Array, params: string, name?: string) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","import CompileToString from './compile-string'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string) {\n return new Function('it', 'Sqrl', CompileToString(str, tagOpen, tagClose)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\nfunction Render (template: string, options: object): string {\n var templateFunc = Compile(template, '{{', '}}')\n return templateFunc(options, { H: Helpers, F: Filters })\n}\n\nexport default Render\nexport type TemplateFunction = (options: object, Sqrl: object) => string\n","interface SqrlConfiguration {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n [index: string]: any\n}\n\nvar Conf: SqrlConfiguration = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true\n}\n\nfunction Config (key: string, val: any): void {\n Conf[key] = val\n}\n\n// TODO: Fix types for this\n\nexport { Conf, Config }\n"],"names":[],"mappings":"AAAA;AAEA,SAAS,cAAc,CAAE,GAAQ,EAAE,KAAU;IAC3C,IAAI,MAAM,CAAC,cAAc,EAAE;QACzB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;KAClC;SAAM;QACL,GAAG,CAAC,SAAS,GAAG,KAAK,CAAA;KACtB;CACF;AAED,SAAwB,OAAO,CAAE,OAAe;IAC9C,IAAI,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5B,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IACtC,OAAO,GAAG,CAAA;CACX;AAED,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE;IACjD,IAAI,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,KAAK,EAAE;CACvD,CAAC,CAAA;;AAIF,SAAgB,QAAQ,CAAE,OAAe,EAAE,GAAW,EAAE,IAAY;IAClE,IAAI,UAAU,GAAG,GAAG;SACjB,KAAK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e,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAA;CAC3E;AAED,AACA,iEAAiE;;ACJjE,SAAS,MAAM,CAAE,QAAgB,EAAE,OAAe;IAChD,IAAI,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IAChD,OAAO,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;CACzD;;ACOD,SAAS,MAAM,CAAE,GAAW,EAAE,GAAQ;AAEtC,CAAC;;;;"} \ No newline at end of file +{"version":3,"file":"squirrelly.dev.js","sources":["../../../src/err.ts","../../../src/utils.ts","../../../src/parse.ts","../../../src/storage.ts","../../../src/containers.ts","../../../src/compile-string.ts","../../../src/config.ts","../../../src/compile.ts","../../../src/render.ts"],"sourcesContent":["// v 1.0.32\n\nfunction setPrototypeOf (obj: any, proto: any) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(obj, proto)\n } else {\n obj.__proto__ = proto\n }\n}\n\nexport default function SqrlErr (message: string) {\n var err = new Error(message)\n setPrototypeOf(err, SqrlErr.prototype)\n return err\n}\n\nSqrlErr.prototype = Object.create(Error.prototype, {\n name: { value: 'Squirrelly Error', enumerable: false }\n})\n\n// TODO: Class transpilation adds a lot to the bundle size\n\nexport function ParseErr (message: string, str: string, indx: number) {\n var whitespace = str\n .slice(0, indx) // +2 because of {{\n .split(/\\n/)\n\n // console.log('whitespace: \\n' + JSON.stringify(whitespace))\n var lineNo = whitespace.length\n var colNo = whitespace[lineNo - 1].length + 1\n message +=\n ' at line ' +\n lineNo +\n ' col ' +\n colNo +\n ':\\n\\n' +\n ' ' +\n str.split(/\\n/)[lineNo - 1] +\n '\\n' +\n ' ' +\n Array(colNo).join(' ') +\n '^'\n throw SqrlErr(message)\n}\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\nexport { trimLeft, trimRight }\n","// Version 1.0.32\nimport { ParseErr } from './err'\nimport { trimLeft, trimRight } from './utils'\nimport { SqrlConfig } from './config'\n\nexport type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's'\nexport type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err'\nexport type TemplateObjectAttribute = 'c' | 'p' | 'n' | 'res'\n\nexport type AstObject = string | TemplateObject\n\nexport type Filter = [string, string | undefined]\n\nexport interface TemplateObject {\n n?: string\n t?: string\n f: Array\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (\n str: string,\n tagOpen: string,\n tagClose: string,\n env: SqrlConfig\n): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n // TODO: create plugin to allow referencing helpers, filters with dot notation\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\nimport { SqrlConfig } from './config'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d, env) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d, env) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d, env) + '}'\n }\n }\n }\n return returnStr\n },\n try: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'try' can't have filters\")\n }\n if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') {\n throw SqrlErr(\"native helper 'try' only accepts 1 block, 'catch'\")\n }\n var returnStr = 'try{' + ParseScope(buffer.d, env) + '}'\n\n var currentBlock = buffer.b[0]\n returnStr +=\n 'catch' +\n (currentBlock.res ? '(' + currentBlock.res + ')' : '') +\n '{' +\n ParseScope(currentBlock.d, env) +\n '}'\n\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nvar Filters = new Cacher({ e: XMLEscape })\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\nimport { SqrlConfig } from './config'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string, env: SqrlConfig) {\n var buffer: Array = Parse(str, tagOpen, tagClose, env)\n return (\n \"var tR='';\" +\n ParseScope(buffer, env)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (\n env: SqrlConfig,\n res: string,\n descendants: Array,\n params: string,\n name?: string\n) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res, env) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array, env: SqrlConfig) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(env, block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string, env: SqrlConfig) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff, env) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array, env: SqrlConfig) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock, env)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(env, res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks, env)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","interface Dict {\n [key: string]: SqrlConfig\n}\n\ninterface IEnv {\n cache: Dict\n define: (key: string, val: SqrlConfig) => void\n get: (key: string) => SqrlConfig\n remove: (key: string) => void\n clear: () => void\n load: (cacheObj: Dict) => void\n}\n\nexport interface SqrlConfig {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n defaultFilter: false | Function\n [index: string]: any\n}\n\ntype PartialConfig = {\n [P in keyof SqrlConfig]?: SqrlConfig[P]\n}\n\nvar defaultConfig: SqrlConfig = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true,\n defaultFilter: false\n}\n\nvar Env: IEnv = {\n cache: {\n default: defaultConfig\n },\n define: function (key: string, newConfig: PartialConfig) {\n if (!this.cache[key]) {\n this.cache[key] = defaultConfig\n }\n for (var attrname in newConfig) {\n this.cache[key][attrname] = newConfig[attrname]\n }\n },\n get: function (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n },\n remove: function (key: string) {\n delete this.cache[key]\n },\n clear: function () {\n this.cache = {}\n },\n load: function (cacheObj: Dict) {\n this.cache = cacheObj\n }\n}\n\nexport { Env }\n\n// Have different envs. Sqrl.Render, Compile, etc. all use default env\n// Use class for env\n","import CompileToString from './compile-string'\nimport { Env } from './config'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string, envName: string) {\n var SqrlEnv = Env.get(envName || 'default')\n return new Function(SqrlEnv.varName, 'Sqrl', CompileToString(str, tagOpen, tagClose, SqrlEnv)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\ntype TemplateFunction = (data: object, Sqrl: object) => string\ntype DetermineEnvFunction = (options?: object) => string\n\nfunction Render (\n template: string | TemplateFunction,\n data: object,\n env?: string | DetermineEnvFunction,\n options?: object\n) {\n if (!env) {\n env = 'default'\n } else if (typeof env === 'function') {\n env = env(options) // this can be used to dynamically pick an env based on name, etc.\n }\n\n if (typeof template === 'function') {\n return template(data, { H: Helpers, F: Filters })\n }\n // else\n var templateFunc = Compile(template, '{{', '}}', env)\n return templateFunc(data, { H: Helpers, F: Filters })\n}\n\nexport default Render\n"],"names":[],"mappings":"AAAA;AAEA,SAAS,cAAc,CAAE,GAAQ,EAAE,KAAU;IAC3C,IAAI,MAAM,CAAC,cAAc,EAAE;QACzB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;KAClC;SAAM;QACL,GAAG,CAAC,SAAS,GAAG,KAAK,CAAA;KACtB;CACF;AAED,SAAwB,OAAO,CAAE,OAAe;IAC9C,IAAI,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5B,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IACtC,OAAO,GAAG,CAAA;CACX;AAED,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE;IACjD,IAAI,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,KAAK,EAAE;CACvD,CAAC,CAAA;;AAIF,SAAgB,QAAQ,CAAE,OAAe,EAAE,GAAW,EAAE,IAAY;IAClE,IAAI,UAAU,GAAG,GAAG;SACjB,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;SACd,KAAK,CAAC,IAAI,CAAC,CAAA;;IAGd,IAAI,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;IAC9B,IAAI,KAAK,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;IAC7C,OAAO;QACL,WAAW;YACX,MAAM;YACN,OAAO;YACP,KAAK;YACL,OAAO;YACP,IAAI;YACJ,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,CAAC,CAAA;KACnB;IAED,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;QAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;KAClD;;IAED,IAAI,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;IACrD,OAAO,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;CACtD;;;;"} \ No newline at end of file diff --git a/dist/browser/es/squirrelly.min.js b/dist/browser/es/squirrelly.min.js index fda4c242..73152653 100644 --- a/dist/browser/es/squirrelly.min.js +++ b/dist/browser/es/squirrelly.min.js @@ -1,2 +1,2 @@ -function e(r){var t,n,i=new Error(r);return t=i,n=e.prototype,Object.setPrototypeOf?Object.setPrototypeOf(t,n):t.__proto__=n,i}function r(r,t,n){var i=t.slice(0,n).split(/\n/),f=i.length,o=i[f-1].length+1;throw e(r+=" at line "+f+" col "+o+":\n\n "+t.split(/\n/)[f-1]+"\n "+Array(o).join(" ")+"^")}function t(e,t,n){var i=new RegExp("([|()]|=>)|'(?:\\\\[\\s\\w\"'\\\\`]|[^\\n\\r'\\\\])*?'|`(?:\\\\[\\s\\w\"'\\\\`]|[^\\\\`])*?`|\"(?:\\\\[\\s\\w\"'\\\\`]|[^\\n\\r\"\\\\])*?\"|\\/\\*[^]*?\\*\\/|((\\/)?(-|_)?"+n+")","g"),f=new RegExp("([^]*?)"+t+"(-|_)?\\s*","g"),o=0,a="";function c(){var t,n={f:[],d:[]},c=0,u=0,l=e[o],s="c",p="r";function h(t,i){var f=e.slice(o,t)+(i||""),a=f.trim();if("f"===s)n.f[u-1][0]+=a;else if("fp"===s)n.f[u-1][1]+=a;else if("err"===s){if(a){var c=f.search(/\S/);r("invalid syntax",e,o+c)}}else s&&(n[s]=a);o=t+1}for(o+=1,"~"===l||"#"===l||"/"===l?(s="n",p=l):"!"===l||"?"===l?p=l:o-=1;null!==(t=i.exec(e));){var g=t[1],v=t[2],d=t[3],x=t[4],y=t.index;if(g)"("===g?(0===c&&("n"===s?(h(y),s="p"):"f"===s&&(h(y),s="fp")),c++):")"===g?0===--c&&"c"!==s&&(h(y),s="err"):0===c&&"|"===g?(h(y),s="f",u++,n.f[u-1]=["",""]):"=>"===g&&(h(y),o+=1,s="res");else if(v)return h(y),o+=v.length-1,f.lastIndex=o,a=x,d&&"~"===p&&(p="s"),n.t=p,n}return r("unclosed tag",e,e.length),n}return function t(n,i){n.b=[];var u,l=!1,s=[];function p(e,r){if(e){var t=e.replace(/\\/g,"\\\\").replace(/'/g,"\\'");r&&(t=function(e,r){return"_"===r?String.prototype.trimRight?e.trimRight():e.replace(/[\s\uFEFF\xA0]+$/,""):e.replace(/(?:[\s\uFEFF\xA0]|\r\n)$/,"")}(t,r)),a&&(t=function(e,r){return"_"===r?String.prototype.trimLeft?e.trimLeft():e.replace(/^[\s\uFEFF\xA0]+/,""):e.replace(/^(?:[\s\uFEFF\xA0]|\r\n)/,"")}(t,a),a=""),s.push(t)}}for(;null!==(u=f.exec(e));){p(u[1],u[2]),o=u.index+u[0].length;var h=c(),g=h.t;if("~"===g)h=t(h),s.push(h);else if("/"===g){if(n.n===h.n)return l?(l.d=s,n.b.push(l)):n.d=s,n;r("Helper start and end don't match",e,u.index+u[0].length)}else"#"===g?(l?(l.d=s,n.b.push(l)):n.d=s,l=h,s=[]):s.push(h)}return i&&(p(e.slice(o,e.length)),n.d=s),n}({f:[],d:[]},!0).d}e.prototype=Object.create(Error.prototype,{name:{value:"Squirrelly Error",enumerable:!1}});var n=function(){function e(e){this.cache=e}return e.prototype.define=function(e,r){this.cache[e]=r},e.prototype.get=function(e){return this.cache[e]},e.prototype.remove=function(e){delete this.cache[e]},e.prototype.clear=function(){this.cache={}},e.prototype.load=function(e){this.cache=e},e}(),i=new n({}),f=new n({}),o=new n({each:function(e){for(var r="",t=e.params[0],n=0;n)|'(?:\\\\[\\s\\w\"'\\\\`]|[^\\n\\r'\\\\])*?'|`(?:\\\\[\\s\\w\"'\\\\`]|[^\\\\`])*?`|\"(?:\\\\[\\s\\w\"'\\\\`]|[^\\n\\r\"\\\\])*?\"|\\/\\*[^]*?\\*\\/|((\\/)?(-|_)?"+n+")","g"),a=new RegExp("([^]*?)"+r+"(-|_)?\\s*","g"),f=0,o="";function u(){var r,n={f:[],d:[]},c=0,u=0,l=e[f],s="c",h="r";function p(r,c){var i=e.slice(f,r)+(c||""),a=i.trim();if("f"===s)n.f[u-1][0]+=a;else if("fp"===s)n.f[u-1][1]+=a;else if("err"===s){if(a){var o=i.search(/\S/);t("invalid syntax",e,f+o)}}else s&&(n[s]=a);f=r+1}for(f+=1,"~"===l||"#"===l||"/"===l?(s="n",h=l):"!"===l||"?"===l?h=l:f-=1;null!==(r=i.exec(e));){var v=r[1],g=r[2],d=r[3],y=r[4],m=r.index;if(v)"("===v?(0===c&&("n"===s?(p(m),s="p"):"f"===s&&(p(m),s="fp")),c++):")"===v?0===--c&&"c"!==s&&(p(m),s="err"):0===c&&"|"===v?(p(m),s="f",u++,n.f[u-1]=["",""]):"=>"===v&&(p(m),f+=1,s="res");else if(g)return p(m),f+=g.length-1,a.lastIndex=f,o=y,d&&"~"===h&&(h="s"),n.t=h,n}return t("unclosed tag",e,e.length),n}return function r(n,c){n.b=[];var i,l=!1,s=[];function h(e,t){if(e){var r=e.replace(/\\/g,"\\\\").replace(/'/g,"\\'");t&&(r=function(e,t){return"_"===t?String.prototype.trimRight?e.trimRight():e.replace(/[\s\uFEFF\xA0]+$/,""):e.replace(/(?:[\s\uFEFF\xA0]|\r\n)$/,"")}(r,t)),o&&(r=function(e,t){return"_"===t?String.prototype.trimLeft?e.trimLeft():e.replace(/^[\s\uFEFF\xA0]+/,""):e.replace(/^(?:[\s\uFEFF\xA0]|\r\n)/,"")}(r,o),o=""),s.push(r)}}for(;null!==(i=a.exec(e));){h(i[1],i[2]),f=i.index+i[0].length;var p=u(),v=p.t;if("~"===v)p=r(p),s.push(p);else if("/"===v){if(n.n===p.n)return l?(l.d=s,n.b.push(l)):n.d=s,n;t("Helper start and end don't match",e,i.index+i[0].length)}else"#"===v?(l?(l.d=s,n.b.push(l)):n.d=s,l=p,s=[]):s.push(p)}return c&&(h(e.slice(f,e.length)),n.d=s),n}({f:[],d:[]},!0).d}e.prototype=Object.create(Error.prototype,{name:{value:"Squirrelly Error",enumerable:!1}});var n=function(){function e(e){this.cache=e}return e.prototype.define=function(e,t){this.cache[e]=t},e.prototype.get=function(e){return this.cache[e]},e.prototype.remove=function(e){delete this.cache[e]},e.prototype.clear=function(){this.cache={}},e.prototype.load=function(e){this.cache=e},e}(),c=new n({}),i=new n({}),a=new n({each:function(e){for(var t="",r=e.params[0],n=0;n\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (str: string, tagOpen: string, tagClose: string): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nexport { trimLeft, trimRight, XMLEscape }\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d) + '}'\n }\n }\n }\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\nvar Filters = new Cacher({})\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string) {\n var buffer: Array = Parse(str, tagOpen, tagClose)\n return (\n \"var tR='';\" +\n ParseScope(buffer)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (res: string, descendants: Array, params: string, name?: string) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","import CompileToString from './compile-string'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string) {\n return new Function('it', 'Sqrl', CompileToString(str, tagOpen, tagClose)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\nfunction Render (template: string, options: object): string {\n var templateFunc = Compile(template, '{{', '}}')\n return templateFunc(options, { H: Helpers, F: Filters })\n}\n\nexport default Render\nexport type TemplateFunction = (options: object, Sqrl: object) => string\n","interface SqrlConfiguration {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n [index: string]: any\n}\n\nvar Conf: SqrlConfiguration = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true\n}\n\nfunction Config (key: string, val: any): void {\n Conf[key] = val\n}\n\n// TODO: Fix types for this\n\nexport { Conf, Config }\n"],"names":["SqrlErr","message","obj","proto","err","Error","prototype","Object","setPrototypeOf","__proto__","ParseErr","str","indx","whitespace","slice","split","lineNo","length","colNo","Array","join","Parse","tagOpen","tagClose","powerchars","RegExp","tagOpenReg","startInd","trimNextLeftWs","parseTag","m","currentObj","f","d","numParens","filterNumber","firstChar","currentAttribute","currentType","addAttrValue","strng","valUnprocessed","val","trim","found","search","exec","char","slash","wsControl","i","index","lastIndex","t","parseContext","parentObj","firstParse","b","tagOpenMatch","lastBlock","buffer","pushString","wsAhead","stringToPush","replace","type","String","trimRight","trimLeft","push","n","create","name","value","enumerable","cache","this","Cacher","key","cacheObj","Layouts","Partials","Helpers","each","content","res","param","params","foreach","hasOwnProperty","NativeHelpers","if","returnStr","p","ParseScope","currentBlock","Filters","CompileToString","parseHelper","descendants","ret","ParseScopeIntoFunction","parseBlocks","blocks","block","buff","buffLength","c","filters","filter","get","helperReturn","Compile","Function","Render","template","options","templateFunc","H","F","Config"],"mappings":"SAUwBA,EAASC,GAC/B,IATuBC,EAAUC,EAS7BC,EAAM,IAAIC,MAAMJ,GAEpB,OAXuBC,EAURE,EAVkBD,EAUbH,EAAQM,UATxBC,OAAOC,eACTD,OAAOC,eAAeN,EAAKC,GAE3BD,EAAIO,UAAYN,EAOXC,EAST,SAAgBM,EAAUT,EAAiBU,EAAaC,GACtD,IA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AI,EAAGA,EAAI0D,EAAQ3F,OAAQiC,IAAK,CACvC,IAAIsB,EAAOoC,EAAQ1D,GAAG,GAClBqC,EAASqB,EAAQ1D,GAAG,GACxBvC,EAAM,eAAiB6D,EAAO,MAAQ7D,EAClC4E,IACF5E,GAAO,IAAM4E,GAEf5E,GAAO,IAET,OAAOA,EC5GT,SAASqG,EAASrG,EAAaW,EAAiBC,GAC9C,OAAO,IAAI0F,SAAS,KAAM,OAAQhB,EAAgBtF,EAAKW,EAASC,ICAlE,SAAS2F,EAAQC,EAAkBC,GAEjC,OADmBJ,EAAQG,EAAU,KAAM,KACpCE,CAAaD,EAAS,CAAEE,EAAGpC,EAASqC,EAAGvB,ICQhD,SAASwB,EAAQ1C,EAAapC"} \ No newline at end of file +{"version":3,"file":"squirrelly.min.js","sources":["../../../src/err.ts","../../../src/parse.ts","../../../src/utils.ts","../../../src/storage.ts","../../../src/containers.ts","../../../src/compile-string.ts","../../../src/config.ts","../../../src/compile.ts","../../../src/render.ts"],"sourcesContent":["// v 1.0.32\n\nfunction setPrototypeOf (obj: any, proto: any) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(obj, proto)\n } else {\n obj.__proto__ = proto\n }\n}\n\nexport default function SqrlErr (message: string) {\n var err = new Error(message)\n setPrototypeOf(err, SqrlErr.prototype)\n return err\n}\n\nSqrlErr.prototype = Object.create(Error.prototype, {\n name: { value: 'Squirrelly Error', enumerable: false }\n})\n\n// TODO: Class transpilation adds a lot to the bundle size\n\nexport function ParseErr (message: string, str: string, indx: number) {\n var whitespace = str\n .slice(0, indx) // +2 because of {{\n .split(/\\n/)\n\n // console.log('whitespace: \\n' + JSON.stringify(whitespace))\n var lineNo = whitespace.length\n var colNo = whitespace[lineNo - 1].length + 1\n message +=\n ' at line ' +\n lineNo +\n ' col ' +\n colNo +\n ':\\n\\n' +\n ' ' +\n str.split(/\\n/)[lineNo - 1] +\n '\\n' +\n ' ' +\n Array(colNo).join(' ') +\n '^'\n throw SqrlErr(message)\n}\n","// Version 1.0.32\nimport { ParseErr } from './err'\nimport { trimLeft, trimRight } from './utils'\nimport { SqrlConfig } from './config'\n\nexport type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's'\nexport type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err'\nexport type TemplateObjectAttribute = 'c' | 'p' | 'n' | 'res'\n\nexport type AstObject = string | TemplateObject\n\nexport type Filter = [string, string | undefined]\n\nexport interface TemplateObject {\n n?: string\n t?: string\n f: Array\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (\n str: string,\n tagOpen: string,\n tagClose: string,\n env: SqrlConfig\n): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\nexport { trimLeft, trimRight }\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n // TODO: create plugin to allow referencing helpers, filters with dot notation\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\nimport { SqrlConfig } from './config'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d, env) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d, env) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d, env) + '}'\n }\n }\n }\n return returnStr\n },\n try: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'try' can't have filters\")\n }\n if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') {\n throw SqrlErr(\"native helper 'try' only accepts 1 block, 'catch'\")\n }\n var returnStr = 'try{' + ParseScope(buffer.d, env) + '}'\n\n var currentBlock = buffer.b[0]\n returnStr +=\n 'catch' +\n (currentBlock.res ? '(' + currentBlock.res + ')' : '') +\n '{' +\n ParseScope(currentBlock.d, env) +\n '}'\n\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nvar Filters = new Cacher({ e: XMLEscape })\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\nimport { SqrlConfig } from './config'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string, env: SqrlConfig) {\n var buffer: Array = Parse(str, tagOpen, tagClose, env)\n return (\n \"var tR='';\" +\n ParseScope(buffer, env)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (\n env: SqrlConfig,\n res: string,\n descendants: Array,\n params: string,\n name?: string\n) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res, env) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array, env: SqrlConfig) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(env, block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string, env: SqrlConfig) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff, env) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array, env: SqrlConfig) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock, env)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(env, res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks, env)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","interface Dict {\n [key: string]: SqrlConfig\n}\n\ninterface IEnv {\n cache: Dict\n define: (key: string, val: SqrlConfig) => void\n get: (key: string) => SqrlConfig\n remove: (key: string) => void\n clear: () => void\n load: (cacheObj: Dict) => void\n}\n\nexport interface SqrlConfig {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n defaultFilter: false | Function\n [index: string]: any\n}\n\ntype PartialConfig = {\n [P in keyof SqrlConfig]?: SqrlConfig[P]\n}\n\nvar defaultConfig: SqrlConfig = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true,\n defaultFilter: false\n}\n\nvar Env: IEnv = {\n cache: {\n default: defaultConfig\n },\n define: function (key: string, newConfig: PartialConfig) {\n if (!this.cache[key]) {\n this.cache[key] = defaultConfig\n }\n for (var attrname in newConfig) {\n this.cache[key][attrname] = newConfig[attrname]\n }\n },\n get: function (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n },\n remove: function (key: string) {\n delete this.cache[key]\n },\n clear: function () {\n this.cache = {}\n },\n load: function (cacheObj: Dict) {\n this.cache = cacheObj\n }\n}\n\nexport { Env }\n\n// Have different envs. Sqrl.Render, Compile, etc. all use default env\n// Use class for env\n","import CompileToString from './compile-string'\nimport { Env } from './config'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string, envName: string) {\n var SqrlEnv = Env.get(envName || 'default')\n return new Function(SqrlEnv.varName, 'Sqrl', CompileToString(str, tagOpen, tagClose, SqrlEnv)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\ntype TemplateFunction = (data: object, Sqrl: object) => string\ntype DetermineEnvFunction = (options?: object) => string\n\nfunction Render (\n template: string | TemplateFunction,\n data: object,\n env?: string | DetermineEnvFunction,\n options?: object\n) {\n if (!env) {\n env = 'default'\n } else if (typeof env === 'function') {\n env = env(options) // this can be used to dynamically pick an env based on name, etc.\n }\n\n if (typeof template === 'function') {\n return template(data, { H: Helpers, F: Filters })\n }\n // else\n var templateFunc = Compile(template, '{{', '}}', env)\n return templateFunc(data, { H: Helpers, F: Filters })\n}\n\nexport default Render\n"],"names":["SqrlErr","message","obj","proto","err","Error","prototype","Object","setPrototypeOf","__proto__","ParseErr","str","indx","whitespace","slice","split","lineNo","length","colNo","Array","join","Parse","tagOpen","tagClose","env","powerchars","RegExp","tagOpenReg","startInd","trimNextLeftWs","parseTag","m","currentObj","f","d","numParens","filterNumber","firstChar","currentAttribute","currentType","addAttrValue","strng","valUnprocessed","val","trim","found","search","exec","char","slash","wsControl","i","index","lastIndex","t","parseContext","parentObj","firstParse","b","tagOpenMatch","lastBlock","buffer","pushString","wsAhead","stringToPush","replace","type","String","trimRight","trimLeft","push","n","create","name","value","enumerable","cache","this","Cacher","key","cacheObj","Layouts","Partials","Helpers","each","content","res","param","params","foreach","hasOwnProperty","NativeHelpers","if","returnStr","p","ParseScope","currentBlock","try","escMap","&","<","\"","'","replaceChar","s","Filters","e","newStr","test","CompileToString","parseHelper","descendants","ret","ParseScopeIntoFunction","parseBlocks","blocks","block","buff","buffLength","c","filters","filter","get","helperReturn","defaultConfig","varName","autoTrim","autoEscape","defaultFilter","Env","default","define","newConfig","attrname","remove","clear","load","Compile","envName","SqrlEnv","Function","Render","template","data","options","H","F","templateFunc"],"mappings":"SAUwBA,EAASC,GAC/B,IATuBC,EAAUC,EAS7BC,EAAM,IAAIC,MAAMJ,GAEpB,OAXuBC,EAURE,EAVkBD,EAUbH,EAAQM,UATxBC,OAAOC,eACTD,OAAOC,eAAeN,EAAKC,GAE3BD,EAAIO,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,IAAIC,KAHJxD,KAAKD,MAAMG,KACdF,KAAKD,MAAMG,GAAO6C,GAECQ,EACnBvD,KAAKD,MAAMG,GAAKsD,GAAYD,EAAUC,IAG1CX,IAAK,SAAU3C,GAGb,OAAOF,KAAKD,MAAMG,IAEpBuD,OAAQ,SAAUvD,UACTF,KAAKD,MAAMG,IAEpBwD,MAAO,WACL1D,KAAKD,MAAQ,IAEf4D,KAAM,SAAUxD,GACdH,KAAKD,MAAQI,ICrDjB,SAASyD,EAAS9H,EAAaW,EAAiBC,EAAkBmH,GAChE,IAAIC,EAAUV,EAAIP,IAAIgB,GAAW,WACjC,OAAO,IAAIE,SAASD,EAAQd,QAAS,OAAQhB,EAAgBlG,EAAKW,EAASC,EAAUoH,ICCvF,SAASE,EACPC,EACAC,EACAvH,EACAwH,GAQA,OANKxH,EAEqB,mBAARA,IAChBA,EAAMA,EAAIwH,IAFVxH,EAAM,UAKgB,mBAAbsH,EACFA,EAASC,EAAM,CAAEE,EAAG9D,EAAS+D,EAAGzC,IAGtBgC,EAAQK,EAAU,KAAM,KAAMtH,EAC1C2H,CAAaJ,EAAM,CAAEE,EAAG9D,EAAS+D,EAAGzC"} \ No newline at end of file diff --git a/dist/browser/squirrelly.dev.js b/dist/browser/squirrelly.dev.js index d15f9ca7..d3fa13ec 100644 --- a/dist/browser/squirrelly.dev.js +++ b/dist/browser/squirrelly.dev.js @@ -100,7 +100,7 @@ } // Version 1.0.32 - function Parse(str, tagOpen, tagClose) { + function Parse(str, tagOpen, tagClose, env) { var powerchars = new RegExp('([|()]|=>)|' + '\'(?:\\\\[\\s\\w"\'\\\\`]|[^\\n\\r\'\\\\])*?\'|`(?:\\\\[\\s\\w"\'\\\\`]|[^\\\\`])*?`|"(?:\\\\[\\s\\w"\'\\\\`]|[^\\n\\r"\\\\])*?"' + // matches strings '|\\/\\*[^]*?\\*\\/|((\\/)?(-|_)?' + @@ -306,6 +306,7 @@ Cacher.prototype.get = function (key) { // string | array. // TODO: allow array of keys to look down + // TODO: create plugin to allow referencing helpers, filters with dot notation return this.cache[key]; }; Cacher.prototype.remove = function (key) { @@ -345,31 +346,67 @@ } }); var NativeHelpers = new Cacher({ - if: function (buffer) { + if: function (buffer, env) { if (buffer.f && buffer.f.length) { throw SqrlErr("native helper 'if' can't have filters"); } - var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d) + '}'; + var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d, env) + '}'; if (buffer.b) { for (var i = 0; i < buffer.b.length; i++) { var currentBlock = buffer.b[i]; if (currentBlock.n === 'else') { - returnStr += 'else{' + ParseScope(currentBlock.d) + '}'; + returnStr += 'else{' + ParseScope(currentBlock.d, env) + '}'; } else if (currentBlock.n === 'elif') { - returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d) + '}'; + returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d, env) + '}'; } } } return returnStr; + }, + try: function (buffer, env) { + if (buffer.f && buffer.f.length) { + throw SqrlErr("native helper 'try' can't have filters"); + } + if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') { + throw SqrlErr("native helper 'try' only accepts 1 block, 'catch'"); + } + var returnStr = 'try{' + ParseScope(buffer.d, env) + '}'; + var currentBlock = buffer.b[0]; + returnStr += + 'catch' + + (currentBlock.res ? '(' + currentBlock.res + ')' : '') + + '{' + + ParseScope(currentBlock.d, env) + + '}'; + return returnStr; } }); - var Filters = new Cacher({}); + var escMap = { + '&': '&', + '<': '<', + '"': '"', + "'": ''' + }; + function replaceChar(s) { + return escMap[s]; + } + function XMLEscape(str) { + // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized. + var newStr = String(str); + if (/[&<"']/.test(newStr)) { + return newStr.replace(/[&<"']/g, replaceChar); + } + else { + return newStr; + } + } + var Filters = new Cacher({ e: XMLEscape }); - function CompileToString(str, tagOpen, tagClose) { + function CompileToString(str, tagOpen, tagClose, env) { var buffer = Parse(str, tagOpen, tagClose); return ("var tR='';" + - ParseScope(buffer) + ParseScope(buffer, env) .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') + 'return tR'); @@ -377,19 +414,19 @@ // TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc. // TODO: Use type intersections for TemplateObject, etc. // so I don't have to make properties mandatory - function parseHelper(res, descendants, params, name) { - var ret = '{exec:' + ParseScopeIntoFunction(descendants, res) + ',params:[' + params + ']'; + function parseHelper(env, res, descendants, params, name) { + var ret = '{exec:' + ParseScopeIntoFunction(descendants, res, env) + ',params:[' + params + ']'; if (name) { ret += ",name:'" + name + "'"; } ret += '}'; return ret; } - function parseBlocks(blocks) { + function parseBlocks(blocks, env) { var ret = '['; for (var i = 0; i < blocks.length; i++) { var block = blocks[i]; - ret += parseHelper(block.res || '', block.d || [], block.p || '', block.n || ''); + ret += parseHelper(env, block.res || '', block.d || [], block.p || '', block.n || ''); if (i < blocks.length) { ret += ','; } @@ -397,10 +434,10 @@ ret += ']'; return ret; } - function ParseScopeIntoFunction(buff, res) { - return 'function(' + res + "){var tR='';" + ParseScope(buff) + 'return tR}'; + function ParseScopeIntoFunction(buff, res, env) { + return 'function(' + res + "){var tR='';" + ParseScope(buff, env) + 'return tR}'; } - function ParseScope(buff) { + function ParseScope(buff, env) { var i = 0; var buffLength = buff.length; var returnStr = ''; @@ -429,12 +466,12 @@ // helper // TODO: native helpers if (NativeHelpers.get(name)) { - returnStr += NativeHelpers.get(name)(currentBlock); + returnStr += NativeHelpers.get(name)(currentBlock, env); } else { - var helperReturn = "Sqrl.H.get('" + name + "')(" + parseHelper(res, currentBlock.d, params); + var helperReturn = "Sqrl.H.get('" + name + "')(" + parseHelper(env, res, currentBlock.d, params); if (blocks) { - helperReturn += ',' + parseBlocks(blocks); + helperReturn += ',' + parseBlocks(blocks, env); } helperReturn += ')'; helperReturn = filter(helperReturn, filters); @@ -466,30 +503,74 @@ return str; } - function Compile(str, tagOpen, tagClose) { - return new Function('it', 'Sqrl', CompileToString(str, tagOpen, tagClose)); // eslint-disable-line no-new-func + var defaultConfig = { + varName: 'it', + autoTrim: false, + autoEscape: true, + defaultFilter: false + }; + var Env = { + cache: { + default: defaultConfig + }, + define: function (key, newConfig) { + if (!this.cache[key]) { + this.cache[key] = defaultConfig; + } + for (var attrname in newConfig) { + this.cache[key][attrname] = newConfig[attrname]; + } + }, + get: function (key) { + // string | array. + // TODO: allow array of keys to look down + return this.cache[key]; + }, + remove: function (key) { + delete this.cache[key]; + }, + clear: function () { + this.cache = {}; + }, + load: function (cacheObj) { + this.cache = cacheObj; + } + }; + // Have different envs. Sqrl.Render, Compile, etc. all use default env + // Use class for env + + function Compile(str, tagOpen, tagClose, envName) { + var SqrlEnv = Env.get(envName || 'default'); + return new Function(SqrlEnv.varName, 'Sqrl', CompileToString(str, tagOpen, tagClose, SqrlEnv)); // eslint-disable-line no-new-func } // console.log(Compile('hi {{this}} hey', '{{', '}}').toString()) - function Render(template, options) { - var templateFunc = Compile(template, '{{', '}}'); - return templateFunc(options, { H: Helpers, F: Filters }); - } - - function Config(key, val) { + function Render(template, data, env, options) { + if (!env) { + env = 'default'; + } + else if (typeof env === 'function') { + env = env(options); // this can be used to dynamically pick an env based on name, etc. + } + if (typeof template === 'function') { + return template(data, { H: Helpers, F: Filters }); + } + // else + var templateFunc = Compile(template, '{{', '}}', env); + return templateFunc(data, { H: Helpers, F: Filters }); } exports.Compile = Compile; exports.CompileToString = CompileToString; - exports.Config = Config; - exports.F = Filters; - exports.H = Helpers; - exports.L = Layouts; - exports.NH = NativeHelpers; - exports.P = Partials; + exports.Env = Env; + exports.Filters = Filters; + exports.Helpers = Helpers; + exports.Layouts = Layouts; + exports.NativeHelpers = NativeHelpers; exports.Parse = Parse; exports.ParseScope = ParseScope; exports.ParseScopeIntoFunction = ParseScopeIntoFunction; + exports.Partials = Partials; exports.Render = Render; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/dist/browser/squirrelly.dev.js.map b/dist/browser/squirrelly.dev.js.map index 24174959..1c07fc96 100644 --- a/dist/browser/squirrelly.dev.js.map +++ b/dist/browser/squirrelly.dev.js.map @@ -1 +1 @@ -{"version":3,"file":"squirrelly.dev.js","sources":["../../src/err.ts","../../src/utils.ts","../../src/parse.ts","../../src/storage.ts","../../src/containers.ts","../../src/compile-string.ts","../../src/compile.ts","../../src/render.ts","../../src/config.ts"],"sourcesContent":["// v 1.0.32\n\nfunction setPrototypeOf (obj: any, proto: any) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(obj, proto)\n } else {\n obj.__proto__ = proto\n }\n}\n\nexport default function SqrlErr (message: string) {\n var err = new Error(message)\n setPrototypeOf(err, SqrlErr.prototype)\n return err\n}\n\nSqrlErr.prototype = Object.create(Error.prototype, {\n name: { value: 'Squirrelly Error', enumerable: false }\n})\n\n// TODO: Class transpilation adds a lot to the bundle size\n\nexport function ParseErr (message: string, str: string, indx: number) {\n var whitespace = str\n .slice(0, indx) // +2 because of {{\n .split(/\\n/)\n\n // console.log('whitespace: \\n' + JSON.stringify(whitespace))\n var lineNo = whitespace.length\n var colNo = whitespace[lineNo - 1].length + 1\n message +=\n ' at line ' +\n lineNo +\n ' col ' +\n colNo +\n ':\\n\\n' +\n ' ' +\n str.split(/\\n/)[lineNo - 1] +\n '\\n' +\n ' ' +\n Array(colNo).join(' ') +\n '^'\n throw SqrlErr(message)\n}\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nexport { trimLeft, trimRight, XMLEscape }\n","// Version 1.0.32\nimport { ParseErr } from './err'\nimport { trimLeft, trimRight } from './utils'\n\nexport type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's'\nexport type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err'\nexport type TemplateObjectAttribute = 'c' | 'p' | 'n' | 'res'\n\nexport type AstObject = string | TemplateObject\n\nexport type Filter = [string, string | undefined]\n\nexport interface TemplateObject {\n n?: string\n t?: string\n f: Array\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (str: string, tagOpen: string, tagClose: string): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d) + '}'\n }\n }\n }\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\nvar Filters = new Cacher({})\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string) {\n var buffer: Array = Parse(str, tagOpen, tagClose)\n return (\n \"var tR='';\" +\n ParseScope(buffer)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (res: string, descendants: Array, params: string, name?: string) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","import CompileToString from './compile-string'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string) {\n return new Function('it', 'Sqrl', CompileToString(str, tagOpen, tagClose)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\nfunction Render (template: string, options: object): string {\n var templateFunc = Compile(template, '{{', '}}')\n return templateFunc(options, { H: Helpers, F: Filters })\n}\n\nexport default Render\nexport type TemplateFunction = (options: object, Sqrl: object) => string\n","interface SqrlConfiguration {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n [index: string]: any\n}\n\nvar Conf: SqrlConfiguration = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true\n}\n\nfunction Config (key: string, val: any): void {\n Conf[key] = val\n}\n\n// TODO: Fix types for this\n\nexport { Conf, Config }\n"],"names":[],"mappings":";;;;;;EAAA;EAEA,SAAS,cAAc,CAAE,GAAQ,EAAE,KAAU;MAC3C,IAAI,MAAM,CAAC,cAAc,EAAE;UACzB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;OAClC;WAAM;UACL,GAAG,CAAC,SAAS,GAAG,KAAK,CAAA;OACtB;E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sB;MAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;UACvC,IAAI,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;UACxB,IAAI,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;UAC1B,GAAG,GAAG,cAAc,GAAG,IAAI,GAAG,KAAK,GAAG,GAAG,CAAA;UACzC,IAAI,MAAM,EAAE;cACV,GAAG,IAAI,GAAG,GAAG,MAAM,CAAA;WACpB;UACD,GAAG,IAAI,GAAG,CAAA;OACX;MACD,OAAO,GAAG,CAAA;EACZ,CAAC;;EC7GD,SAAS,OAAO,CAAE,GAAW,EAAE,OAAe,EAAE,QAAgB;MAC9D,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAA;EAC5E,CAAC;AAED,EACA,iEAAiE;;ECJjE,SAAS,MAAM,CAAE,QAAgB,EAAE,OAAe;MAChD,IAAI,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;MAChD,OAAO,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;EAC1D,CAAC;;ECOD,SAAS,MAAM,CAAE,GAAW,EAAE,GAAQ;EAEtC,CAAC;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"squirrelly.dev.js","sources":["../../src/err.ts","../../src/utils.ts","../../src/parse.ts","../../src/storage.ts","../../src/containers.ts","../../src/compile-string.ts","../../src/config.ts","../../src/compile.ts","../../src/render.ts"],"sourcesContent":["// v 1.0.32\n\nfunction setPrototypeOf (obj: any, proto: any) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(obj, proto)\n } else {\n obj.__proto__ = proto\n }\n}\n\nexport default function SqrlErr (message: string) {\n var err = new Error(message)\n setPrototypeOf(err, SqrlErr.prototype)\n return err\n}\n\nSqrlErr.prototype = Object.create(Error.prototype, {\n name: { value: 'Squirrelly Error', enumerable: false }\n})\n\n// TODO: Class transpilation adds a lot to the bundle size\n\nexport function ParseErr (message: string, str: string, indx: number) {\n var whitespace = str\n .slice(0, indx) // +2 because of {{\n .split(/\\n/)\n\n // console.log('whitespace: \\n' + JSON.stringify(whitespace))\n var lineNo = whitespace.length\n var colNo = whitespace[lineNo - 1].length + 1\n message +=\n ' at line ' +\n lineNo +\n ' col ' +\n colNo +\n ':\\n\\n' +\n ' ' +\n str.split(/\\n/)[lineNo - 1] +\n '\\n' +\n ' ' +\n Array(colNo).join(' ') +\n '^'\n throw SqrlErr(message)\n}\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\nexport { trimLeft, trimRight }\n","// Version 1.0.32\nimport { ParseErr } from './err'\nimport { trimLeft, trimRight } from './utils'\nimport { SqrlConfig } from './config'\n\nexport type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's'\nexport type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err'\nexport type TemplateObjectAttribute = 'c' | 'p' | 'n' | 'res'\n\nexport type AstObject = string | TemplateObject\n\nexport type Filter = [string, string | undefined]\n\nexport interface TemplateObject {\n n?: string\n t?: string\n f: Array\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (\n str: string,\n tagOpen: string,\n tagClose: string,\n env: SqrlConfig\n): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n // TODO: create plugin to allow referencing helpers, filters with dot notation\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\nimport { SqrlConfig } from './config'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d, env) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d, env) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d, env) + '}'\n }\n }\n }\n return returnStr\n },\n try: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'try' can't have filters\")\n }\n if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') {\n throw SqrlErr(\"native helper 'try' only accepts 1 block, 'catch'\")\n }\n var returnStr = 'try{' + ParseScope(buffer.d, env) + '}'\n\n var currentBlock = buffer.b[0]\n returnStr +=\n 'catch' +\n (currentBlock.res ? '(' + currentBlock.res + ')' : '') +\n '{' +\n ParseScope(currentBlock.d, env) +\n '}'\n\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nvar Filters = new Cacher({ e: XMLEscape })\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\nimport { SqrlConfig } from './config'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string, env: SqrlConfig) {\n var buffer: Array = Parse(str, tagOpen, tagClose, env)\n return (\n \"var tR='';\" +\n ParseScope(buffer, env)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (\n env: SqrlConfig,\n res: string,\n descendants: Array,\n params: string,\n name?: string\n) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res, env) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array, env: SqrlConfig) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(env, block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string, env: SqrlConfig) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff, env) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array, env: SqrlConfig) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock, env)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(env, res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks, env)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","interface Dict {\n [key: string]: SqrlConfig\n}\n\ninterface IEnv {\n cache: Dict\n define: (key: string, val: SqrlConfig) => void\n get: (key: string) => SqrlConfig\n remove: (key: string) => void\n clear: () => void\n load: (cacheObj: Dict) => void\n}\n\nexport interface SqrlConfig {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n defaultFilter: false | Function\n [index: string]: any\n}\n\ntype PartialConfig = {\n [P in keyof SqrlConfig]?: SqrlConfig[P]\n}\n\nvar defaultConfig: SqrlConfig = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true,\n defaultFilter: false\n}\n\nvar Env: IEnv = {\n cache: {\n default: defaultConfig\n },\n define: function (key: string, newConfig: PartialConfig) {\n if (!this.cache[key]) {\n this.cache[key] = defaultConfig\n }\n for (var attrname in newConfig) {\n this.cache[key][attrname] = newConfig[attrname]\n }\n },\n get: function (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n },\n remove: function (key: string) {\n delete this.cache[key]\n },\n clear: function () {\n this.cache = {}\n },\n load: function (cacheObj: Dict) {\n this.cache = cacheObj\n }\n}\n\nexport { Env }\n\n// Have different envs. Sqrl.Render, Compile, etc. all use default env\n// Use class for env\n","import CompileToString from './compile-string'\nimport { Env } from './config'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string, envName: string) {\n var SqrlEnv = Env.get(envName || 'default')\n return new Function(SqrlEnv.varName, 'Sqrl', CompileToString(str, tagOpen, tagClose, SqrlEnv)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\ntype TemplateFunction = (data: object, Sqrl: object) => string\ntype DetermineEnvFunction = (options?: object) => string\n\nfunction Render (\n template: string | TemplateFunction,\n data: object,\n env?: string | DetermineEnvFunction,\n options?: object\n) {\n if (!env) {\n env = 'default'\n } else if (typeof env === 'function') {\n env = env(options) // this can be used to dynamically pick an env based on name, etc.\n }\n\n if (typeof template === 'function') {\n return template(data, { H: Helpers, F: Filters })\n }\n // else\n var templateFunc = Compile(template, '{{', '}}', env)\n return templateFunc(data, { H: Helpers, F: Filters })\n}\n\nexport default Render\n"],"names":[],"mappings":";;;;;;EAAA;EAEA,SAAS,cAAc,CAAE,GAAQ,EAAE,KAAU;MAC3C,IAAI,MAAM,CAAC,cAAc,EAAE;UACzB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;OAClC;WAAM;UACL,GAAG,CAAC,SAAS,GAAG,KAAK,CAAA;OACtB;EACH,CAAC;AAED,WAAwB,OAAO,CAAE,OAAe;MAC9C,IAAI,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;MAC5B,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,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GAAG,CAAC,CAAA;OACvB;MACD,KAAK,EAAE;UACL,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;OAChB;MACD,IAAI,EAAE,UAAU,QAAc;UAC5B,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAA;OACtB;GACF,CAAA;AAED,EAEA;EACA,oBAAoB;;EC5DpB,SAAS,OAAO,CAAE,GAAW,EAAE,OAAe,EAAE,QAAgB,EAAE,OAAe;MAC/E,IAAI,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,IAAI,SAAS,CAAC,CAAA;MAC3C,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAA;EAChG,CAAC;AAED,EACA,iEAAiE;;ECHjE,SAAS,MAAM,CACb,QAAmC,EACnC,IAAY,EACZ,GAAmC,EACnC,OAAgB;MAEhB,IAAI,CAAC,GAAG,EAAE;UACR,GAAG,GAAG,SAAS,CAAA;OAChB;WAAM,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;UACpC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,CAAA;OACnB;MAED,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;UAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;OAClD;;MAED,IAAI,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;MACrD,OAAO,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;EACvD,CAAC;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/browser/squirrelly.min.js b/dist/browser/squirrelly.min.js index 746d102b..0b575b76 100644 --- a/dist/browser/squirrelly.min.js +++ b/dist/browser/squirrelly.min.js @@ -1,2 +1,2 @@ -!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).Sqrl={})}(this,(function(e){"use strict";function r(e){var t,n,i=new Error(e);return t=i,n=r.prototype,Object.setPrototypeOf?Object.setPrototypeOf(t,n):t.__proto__=n,i}function t(e,t,n){var i=t.slice(0,n).split(/\n/),o=i.length,f=i[o-1].length+1;throw r(e+=" at line "+o+" col "+f+":\n\n "+t.split(/\n/)[o-1]+"\n "+Array(f).join(" ")+"^")}function n(e,r,n){var i=new RegExp("([|()]|=>)|'(?:\\\\[\\s\\w\"'\\\\`]|[^\\n\\r'\\\\])*?'|`(?:\\\\[\\s\\w\"'\\\\`]|[^\\\\`])*?`|\"(?:\\\\[\\s\\w\"'\\\\`]|[^\\n\\r\"\\\\])*?\"|\\/\\*[^]*?\\*\\/|((\\/)?(-|_)?"+n+")","g"),o=new RegExp("([^]*?)"+r+"(-|_)?\\s*","g"),f=0,c="";function u(){var r,n={f:[],d:[]},u=0,a=0,l=e[f],s="c",p="r";function h(r,i){var o=e.slice(f,r)+(i||""),c=o.trim();if("f"===s)n.f[a-1][0]+=c;else if("fp"===s)n.f[a-1][1]+=c;else if("err"===s){if(c){var u=o.search(/\S/);t("invalid syntax",e,f+u)}}else s&&(n[s]=c);f=r+1}for(f+=1,"~"===l||"#"===l||"/"===l?(s="n",p=l):"!"===l||"?"===l?p=l:f-=1;null!==(r=i.exec(e));){var g=r[1],d=r[2],v=r[3],y=r[4],x=r.index;if(g)"("===g?(0===u&&("n"===s?(h(x),s="p"):"f"===s&&(h(x),s="fp")),u++):")"===g?0===--u&&"c"!==s&&(h(x),s="err"):0===u&&"|"===g?(h(x),s="f",a++,n.f[a-1]=["",""]):"=>"===g&&(h(x),f+=1,s="res");else if(d)return h(x),f+=d.length-1,o.lastIndex=f,c=y,v&&"~"===p&&(p="s"),n.t=p,n}return t("unclosed tag",e,e.length),n}return function r(n,i){n.b=[];var a,l=!1,s=[];function p(e,r){if(e){var t=e.replace(/\\/g,"\\\\").replace(/'/g,"\\'");r&&(t=function(e,r){return"_"===r?String.prototype.trimRight?e.trimRight():e.replace(/[\s\uFEFF\xA0]+$/,""):e.replace(/(?:[\s\uFEFF\xA0]|\r\n)$/,"")}(t,r)),c&&(t=function(e,r){return"_"===r?String.prototype.trimLeft?e.trimLeft():e.replace(/^[\s\uFEFF\xA0]+/,""):e.replace(/^(?:[\s\uFEFF\xA0]|\r\n)/,"")}(t,c),c=""),s.push(t)}}for(;null!==(a=o.exec(e));){p(a[1],a[2]),f=a.index+a[0].length;var h=u(),g=h.t;if("~"===g)h=r(h),s.push(h);else if("/"===g){if(n.n===h.n)return l?(l.d=s,n.b.push(l)):n.d=s,n;t("Helper start and end don't match",e,a.index+a[0].length)}else"#"===g?(l?(l.d=s,n.b.push(l)):n.d=s,l=h,s=[]):s.push(h)}return i&&(p(e.slice(f,e.length)),n.d=s),n}({f:[],d:[]},!0).d}r.prototype=Object.create(Error.prototype,{name:{value:"Squirrelly Error",enumerable:!1}});var i=function(){function e(e){this.cache=e}return e.prototype.define=function(e,r){this.cache[e]=r},e.prototype.get=function(e){return this.cache[e]},e.prototype.remove=function(e){delete this.cache[e]},e.prototype.clear=function(){this.cache={}},e.prototype.load=function(e){this.cache=e},e}(),o=new i({}),f=new i({}),c=new i({each:function(e){for(var r="",t=e.params[0],n=0;n)|'(?:\\\\[\\s\\w\"'\\\\`]|[^\\n\\r'\\\\])*?'|`(?:\\\\[\\s\\w\"'\\\\`]|[^\\\\`])*?`|\"(?:\\\\[\\s\\w\"'\\\\`]|[^\\n\\r\"\\\\])*?\"|\\/\\*[^]*?\\*\\/|((\\/)?(-|_)?"+n+")","g"),o=new RegExp("([^]*?)"+t+"(-|_)?\\s*","g"),a=0,f="";function u(){var t,n={f:[],d:[]},i=0,u=0,l=e[a],s="c",p="r";function h(t,i){var c=e.slice(a,t)+(i||""),o=c.trim();if("f"===s)n.f[u-1][0]+=o;else if("fp"===s)n.f[u-1][1]+=o;else if("err"===s){if(o){var f=c.search(/\S/);r("invalid syntax",e,a+f)}}else s&&(n[s]=o);a=t+1}for(a+=1,"~"===l||"#"===l||"/"===l?(s="n",p=l):"!"===l||"?"===l?p=l:a-=1;null!==(t=c.exec(e));){var v=t[1],d=t[2],g=t[3],y=t[4],m=t.index;if(v)"("===v?(0===i&&("n"===s?(h(m),s="p"):"f"===s&&(h(m),s="fp")),i++):")"===v?0===--i&&"c"!==s&&(h(m),s="err"):0===i&&"|"===v?(h(m),s="f",u++,n.f[u-1]=["",""]):"=>"===v&&(h(m),a+=1,s="res");else if(d)return h(m),a+=d.length-1,o.lastIndex=a,f=y,g&&"~"===p&&(p="s"),n.t=p,n}return r("unclosed tag",e,e.length),n}return function t(n,i){n.b=[];var c,l=!1,s=[];function p(e,t){if(e){var r=e.replace(/\\/g,"\\\\").replace(/'/g,"\\'");t&&(r=function(e,t){return"_"===t?String.prototype.trimRight?e.trimRight():e.replace(/[\s\uFEFF\xA0]+$/,""):e.replace(/(?:[\s\uFEFF\xA0]|\r\n)$/,"")}(r,t)),f&&(r=function(e,t){return"_"===t?String.prototype.trimLeft?e.trimLeft():e.replace(/^[\s\uFEFF\xA0]+/,""):e.replace(/^(?:[\s\uFEFF\xA0]|\r\n)/,"")}(r,f),f=""),s.push(r)}}for(;null!==(c=o.exec(e));){p(c[1],c[2]),a=c.index+c[0].length;var h=u(),v=h.t;if("~"===v)h=t(h),s.push(h);else if("/"===v){if(n.n===h.n)return l?(l.d=s,n.b.push(l)):n.d=s,n;r("Helper start and end don't match",e,c.index+c[0].length)}else"#"===v?(l?(l.d=s,n.b.push(l)):n.d=s,l=h,s=[]):s.push(h)}return i&&(p(e.slice(a,e.length)),n.d=s),n}({f:[],d:[]},!0).d}t.prototype=Object.create(Error.prototype,{name:{value:"Squirrelly Error",enumerable:!1}});var i=function(){function e(e){this.cache=e}return e.prototype.define=function(e,t){this.cache[e]=t},e.prototype.get=function(e){return this.cache[e]},e.prototype.remove=function(e){delete this.cache[e]},e.prototype.clear=function(){this.cache={}},e.prototype.load=function(e){this.cache=e},e}(),c=new i({}),o=new i({}),a=new i({each:function(e){for(var t="",r=e.params[0],n=0;n\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (str: string, tagOpen: string, tagClose: string): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nexport { trimLeft, trimRight, XMLEscape }\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d) + '}'\n }\n }\n }\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\nvar Filters = new Cacher({})\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string) {\n var buffer: Array = Parse(str, tagOpen, tagClose)\n return (\n \"var tR='';\" +\n ParseScope(buffer)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (res: string, descendants: Array, params: string, name?: string) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","import CompileToString from './compile-string'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string) {\n return new Function('it', 'Sqrl', CompileToString(str, tagOpen, tagClose)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","interface SqrlConfiguration {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n [index: string]: any\n}\n\nvar Conf: SqrlConfiguration = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true\n}\n\nfunction Config (key: string, val: any): void {\n Conf[key] = val\n}\n\n// TODO: Fix types for this\n\nexport { Conf, Config }\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\nfunction Render (template: string, options: object): string {\n var templateFunc = Compile(template, '{{', '}}')\n return templateFunc(options, { H: Helpers, F: Filters })\n}\n\nexport default Render\nexport type TemplateFunction = (options: object, Sqrl: object) => string\n"],"names":["SqrlErr","message","obj","proto","err","Error","prototype","Object","setPrototypeOf","__proto__","ParseErr","str","indx","whitespace","slice","split","lineNo","length","colNo","Array","join","Parse","tagOpen","tagClose","powerchars","RegExp","tagOpenReg","startInd","trimNextLeftWs","parseTag","m","currentObj","f","d","numParens","filterNumber","firstChar","currentAttribute","currentType","addAttrValue","strng","valUnprocessed","val","trim","found","search","exec","char","slash","wsControl","i","index","lastIndex","t","parseContext","parentObj","firstParse","b","tagOpenMatch","lastBlock","buffer","pushString","wsAhead","stringToPush","replace","type","String","trimRight","trimLeft","push","n","create","name","value","enumerable","cache","this","Cacher","key","cacheObj","Layouts","Partials","Helpers","each","content","res","param","params","foreach","hasOwnProperty","NativeHelpers","if","returnStr","p","ParseScope","currentBlock","Filters","CompileToString","parseHelper","descendants","ret","ParseScopeIntoFunction","parseBlocks","blocks","block","buff","buffLength","c","filters","filter","get","helperReturn","Compile","Function","template","options","templateFunc","H","F"],"mappings":"2MAUwBA,EAASC,GAC/B,IATuBC,EAAUC,EAS7BC,EAAM,IAAIC,MAAMJ,GAEpB,OAXuBC,EAURE,EAVkBD,EAUbH,EAAQM,UATxBC,OAAOC,eACTD,OAAOC,eAAeN,EAAKC,GAE3BD,EAAIO,UAAYN,EAOXC,WASOM,EAAUT,EAAiBU,EAAaC,GACtD,IAAIC,EAAaF,EACdG,MAAM,EAAGF,GACTG,MAAM,MAGLC,EAASH,EAAWI,OACpBC,EAAQL,EAAWG,EAAS,GAAGC,OAAS,EAa5C,MAAMjB,EAZNC,GACE,YACAe,EACA,QACAE,EACA,UAEAP,EAAII,MAAM,MAAMC,EAAS,GACzB,OAEAG,MAAMD,GAAOE,KAAK,KAClB,cClBoBC,EAAOV,EAAaW,EAAiBC,GAC3D,IAAIC,EAAa,IAAIC,OACnB,8KAGEF,EACA,IACF,KAEEG,EAAa,IAAID,OAAO,UAAYH,EAAU,aAAc,KAC5DK,EAAW,EACXC,EAAi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U,KAAM,KACpCE,CAAaD,EAAS,CAAEE,EAAGnC,EAASoC,EAAGtB"} \ No newline at end of file +{"version":3,"file":"squirrelly.min.js","sources":["../../src/err.ts","../../src/parse.ts","../../src/utils.ts","../../src/storage.ts","../../src/containers.ts","../../src/compile-string.ts","../../src/config.ts","../../src/compile.ts","../../src/render.ts"],"sourcesContent":["// v 1.0.32\n\nfunction setPrototypeOf (obj: any, proto: any) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(obj, proto)\n } else {\n obj.__proto__ = proto\n }\n}\n\nexport default function SqrlErr (message: string) {\n var err = new Error(message)\n setPrototypeOf(err, SqrlErr.prototype)\n return err\n}\n\nSqrlErr.prototype = Object.create(Error.prototype, {\n name: { value: 'Squirrelly Error', enumerable: false }\n})\n\n// TODO: Class transpilation adds a lot to the bundle size\n\nexport function ParseErr (message: string, str: string, indx: number) {\n var whitespace = str\n .slice(0, indx) // +2 because of {{\n .split(/\\n/)\n\n // console.log('whitespace: \\n' + JSON.stringify(whitespace))\n var lineNo = whitespace.length\n var colNo = whitespace[lineNo - 1].length + 1\n message +=\n ' at line ' +\n lineNo +\n ' col ' +\n colNo +\n ':\\n\\n' +\n ' ' +\n str.split(/\\n/)[lineNo - 1] +\n '\\n' +\n ' ' +\n Array(colNo).join(' ') +\n '^'\n throw SqrlErr(message)\n}\n","// Version 1.0.32\nimport { ParseErr } from './err'\nimport { trimLeft, trimRight } from './utils'\nimport { SqrlConfig } from './config'\n\nexport type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's'\nexport type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err'\nexport type TemplateObjectAttribute = 'c' | 'p' | 'n' | 'res'\n\nexport type AstObject = string | TemplateObject\n\nexport type Filter = [string, string | undefined]\n\nexport interface TemplateObject {\n n?: string\n t?: string\n f: Array\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (\n str: string,\n tagOpen: string,\n tagClose: string,\n env: SqrlConfig\n): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\nexport { trimLeft, trimRight }\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n // TODO: create plugin to allow referencing helpers, filters with dot notation\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\nimport { SqrlConfig } from './config'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d, env) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d, env) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d, env) + '}'\n }\n }\n }\n return returnStr\n },\n try: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'try' can't have filters\")\n }\n if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') {\n throw SqrlErr(\"native helper 'try' only accepts 1 block, 'catch'\")\n }\n var returnStr = 'try{' + ParseScope(buffer.d, env) + '}'\n\n var currentBlock = buffer.b[0]\n returnStr +=\n 'catch' +\n (currentBlock.res ? '(' + currentBlock.res + ')' : '') +\n '{' +\n ParseScope(currentBlock.d, env) +\n '}'\n\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nvar Filters = new Cacher({ e: XMLEscape })\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\nimport { SqrlConfig } from './config'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string, env: SqrlConfig) {\n var buffer: Array = Parse(str, tagOpen, tagClose, env)\n return (\n \"var tR='';\" +\n ParseScope(buffer, env)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (\n env: SqrlConfig,\n res: string,\n descendants: Array,\n params: string,\n name?: string\n) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res, env) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array, env: SqrlConfig) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(env, block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string, env: SqrlConfig) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff, env) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array, env: SqrlConfig) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock, env)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(env, res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks, env)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","interface Dict {\n [key: string]: SqrlConfig\n}\n\ninterface IEnv {\n cache: Dict\n define: (key: string, val: SqrlConfig) => void\n get: (key: string) => SqrlConfig\n remove: (key: string) => void\n clear: () => void\n load: (cacheObj: Dict) => void\n}\n\nexport interface SqrlConfig {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n defaultFilter: false | Function\n [index: string]: any\n}\n\ntype PartialConfig = {\n [P in keyof SqrlConfig]?: SqrlConfig[P]\n}\n\nvar defaultConfig: SqrlConfig = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true,\n defaultFilter: false\n}\n\nvar Env: IEnv = {\n cache: {\n default: defaultConfig\n },\n define: function (key: string, newConfig: PartialConfig) {\n if (!this.cache[key]) {\n this.cache[key] = defaultConfig\n }\n for (var attrname in newConfig) {\n this.cache[key][attrname] = newConfig[attrname]\n }\n },\n get: function (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n },\n remove: function (key: string) {\n delete this.cache[key]\n },\n clear: function () {\n this.cache = {}\n },\n load: function (cacheObj: Dict) {\n this.cache = cacheObj\n }\n}\n\nexport { Env }\n\n// Have different envs. Sqrl.Render, Compile, etc. all use default env\n// Use class for env\n","import CompileToString from './compile-string'\nimport { Env } from './config'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string, envName: string) {\n var SqrlEnv = Env.get(envName || 'default')\n return new Function(SqrlEnv.varName, 'Sqrl', CompileToString(str, tagOpen, tagClose, SqrlEnv)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\ntype TemplateFunction = (data: object, Sqrl: object) => string\ntype DetermineEnvFunction = (options?: object) => string\n\nfunction Render (\n template: string | TemplateFunction,\n data: object,\n env?: string | DetermineEnvFunction,\n options?: object\n) {\n if (!env) {\n env = 'default'\n } else if (typeof env === 'function') {\n env = env(options) // this can be used to dynamically pick an env based on name, etc.\n }\n\n if (typeof template === 'function') {\n return template(data, { H: Helpers, F: Filters })\n }\n // else\n var templateFunc = Compile(template, '{{', '}}', env)\n return templateFunc(data, { H: Helpers, F: Filters })\n}\n\nexport default Render\n"],"names":["SqrlErr","message","obj","proto","err","Error","prototype","Object","setPrototypeOf","__proto__","ParseErr","str","indx","whitespace","slice","split","lineNo","length","colNo","Array","join","Parse","tagOpen","tagClose","env","powerchars","RegExp","tagOpenReg","startInd","trimNextLeftWs","parseTag","m","currentObj","f","d","numParens","filterNumber","firstChar","currentAttribute","currentType","addAttrValue","strng","valUnprocessed","val","trim","found","search","exec","char","slash","wsControl","i","index","lastIndex","t","parseContext","parentObj","firstParse","b","tagOpenMatch","lastBlock","buffer","pushString","wsAhead","stringToPush","replace","type","String","trimRight","trimLeft","push","n","create","name","value","enumerable","cache","this","Cacher","key","cacheObj","Layouts","Partials","Helpers","each","content","res","param","params","foreach","hasOwnProperty","NativeHelpers","if","returnStr","p","ParseScope","currentBlock","try","escMap","&","<","\"","'","replaceChar","s","Filters","e","newStr","test","CompileToString","parseHelper","descendants","ret","ParseScopeIntoFunction","parseBlocks","blocks","block","buff","buffLength","c","filters","filter","get","helperReturn","defaultConfig","varName","autoTrim","autoEscape","defaultFilter","Env","default","define","newConfig","attrname","remove","clear","load","Compile","envName","SqrlEnv","Function","template","data","options","H","F","templateFunc"],"mappings":"2MAUwBA,EAASC,GAC/B,IATuBC,EAAUC,EAS7BC,EAAM,IAAIC,MAAMJ,GAEpB,OAXuBC,EAURE,EAVkBD,EAUbH,EAAQM,UATxBC,OAAOC,eACTD,OAAOC,eAAeN,EAAKC,GAE3BD,EAAIO,UAAYN,EAOXC,WASOM,EAAUT,EAAiBU,EAAaC,GACtD,IAAIC,EAAaF,EACdG,MAAM,EAAGF,GACTG,MAAM,MAGLC,EAASH,EAAWI,OACpBC,EAAQL,EAAWG,EAAS,GAAGC,OAAS,EAa5C,MAAMjB,EAZNC,GACE,YACAe,EACA,QACAE,EACA,UAEAP,EAAII,MAAM,MAAMC,EAAS,GACzB,OAEAG,MAAMD,GAAOE,KAAK,KAClB,cCjBoBC,EACtBV,EACAW,EACAC,EACAC,GAEA,IAAIC,EAAa,IAAIC,OACnB,8KAGEH,EACA,IACF,KAEEI,EAAa,IAAID,OAAO,UAAYJ,EAAU,aAAc,KAC5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W,EAASC,EAAUoH,4KCCvF,SACEE,EACAC,EACAtH,EACAuH,GAQA,OANKvH,EAEqB,mBAARA,IAChBA,EAAMA,EAAIuH,IAFVvH,EAAM,UAKgB,mBAAbqH,EACFA,EAASC,EAAM,CAAEE,EAAG7D,EAAS8D,EAAGxC,IAGtBgC,EAAQI,EAAU,KAAM,KAAMrH,EAC1C0H,CAAaJ,EAAM,CAAEE,EAAG7D,EAAS8D,EAAGxC"} \ No newline at end of file diff --git a/dist/squirrelly.cjs.js b/dist/squirrelly.cjs.js index 8c9e0565..5bdc1990 100644 --- a/dist/squirrelly.cjs.js +++ b/dist/squirrelly.cjs.js @@ -98,7 +98,7 @@ function trimRight(str, type) { } // Version 1.0.32 -function Parse(str, tagOpen, tagClose) { +function Parse(str, tagOpen, tagClose, env) { var powerchars = new RegExp('([|()]|=>)|' + '\'(?:\\\\[\\s\\w"\'\\\\`]|[^\\n\\r\'\\\\])*?\'|`(?:\\\\[\\s\\w"\'\\\\`]|[^\\\\`])*?`|"(?:\\\\[\\s\\w"\'\\\\`]|[^\\n\\r"\\\\])*?"' + // matches strings '|\\/\\*[^]*?\\*\\/|((\\/)?(-|_)?' + @@ -304,6 +304,7 @@ var Cacher = /** @class */ (function () { Cacher.prototype.get = function (key) { // string | array. // TODO: allow array of keys to look down + // TODO: create plugin to allow referencing helpers, filters with dot notation return this.cache[key]; }; Cacher.prototype.remove = function (key) { @@ -343,31 +344,67 @@ var Helpers = new Cacher({ } }); var NativeHelpers = new Cacher({ - if: function (buffer) { + if: function (buffer, env) { if (buffer.f && buffer.f.length) { throw SqrlErr("native helper 'if' can't have filters"); } - var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d) + '}'; + var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d, env) + '}'; if (buffer.b) { for (var i = 0; i < buffer.b.length; i++) { var currentBlock = buffer.b[i]; if (currentBlock.n === 'else') { - returnStr += 'else{' + ParseScope(currentBlock.d) + '}'; + returnStr += 'else{' + ParseScope(currentBlock.d, env) + '}'; } else if (currentBlock.n === 'elif') { - returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d) + '}'; + returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d, env) + '}'; } } } return returnStr; + }, + try: function (buffer, env) { + if (buffer.f && buffer.f.length) { + throw SqrlErr("native helper 'try' can't have filters"); + } + if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') { + throw SqrlErr("native helper 'try' only accepts 1 block, 'catch'"); + } + var returnStr = 'try{' + ParseScope(buffer.d, env) + '}'; + var currentBlock = buffer.b[0]; + returnStr += + 'catch' + + (currentBlock.res ? '(' + currentBlock.res + ')' : '') + + '{' + + ParseScope(currentBlock.d, env) + + '}'; + return returnStr; } }); -var Filters = new Cacher({}); +var escMap = { + '&': '&', + '<': '<', + '"': '"', + "'": ''' +}; +function replaceChar(s) { + return escMap[s]; +} +function XMLEscape(str) { + // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized. + var newStr = String(str); + if (/[&<"']/.test(newStr)) { + return newStr.replace(/[&<"']/g, replaceChar); + } + else { + return newStr; + } +} +var Filters = new Cacher({ e: XMLEscape }); -function CompileToString(str, tagOpen, tagClose) { +function CompileToString(str, tagOpen, tagClose, env) { var buffer = Parse(str, tagOpen, tagClose); return ("var tR='';" + - ParseScope(buffer) + ParseScope(buffer, env) .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') + 'return tR'); @@ -375,19 +412,19 @@ function CompileToString(str, tagOpen, tagClose) { // TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc. // TODO: Use type intersections for TemplateObject, etc. // so I don't have to make properties mandatory -function parseHelper(res, descendants, params, name) { - var ret = '{exec:' + ParseScopeIntoFunction(descendants, res) + ',params:[' + params + ']'; +function parseHelper(env, res, descendants, params, name) { + var ret = '{exec:' + ParseScopeIntoFunction(descendants, res, env) + ',params:[' + params + ']'; if (name) { ret += ",name:'" + name + "'"; } ret += '}'; return ret; } -function parseBlocks(blocks) { +function parseBlocks(blocks, env) { var ret = '['; for (var i = 0; i < blocks.length; i++) { var block = blocks[i]; - ret += parseHelper(block.res || '', block.d || [], block.p || '', block.n || ''); + ret += parseHelper(env, block.res || '', block.d || [], block.p || '', block.n || ''); if (i < blocks.length) { ret += ','; } @@ -395,10 +432,10 @@ function parseBlocks(blocks) { ret += ']'; return ret; } -function ParseScopeIntoFunction(buff, res) { - return 'function(' + res + "){var tR='';" + ParseScope(buff) + 'return tR}'; +function ParseScopeIntoFunction(buff, res, env) { + return 'function(' + res + "){var tR='';" + ParseScope(buff, env) + 'return tR}'; } -function ParseScope(buff) { +function ParseScope(buff, env) { var i = 0; var buffLength = buff.length; var returnStr = ''; @@ -427,12 +464,12 @@ function ParseScope(buff) { // helper // TODO: native helpers if (NativeHelpers.get(name)) { - returnStr += NativeHelpers.get(name)(currentBlock); + returnStr += NativeHelpers.get(name)(currentBlock, env); } else { - var helperReturn = "Sqrl.H.get('" + name + "')(" + parseHelper(res, currentBlock.d, params); + var helperReturn = "Sqrl.H.get('" + name + "')(" + parseHelper(env, res, currentBlock.d, params); if (blocks) { - helperReturn += ',' + parseBlocks(blocks); + helperReturn += ',' + parseBlocks(blocks, env); } helperReturn += ')'; helperReturn = filter(helperReturn, filters); @@ -464,29 +501,73 @@ function filter(str, filters) { return str; } -function Compile(str, tagOpen, tagClose) { - return new Function('it', 'Sqrl', CompileToString(str, tagOpen, tagClose)); // eslint-disable-line no-new-func +var defaultConfig = { + varName: 'it', + autoTrim: false, + autoEscape: true, + defaultFilter: false +}; +var Env = { + cache: { + default: defaultConfig + }, + define: function (key, newConfig) { + if (!this.cache[key]) { + this.cache[key] = defaultConfig; + } + for (var attrname in newConfig) { + this.cache[key][attrname] = newConfig[attrname]; + } + }, + get: function (key) { + // string | array. + // TODO: allow array of keys to look down + return this.cache[key]; + }, + remove: function (key) { + delete this.cache[key]; + }, + clear: function () { + this.cache = {}; + }, + load: function (cacheObj) { + this.cache = cacheObj; + } +}; +// Have different envs. Sqrl.Render, Compile, etc. all use default env +// Use class for env + +function Compile(str, tagOpen, tagClose, envName) { + var SqrlEnv = Env.get(envName || 'default'); + return new Function(SqrlEnv.varName, 'Sqrl', CompileToString(str, tagOpen, tagClose, SqrlEnv)); // eslint-disable-line no-new-func } // console.log(Compile('hi {{this}} hey', '{{', '}}').toString()) -function Render(template, options) { - var templateFunc = Compile(template, '{{', '}}'); - return templateFunc(options, { H: Helpers, F: Filters }); -} - -function Config(key, val) { +function Render(template, data, env, options) { + if (!env) { + env = 'default'; + } + else if (typeof env === 'function') { + env = env(options); // this can be used to dynamically pick an env based on name, etc. + } + if (typeof template === 'function') { + return template(data, { H: Helpers, F: Filters }); + } + // else + var templateFunc = Compile(template, '{{', '}}', env); + return templateFunc(data, { H: Helpers, F: Filters }); } exports.Compile = Compile; exports.CompileToString = CompileToString; -exports.Config = Config; -exports.F = Filters; -exports.H = Helpers; -exports.L = Layouts; -exports.NH = NativeHelpers; -exports.P = Partials; +exports.Env = Env; +exports.Filters = Filters; +exports.Helpers = Helpers; +exports.Layouts = Layouts; +exports.NativeHelpers = NativeHelpers; exports.Parse = Parse; exports.ParseScope = ParseScope; exports.ParseScopeIntoFunction = ParseScopeIntoFunction; +exports.Partials = Partials; exports.Render = Render; //# sourceMappingURL=squirrelly.cjs.js.map diff --git a/dist/squirrelly.cjs.js.map b/dist/squirrelly.cjs.js.map index 7e67a136..710847e8 100644 --- a/dist/squirrelly.cjs.js.map +++ b/dist/squirrelly.cjs.js.map @@ -1 +1 @@ -{"version":3,"file":"squirrelly.cjs.js","sources":["../src/err.ts","../src/utils.ts","../src/parse.ts","../src/storage.ts","../src/containers.ts","../src/compile-string.ts","../src/compile.ts","../src/render.ts","../src/config.ts"],"sourcesContent":["// v 1.0.32\n\nfunction setPrototypeOf (obj: any, proto: any) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(obj, proto)\n } else {\n obj.__proto__ = proto\n }\n}\n\nexport default function SqrlErr (message: string) {\n var err = new Error(message)\n setPrototypeOf(err, SqrlErr.prototype)\n return err\n}\n\nSqrlErr.prototype = Object.create(Error.prototype, {\n name: { value: 'Squirrelly Error', enumerable: false }\n})\n\n// TODO: Class transpilation adds a lot to the bundle size\n\nexport function ParseErr (message: string, str: string, indx: number) {\n var whitespace = str\n .slice(0, indx) // +2 because of {{\n .split(/\\n/)\n\n // console.log('whitespace: \\n' + JSON.stringify(whitespace))\n var lineNo = whitespace.length\n var colNo = whitespace[lineNo - 1].length + 1\n message +=\n ' at line ' +\n lineNo +\n ' col ' +\n colNo +\n ':\\n\\n' +\n ' ' +\n str.split(/\\n/)[lineNo - 1] +\n '\\n' +\n ' ' +\n Array(colNo).join(' ') +\n '^'\n throw SqrlErr(message)\n}\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nexport { trimLeft, trimRight, XMLEscape }\n","// Version 1.0.32\nimport { ParseErr } from './err'\nimport { trimLeft, trimRight } from './utils'\n\nexport type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's'\nexport type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err'\nexport type TemplateObjectAttribute = 'c' | 'p' | 'n' | 'res'\n\nexport type AstObject = string | TemplateObject\n\nexport type Filter = [string, string | undefined]\n\nexport interface TemplateObject {\n n?: string\n t?: string\n f: Array\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (str: string, tagOpen: string, tagClose: string): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d) + '}'\n }\n }\n }\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\nvar Filters = new Cacher({})\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string) {\n var buffer: Array = Parse(str, tagOpen, tagClose)\n return (\n \"var tR='';\" +\n ParseScope(buffer)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (res: string, descendants: Array, params: string, name?: string) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","import CompileToString from './compile-string'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string) {\n return new Function('it', 'Sqrl', CompileToString(str, tagOpen, tagClose)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\nfunction Render (template: string, options: object): string {\n var templateFunc = Compile(template, '{{', '}}')\n return templateFunc(options, { H: Helpers, F: Filters })\n}\n\nexport default Render\nexport type TemplateFunction = (options: object, Sqrl: object) => string\n","interface SqrlConfiguration {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n [index: string]: any\n}\n\nvar Conf: SqrlConfiguration = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true\n}\n\nfunction Config (key: string, val: any): void {\n Conf[key] = val\n}\n\n// TODO: Fix types for this\n\nexport { Conf, Config }\n"],"names":[],"mappings":";;;;AAAA;AAEA,SAAS,cAAc,CAAE,GAAQ,EAAE,KAAU;IAC3C,IAAI,MAAM,CAAC,cAAc,EAAE;QACzB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;KAClC;SAAM;QACL,GAAG,CAAC,SAAS,GAAG,KAAK,CAAA;KACtB;CACF;AAED,SAAwB,OAAO,CAAE,OAAe;IAC9C,IAAI,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5B,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IACtC,OAAO,GAAG,CAAA;CACX;AAED,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE;IACjD,IAAI,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,KAAK,EAAE;CACvD,CAAC,CAAA;;AAIF,SAA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W,EAAE,OAAe,EAAE,QAAgB;IAC9D,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAA;CAC3E;AAED,AACA,iEAAiE;;ACJjE,SAAS,MAAM,CAAE,QAAgB,EAAE,OAAe;IAChD,IAAI,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IAChD,OAAO,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;CACzD;;ACOD,SAAS,MAAM,CAAE,GAAW,EAAE,GAAQ;AAEtC,CAAC;;;;;;;;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"squirrelly.cjs.js","sources":["../src/err.ts","../src/utils.ts","../src/parse.ts","../src/storage.ts","../src/containers.ts","../src/compile-string.ts","../src/config.ts","../src/compile.ts","../src/render.ts"],"sourcesContent":["// v 1.0.32\n\nfunction setPrototypeOf (obj: any, proto: any) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(obj, proto)\n } else {\n obj.__proto__ = proto\n }\n}\n\nexport default function SqrlErr (message: string) {\n var err = new Error(message)\n setPrototypeOf(err, SqrlErr.prototype)\n return err\n}\n\nSqrlErr.prototype = Object.create(Error.prototype, {\n name: { value: 'Squirrelly Error', enumerable: false }\n})\n\n// TODO: Class transpilation adds a lot to the bundle size\n\nexport function ParseErr (message: string, str: string, indx: number) {\n var whitespace = str\n .slice(0, indx) // +2 because of {{\n .split(/\\n/)\n\n // console.log('whitespace: \\n' + JSON.stringify(whitespace))\n var lineNo = whitespace.length\n var colNo = whitespace[lineNo - 1].length + 1\n message +=\n ' at line ' +\n lineNo +\n ' col ' +\n colNo +\n ':\\n\\n' +\n ' ' +\n str.split(/\\n/)[lineNo - 1] +\n '\\n' +\n ' ' +\n Array(colNo).join(' ') +\n '^'\n throw SqrlErr(message)\n}\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\nexport { trimLeft, trimRight }\n","// Version 1.0.32\nimport { ParseErr } from './err'\nimport { trimLeft, trimRight } from './utils'\nimport { SqrlConfig } from './config'\n\nexport type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's'\nexport type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err'\nexport type TemplateObjectAttribute = 'c' | 'p' | 'n' | 'res'\n\nexport type AstObject = string | TemplateObject\n\nexport type Filter = [string, string | undefined]\n\nexport interface TemplateObject {\n n?: string\n t?: string\n f: Array\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (\n str: string,\n tagOpen: string,\n tagClose: string,\n env: SqrlConfig\n): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n // TODO: create plugin to allow referencing helpers, filters with dot notation\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\nimport { SqrlConfig } from './config'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d, env) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d, env) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d, env) + '}'\n }\n }\n }\n return returnStr\n },\n try: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'try' can't have filters\")\n }\n if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') {\n throw SqrlErr(\"native helper 'try' only accepts 1 block, 'catch'\")\n }\n var returnStr = 'try{' + ParseScope(buffer.d, env) + '}'\n\n var currentBlock = buffer.b[0]\n returnStr +=\n 'catch' +\n (currentBlock.res ? '(' + currentBlock.res + ')' : '') +\n '{' +\n ParseScope(currentBlock.d, env) +\n '}'\n\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nvar Filters = new Cacher({ e: XMLEscape })\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\nimport { SqrlConfig } from './config'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string, env: SqrlConfig) {\n var buffer: Array = Parse(str, tagOpen, tagClose, env)\n return (\n \"var tR='';\" +\n ParseScope(buffer, env)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (\n env: SqrlConfig,\n res: string,\n descendants: Array,\n params: string,\n name?: string\n) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res, env) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array, env: SqrlConfig) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(env, block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string, env: SqrlConfig) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff, env) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array, env: SqrlConfig) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock, env)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(env, res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks, env)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","interface Dict {\n [key: string]: SqrlConfig\n}\n\ninterface IEnv {\n cache: Dict\n define: (key: string, val: SqrlConfig) => void\n get: (key: string) => SqrlConfig\n remove: (key: string) => void\n clear: () => void\n load: (cacheObj: Dict) => void\n}\n\nexport interface SqrlConfig {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n defaultFilter: false | Function\n [index: string]: any\n}\n\ntype PartialConfig = {\n [P in keyof SqrlConfig]?: SqrlConfig[P]\n}\n\nvar defaultConfig: SqrlConfig = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true,\n defaultFilter: false\n}\n\nvar Env: IEnv = {\n cache: {\n default: defaultConfig\n },\n define: function (key: string, newConfig: PartialConfig) {\n if (!this.cache[key]) {\n this.cache[key] = defaultConfig\n }\n for (var attrname in newConfig) {\n this.cache[key][attrname] = newConfig[attrname]\n }\n },\n get: function (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n },\n remove: function (key: string) {\n delete this.cache[key]\n },\n clear: function () {\n this.cache = {}\n },\n load: function (cacheObj: Dict) {\n this.cache = cacheObj\n }\n}\n\nexport { Env }\n\n// Have different envs. Sqrl.Render, Compile, etc. all use default env\n// Use class for env\n","import CompileToString from './compile-string'\nimport { Env } from './config'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string, envName: string) {\n var SqrlEnv = Env.get(envName || 'default')\n return new Function(SqrlEnv.varName, 'Sqrl', CompileToString(str, tagOpen, tagClose, SqrlEnv)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\ntype TemplateFunction = (data: object, Sqrl: object) => string\ntype DetermineEnvFunction = (options?: object) => string\n\nfunction Render (\n template: string | TemplateFunction,\n data: object,\n env?: string | DetermineEnvFunction,\n options?: object\n) {\n if (!env) {\n env = 'default'\n } else if (typeof env === 'function') {\n env = env(options) // this can be used to dynamically pick an env based on name, etc.\n }\n\n if (typeof template === 'function') {\n return template(data, { H: Helpers, F: Filters })\n }\n // else\n var templateFunc = Compile(template, '{{', '}}', env)\n return templateFunc(data, { H: Helpers, F: Filters })\n}\n\nexport default Render\n"],"names":[],"mappings":";;;;AAAA;AAEA,SAAS,cAAc,CAAE,GAAQ,EAAE,KAAU;IAC3C,IAAI,MAAM,CAAC,cAAc,EAAE;QACzB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;KAClC;SAAM;QACL,GAAG,CAAC,SAAS,GAAG,KAAK,CAAA;KACtB;CACF;AAED,SAAwB,OAAO,CAAE,OAAe;IAC9C,IAAI,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5B,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IACtC,OAAO,GAAG,CAAA;CACX;AAED,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE;IACjD,IAAI,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,KAAK,EAAE;CACvD,CAAC,CAAA;;AAIF,SAAgB,QAAQ,CAAE,OAAe,EAAE,GAAW,EAAE,IAAY;IAClE,IAAI,UAAU,GAAG,GAAG;SACjB,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;SACd,KAAK,CAAC,IAAI,CAAC,CAAA;;IAGd,IAAI,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;IAC9B,IAAI,KAAK,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;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;KAChB;SAAM,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;QACpC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,CAAA;KACnB;IAED,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;QAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;KAClD;;IAED,IAAI,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;IACrD,OAAO,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;CACtD;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/squirrelly.es.js b/dist/squirrelly.es.js index 0d370d8b..304ff0ae 100644 --- a/dist/squirrelly.es.js +++ b/dist/squirrelly.es.js @@ -94,7 +94,7 @@ function trimRight(str, type) { } // Version 1.0.32 -function Parse(str, tagOpen, tagClose) { +function Parse(str, tagOpen, tagClose, env) { var powerchars = new RegExp('([|()]|=>)|' + '\'(?:\\\\[\\s\\w"\'\\\\`]|[^\\n\\r\'\\\\])*?\'|`(?:\\\\[\\s\\w"\'\\\\`]|[^\\\\`])*?`|"(?:\\\\[\\s\\w"\'\\\\`]|[^\\n\\r"\\\\])*?"' + // matches strings '|\\/\\*[^]*?\\*\\/|((\\/)?(-|_)?' + @@ -300,6 +300,7 @@ var Cacher = /** @class */ (function () { Cacher.prototype.get = function (key) { // string | array. // TODO: allow array of keys to look down + // TODO: create plugin to allow referencing helpers, filters with dot notation return this.cache[key]; }; Cacher.prototype.remove = function (key) { @@ -339,31 +340,67 @@ var Helpers = new Cacher({ } }); var NativeHelpers = new Cacher({ - if: function (buffer) { + if: function (buffer, env) { if (buffer.f && buffer.f.length) { throw SqrlErr("native helper 'if' can't have filters"); } - var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d) + '}'; + var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d, env) + '}'; if (buffer.b) { for (var i = 0; i < buffer.b.length; i++) { var currentBlock = buffer.b[i]; if (currentBlock.n === 'else') { - returnStr += 'else{' + ParseScope(currentBlock.d) + '}'; + returnStr += 'else{' + ParseScope(currentBlock.d, env) + '}'; } else if (currentBlock.n === 'elif') { - returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d) + '}'; + returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d, env) + '}'; } } } return returnStr; + }, + try: function (buffer, env) { + if (buffer.f && buffer.f.length) { + throw SqrlErr("native helper 'try' can't have filters"); + } + if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') { + throw SqrlErr("native helper 'try' only accepts 1 block, 'catch'"); + } + var returnStr = 'try{' + ParseScope(buffer.d, env) + '}'; + var currentBlock = buffer.b[0]; + returnStr += + 'catch' + + (currentBlock.res ? '(' + currentBlock.res + ')' : '') + + '{' + + ParseScope(currentBlock.d, env) + + '}'; + return returnStr; } }); -var Filters = new Cacher({}); +var escMap = { + '&': '&', + '<': '<', + '"': '"', + "'": ''' +}; +function replaceChar(s) { + return escMap[s]; +} +function XMLEscape(str) { + // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized. + var newStr = String(str); + if (/[&<"']/.test(newStr)) { + return newStr.replace(/[&<"']/g, replaceChar); + } + else { + return newStr; + } +} +var Filters = new Cacher({ e: XMLEscape }); -function CompileToString(str, tagOpen, tagClose) { +function CompileToString(str, tagOpen, tagClose, env) { var buffer = Parse(str, tagOpen, tagClose); return ("var tR='';" + - ParseScope(buffer) + ParseScope(buffer, env) .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') + 'return tR'); @@ -371,19 +408,19 @@ function CompileToString(str, tagOpen, tagClose) { // TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc. // TODO: Use type intersections for TemplateObject, etc. // so I don't have to make properties mandatory -function parseHelper(res, descendants, params, name) { - var ret = '{exec:' + ParseScopeIntoFunction(descendants, res) + ',params:[' + params + ']'; +function parseHelper(env, res, descendants, params, name) { + var ret = '{exec:' + ParseScopeIntoFunction(descendants, res, env) + ',params:[' + params + ']'; if (name) { ret += ",name:'" + name + "'"; } ret += '}'; return ret; } -function parseBlocks(blocks) { +function parseBlocks(blocks, env) { var ret = '['; for (var i = 0; i < blocks.length; i++) { var block = blocks[i]; - ret += parseHelper(block.res || '', block.d || [], block.p || '', block.n || ''); + ret += parseHelper(env, block.res || '', block.d || [], block.p || '', block.n || ''); if (i < blocks.length) { ret += ','; } @@ -391,10 +428,10 @@ function parseBlocks(blocks) { ret += ']'; return ret; } -function ParseScopeIntoFunction(buff, res) { - return 'function(' + res + "){var tR='';" + ParseScope(buff) + 'return tR}'; +function ParseScopeIntoFunction(buff, res, env) { + return 'function(' + res + "){var tR='';" + ParseScope(buff, env) + 'return tR}'; } -function ParseScope(buff) { +function ParseScope(buff, env) { var i = 0; var buffLength = buff.length; var returnStr = ''; @@ -423,12 +460,12 @@ function ParseScope(buff) { // helper // TODO: native helpers if (NativeHelpers.get(name)) { - returnStr += NativeHelpers.get(name)(currentBlock); + returnStr += NativeHelpers.get(name)(currentBlock, env); } else { - var helperReturn = "Sqrl.H.get('" + name + "')(" + parseHelper(res, currentBlock.d, params); + var helperReturn = "Sqrl.H.get('" + name + "')(" + parseHelper(env, res, currentBlock.d, params); if (blocks) { - helperReturn += ',' + parseBlocks(blocks); + helperReturn += ',' + parseBlocks(blocks, env); } helperReturn += ')'; helperReturn = filter(helperReturn, filters); @@ -460,18 +497,62 @@ function filter(str, filters) { return str; } -function Compile(str, tagOpen, tagClose) { - return new Function('it', 'Sqrl', CompileToString(str, tagOpen, tagClose)); // eslint-disable-line no-new-func +var defaultConfig = { + varName: 'it', + autoTrim: false, + autoEscape: true, + defaultFilter: false +}; +var Env = { + cache: { + default: defaultConfig + }, + define: function (key, newConfig) { + if (!this.cache[key]) { + this.cache[key] = defaultConfig; + } + for (var attrname in newConfig) { + this.cache[key][attrname] = newConfig[attrname]; + } + }, + get: function (key) { + // string | array. + // TODO: allow array of keys to look down + return this.cache[key]; + }, + remove: function (key) { + delete this.cache[key]; + }, + clear: function () { + this.cache = {}; + }, + load: function (cacheObj) { + this.cache = cacheObj; + } +}; +// Have different envs. Sqrl.Render, Compile, etc. all use default env +// Use class for env + +function Compile(str, tagOpen, tagClose, envName) { + var SqrlEnv = Env.get(envName || 'default'); + return new Function(SqrlEnv.varName, 'Sqrl', CompileToString(str, tagOpen, tagClose, SqrlEnv)); // eslint-disable-line no-new-func } // console.log(Compile('hi {{this}} hey', '{{', '}}').toString()) -function Render(template, options) { - var templateFunc = Compile(template, '{{', '}}'); - return templateFunc(options, { H: Helpers, F: Filters }); -} - -function Config(key, val) { +function Render(template, data, env, options) { + if (!env) { + env = 'default'; + } + else if (typeof env === 'function') { + env = env(options); // this can be used to dynamically pick an env based on name, etc. + } + if (typeof template === 'function') { + return template(data, { H: Helpers, F: Filters }); + } + // else + var templateFunc = Compile(template, '{{', '}}', env); + return templateFunc(data, { H: Helpers, F: Filters }); } -export { Compile, CompileToString, Config, Filters as F, Helpers as H, Layouts as L, NativeHelpers as NH, Partials as P, Parse, ParseScope, ParseScopeIntoFunction, Render }; +export { Compile, CompileToString, Env, Filters, Helpers, Layouts, NativeHelpers, Parse, ParseScope, ParseScopeIntoFunction, Partials, Render }; //# sourceMappingURL=squirrelly.es.js.map diff --git a/dist/squirrelly.es.js.map b/dist/squirrelly.es.js.map index 8ce9e881..0c996783 100644 --- a/dist/squirrelly.es.js.map +++ b/dist/squirrelly.es.js.map @@ -1 +1 @@ -{"version":3,"file":"squirrelly.es.js","sources":["../src/err.ts","../src/utils.ts","../src/parse.ts","../src/storage.ts","../src/containers.ts","../src/compile-string.ts","../src/compile.ts","../src/render.ts","../src/config.ts"],"sourcesContent":["// v 1.0.32\n\nfunction setPrototypeOf (obj: any, proto: any) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(obj, proto)\n } else {\n obj.__proto__ = proto\n }\n}\n\nexport default function SqrlErr (message: string) {\n var err = new Error(message)\n setPrototypeOf(err, SqrlErr.prototype)\n return err\n}\n\nSqrlErr.prototype = Object.create(Error.prototype, {\n name: { value: 'Squirrelly Error', enumerable: false }\n})\n\n// TODO: Class transpilation adds a lot to the bundle size\n\nexport function ParseErr (message: string, str: string, indx: number) {\n var whitespace = str\n .slice(0, indx) // +2 because of {{\n .split(/\\n/)\n\n // console.log('whitespace: \\n' + JSON.stringify(whitespace))\n var lineNo = whitespace.length\n var colNo = whitespace[lineNo - 1].length + 1\n message +=\n ' at line ' +\n lineNo +\n ' col ' +\n colNo +\n ':\\n\\n' +\n ' ' +\n str.split(/\\n/)[lineNo - 1] +\n '\\n' +\n ' ' +\n Array(colNo).join(' ') +\n '^'\n throw SqrlErr(message)\n}\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nexport { trimLeft, trimRight, XMLEscape }\n","// Version 1.0.32\nimport { ParseErr } from './err'\nimport { trimLeft, trimRight } from './utils'\n\nexport type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's'\nexport type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err'\nexport type TemplateObjectAttribute = 'c' | 'p' | 'n' | 'res'\n\nexport type AstObject = string | TemplateObject\n\nexport type Filter = [string, string | undefined]\n\nexport interface TemplateObject {\n n?: string\n t?: string\n f: Array\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (str: string, tagOpen: string, tagClose: string): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d) + '}'\n }\n }\n }\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\nvar Filters = new Cacher({})\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string) {\n var buffer: Array = Parse(str, tagOpen, tagClose)\n return (\n \"var tR='';\" +\n ParseScope(buffer)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (res: string, descendants: Array, params: string, name?: string) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","import CompileToString from './compile-string'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string) {\n return new Function('it', 'Sqrl', CompileToString(str, tagOpen, tagClose)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\nfunction Render (template: string, options: object): string {\n var templateFunc = Compile(template, '{{', '}}')\n return templateFunc(options, { H: Helpers, F: Filters })\n}\n\nexport default Render\nexport type TemplateFunction = (options: object, Sqrl: object) => string\n","interface SqrlConfiguration {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n [index: string]: any\n}\n\nvar Conf: SqrlConfiguration = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true\n}\n\nfunction Config (key: string, val: any): void {\n Conf[key] = val\n}\n\n// TODO: Fix types for this\n\nexport { Conf, Config }\n"],"names":[],"mappings":"AAAA;AAEA,SAAS,cAAc,CAAE,GAAQ,EAAE,KAAU;IAC3C,IAAI,MAAM,CAAC,cAAc,EAAE;QACzB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;KAClC;SAAM;QACL,GAAG,CAAC,SAAS,GAAG,KAAK,CAAA;KACtB;CACF;AAED,SAAwB,OAAO,CAAE,OAAe;IAC9C,IAAI,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5B,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IACtC,OAAO,GAAG,CAAA;CACX;AAED,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE;IACjD,IAAI,EAAE,EAAE,KAAK,EAAE,kBAAkB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X;IACD,OAAO,GAAG,CAAA;CACX;;AC7GD,SAAS,OAAO,CAAE,GAAW,EAAE,OAAe,EAAE,QAAgB;IAC9D,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAA;CAC3E;AAED,AACA,iEAAiE;;ACJjE,SAAS,MAAM,CAAE,QAAgB,EAAE,OAAe;IAChD,IAAI,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IAChD,OAAO,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;CACzD;;ACOD,SAAS,MAAM,CAAE,GAAW,EAAE,GAAQ;AAEtC,CAAC;;;;"} \ No newline at end of file +{"version":3,"file":"squirrelly.es.js","sources":["../src/err.ts","../src/utils.ts","../src/parse.ts","../src/storage.ts","../src/containers.ts","../src/compile-string.ts","../src/config.ts","../src/compile.ts","../src/render.ts"],"sourcesContent":["// v 1.0.32\n\nfunction setPrototypeOf (obj: any, proto: any) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(obj, proto)\n } else {\n obj.__proto__ = proto\n }\n}\n\nexport default function SqrlErr (message: string) {\n var err = new Error(message)\n setPrototypeOf(err, SqrlErr.prototype)\n return err\n}\n\nSqrlErr.prototype = Object.create(Error.prototype, {\n name: { value: 'Squirrelly Error', enumerable: false }\n})\n\n// TODO: Class transpilation adds a lot to the bundle size\n\nexport function ParseErr (message: string, str: string, indx: number) {\n var whitespace = str\n .slice(0, indx) // +2 because of {{\n .split(/\\n/)\n\n // console.log('whitespace: \\n' + JSON.stringify(whitespace))\n var lineNo = whitespace.length\n var colNo = whitespace[lineNo - 1].length + 1\n message +=\n ' at line ' +\n lineNo +\n ' col ' +\n colNo +\n ':\\n\\n' +\n ' ' +\n str.split(/\\n/)[lineNo - 1] +\n '\\n' +\n ' ' +\n Array(colNo).join(' ') +\n '^'\n throw SqrlErr(message)\n}\n","/**\n * Trims either one whitespace character from the beginning of a string, or all\n *\n * @remarks\n * Includes trimLeft polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\n// TODO: allow '-' to trim up until newline. Use [^\\S\\n\\r] instead of \\s\n// TODO: only include trimLeft polyfill if not in ES6\n\nfunction trimLeft (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimLeft) {\n return str.trimLeft()\n } else {\n return str.replace(/^[\\s\\uFEFF\\xA0]+/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/^(?:[\\s\\uFEFF\\xA0]|\\r\\n)/, '')\n }\n}\n\n/**\n * Trims either one whitespace character from the end of the string, or all\n *\n * @remarks\n * Includes trimRight polyfill\n *\n * @param str - String to trim\n * @param type - Either '-' (trim only 1 whitespace char) or '_' (trim all whitespace)\n * @returns Trimmed string\n *\n */\n\nfunction trimRight (str: string, type: string): string {\n if (type === '_') {\n // full slurp\n if (String.prototype.trimRight) {\n return str.trimRight()\n } else {\n return str.replace(/[\\s\\uFEFF\\xA0]+$/, '')\n }\n } else {\n // type must be '-'\n return str.replace(/(?:[\\s\\uFEFF\\xA0]|\\r\\n)$/, '') // TODO: make sure this gets \\r\\n\n }\n}\n\nexport { trimLeft, trimRight }\n","// Version 1.0.32\nimport { ParseErr } from './err'\nimport { trimLeft, trimRight } from './utils'\nimport { SqrlConfig } from './config'\n\nexport type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's'\nexport type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err'\nexport type TemplateObjectAttribute = 'c' | 'p' | 'n' | 'res'\n\nexport type AstObject = string | TemplateObject\n\nexport type Filter = [string, string | undefined]\n\nexport interface TemplateObject {\n n?: string\n t?: string\n f: Array\n c?: string\n p?: string\n res?: string\n d: Array // Todo: Make this optional\n b?: Array\n}\n\nexport default function Parse (\n str: string,\n tagOpen: string,\n tagClose: string,\n env: SqrlConfig\n): Array {\n var powerchars = new RegExp(\n '([|()]|=>)|' +\n '\\'(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\\'\\\\\\\\])*?\\'|`(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\\\\\`])*?`|\"(?:\\\\\\\\[\\\\s\\\\w\"\\'\\\\\\\\`]|[^\\\\n\\\\r\"\\\\\\\\])*?\"' + // matches strings\n '|\\\\/\\\\*[^]*?\\\\*\\\\/|((\\\\/)?(-|_)?' +\n tagClose +\n ')',\n 'g'\n )\n var tagOpenReg = new RegExp('([^]*?)' + tagOpen + '(-|_)?\\\\s*', 'g')\n var startInd = 0\n var trimNextLeftWs = ''\n\n function parseTag (): TemplateObject {\n // console.log(JSON.stringify(match))\n var currentObj: TemplateObject = { f: [], d: [] }\n var numParens = 0\n var filterNumber = 0\n var firstChar = str[startInd]\n var currentAttribute: TemplateAttribute = 'c' // default - Valid values: 'c'=content, 'f'=filter, 'fp'=filter params, 'p'=param, 'n'=name\n var currentType: TagType = 'r' // Default\n startInd += 1 // assume we're gonna skip the first character\n\n if (firstChar === '~' || firstChar === '#' || firstChar === '/') {\n currentAttribute = 'n'\n currentType = firstChar\n } else if (firstChar === '!' || firstChar === '?') {\n // ? for custom\n currentType = firstChar\n } else {\n startInd -= 1\n }\n\n function addAttrValue (indx: number, strng?: string) {\n var valUnprocessed = str.slice(startInd, indx) + (strng || '')\n // console.log(valUnprocessed)\n var val = valUnprocessed.trim()\n if (currentAttribute === 'f') {\n currentObj.f[filterNumber - 1][0] += val // filterNumber - 1 because first filter: 0->1, but zero-indexed arrays\n } else if (currentAttribute === 'fp') {\n currentObj.f[filterNumber - 1][1] += val\n } else if (currentAttribute === 'err') {\n if (val) {\n var found = valUnprocessed.search(/\\S/)\n ParseErr('invalid syntax', str, startInd + found)\n }\n } else if (currentAttribute) {\n // if (currentObj[currentAttribute]) { // TODO make sure no errs\n // currentObj[currentAttribute] += val\n // } else {\n currentObj[currentAttribute] = val\n // }\n }\n startInd = indx + 1\n }\n var m\n // tslint:disable-next-line:no-conditional-assignment\n while ((m = powerchars.exec(str)) !== null) {\n var char = m[1]\n var tagClose = m[2]\n var slash = m[3]\n var wsControl = m[4]\n var i = m.index\n\n if (char) {\n // Power character\n if (char === '(') {\n if (numParens === 0) {\n if (currentAttribute === 'n') {\n addAttrValue(i)\n currentAttribute = 'p'\n } else if (currentAttribute === 'f') {\n addAttrValue(i)\n currentAttribute = 'fp'\n }\n }\n numParens++\n } else if (char === ')') {\n numParens--\n if (numParens === 0 && currentAttribute !== 'c') {\n // Then it's closing a filter, block, or helper\n addAttrValue(i)\n\n currentAttribute = 'err' // Reset the current attribute\n }\n } else if (numParens === 0 && char === '|') {\n addAttrValue(i) // this should actually always be whitespace or empty\n currentAttribute = 'f'\n filterNumber++\n // TODO if (!currentObj.f) {\n // currentObj.f = [] // Initial assign\n // }\n currentObj.f[filterNumber - 1] = ['', '']\n } else if (char === '=>') {\n addAttrValue(i)\n startInd += 1 // this is 2 chars\n currentAttribute = 'res'\n }\n } else if (tagClose) {\n addAttrValue(i)\n startInd += tagClose.length - 1\n tagOpenReg.lastIndex = startInd\n // console.log('tagClose: ' + startInd)\n trimNextLeftWs = wsControl\n if (slash && currentType === '~') {\n currentType = 's'\n } // TODO throw err\n currentObj.t = currentType\n return currentObj\n }\n }\n // TODO: Do I need this?\n ParseErr('unclosed tag', str, str.length)\n return currentObj // To prevent TypeScript from erroring\n }\n\n function parseContext (parentObj: TemplateObject, firstParse?: boolean): TemplateObject {\n parentObj.b = [] // assume there will be blocks\n var lastBlock: TemplateObject | boolean = false\n var buffer: Array = []\n\n function pushString (strng: string, wsAhead?: string) {\n if (strng) {\n var stringToPush = strng.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n if (wsAhead) {\n stringToPush = trimRight(stringToPush, wsAhead)\n }\n if (trimNextLeftWs) {\n stringToPush = trimLeft(stringToPush, trimNextLeftWs)\n trimNextLeftWs = ''\n }\n buffer.push(stringToPush)\n }\n }\n\n // Random TODO: parentObj.b doesn't need to have t: #\n var tagOpenMatch\n // tslint:disable-next-line:no-conditional-assignment\n while ((tagOpenMatch = tagOpenReg.exec(str)) !== null) {\n var precedingString = tagOpenMatch[1]\n var ws = tagOpenMatch[2]\n\n pushString(precedingString, ws)\n startInd = tagOpenMatch.index + tagOpenMatch[0].length\n\n var currentObj = parseTag()\n // ===== NOW ADD THE OBJECT TO OUR BUFFER =====\n\n var currentType = currentObj.t\n if (currentType === '~') {\n currentObj = parseContext(currentObj) // currentObj is the parent object\n buffer.push(currentObj)\n } else if (currentType === '/') {\n if (parentObj.n === currentObj.n) {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n // console.log('parentObj: ' + JSON.stringify(parentObj))\n return parentObj\n } else {\n ParseErr(\n \"Helper start and end don't match\",\n str,\n tagOpenMatch.index + tagOpenMatch[0].length\n )\n }\n } else if (currentType === '#') {\n if (lastBlock) {\n // If there's a previous block\n lastBlock.d = buffer\n parentObj.b.push(lastBlock)\n } else {\n parentObj.d = buffer\n }\n lastBlock = currentObj // Set the 'lastBlock' object to the value of the current block\n\n buffer = []\n } else {\n buffer.push(currentObj)\n }\n // ===== DONE ADDING OBJECT TO BUFFER =====\n }\n\n if (firstParse) {\n // TODO: more intuitive\n pushString(str.slice(startInd, str.length))\n parentObj.d = buffer\n }\n\n return parentObj\n }\n\n var parseResult = parseContext({ f: [], d: [] }, true)\n // console.log(JSON.stringify(parseResult))\n return parseResult.d // Parse the very outside context\n}\n\n// TODO: Don't add f[] by default. Use currentObj.f[currentObj.f.length - 1] instead of using filterNumber\n","import SqrlErr from './err'\n\ninterface ICache {\n // Basically, an object where all keys point to a value of the same type\n [key: string]: T\n}\n\nclass Cacher {\n constructor (private cache: ICache) {}\n define (key: string, val: T) {\n this.cache[key] = val\n }\n get (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n // TODO: create plugin to allow referencing helpers, filters with dot notation\n return this.cache[key]\n }\n remove (key: string) {\n delete this.cache[key]\n }\n clear () {\n this.cache = {}\n }\n load (cacheObj: ICache) {\n this.cache = cacheObj\n }\n}\n\nexport { Cacher }\n","import { Cacher } from './storage'\nimport { AstObject, Filter, TemplateObject } from './parse'\nimport SqrlErr from './err'\nimport { ParseScope } from './compile-string'\nimport { SqrlConfig } from './config'\n\ntype TemplateFunction = (options: object, Sqrl: object) => string\n\n// interface ITemplate {\n// exec: (options: object, Sqrl: object) => string\n// }\n\nvar Templates = new Cacher({})\n\n// Templates.define(\"hey\", function (it) {return \"hey\"})\n\nvar Layouts = new Cacher({})\n\nvar Partials = new Cacher({})\n\ninterface HelperBlock {\n exec: Function\n params: Array\n}\ntype HelperFunction = (content: HelperBlock, blocks: Array) => string\n\nvar Helpers = new Cacher({\n each: function (content: HelperBlock) {\n // helperStart is called with (params, id) but id isn't needed\n var res = ''\n var param = content.params[0]\n for (var i = 0; i < param.length; i++) {\n res += content.exec(param[i], i)\n }\n return res\n },\n foreach: function (content: HelperBlock) {\n var res = ''\n var param = content.params[0]\n for (var key in param) {\n if (!param.hasOwnProperty(key)) continue\n res += content.exec(param, key)\n }\n return res\n }\n})\n\nvar NativeHelpers = new Cacher({\n if: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'if' can't have filters\")\n }\n var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d, env) + '}'\n if (buffer.b) {\n for (var i = 0; i < buffer.b.length; i++) {\n var currentBlock = buffer.b[i]\n if (currentBlock.n === 'else') {\n returnStr += 'else{' + ParseScope(currentBlock.d, env) + '}'\n } else if (currentBlock.n === 'elif') {\n returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d, env) + '}'\n }\n }\n }\n return returnStr\n },\n try: function (buffer: TemplateObject, env: SqrlConfig) {\n if (buffer.f && buffer.f.length) {\n throw SqrlErr(\"native helper 'try' can't have filters\")\n }\n if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') {\n throw SqrlErr(\"native helper 'try' only accepts 1 block, 'catch'\")\n }\n var returnStr = 'try{' + ParseScope(buffer.d, env) + '}'\n\n var currentBlock = buffer.b[0]\n returnStr +=\n 'catch' +\n (currentBlock.res ? '(' + currentBlock.res + ')' : '') +\n '{' +\n ParseScope(currentBlock.d, env) +\n '}'\n\n return returnStr\n }\n})\n\ntype FilterFunction = (str: string) => string\n\ninterface EscapeMap {\n '&': '&'\n '<': '<'\n '\"': '"'\n \"'\": '''\n [index: string]: string\n}\n\nvar escMap: EscapeMap = {\n '&': '&',\n '<': '<',\n '\"': '"',\n \"'\": '''\n}\n\nfunction replaceChar (s: string): string {\n return escMap[s]\n}\n\nfunction XMLEscape (str: any) {\n // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.\n var newStr = String(str)\n if (/[&<\"']/.test(newStr)) {\n return newStr.replace(/[&<\"']/g, replaceChar)\n } else {\n return newStr\n }\n}\n\nvar Filters = new Cacher({ e: XMLEscape })\n\nexport { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters }\n","import Parse, { AstObject, Filter, TemplateObject } from './parse'\nimport { NativeHelpers } from './containers'\nimport { SqrlConfig } from './config'\n\nfunction CompileToString (str: string, tagOpen: string, tagClose: string, env: SqrlConfig) {\n var buffer: Array = Parse(str, tagOpen, tagClose, env)\n return (\n \"var tR='';\" +\n ParseScope(buffer, env)\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r') +\n 'return tR'\n )\n}\n\n// TODO: rename parseHelper, parseScope, etc. to compileHelper, compileScope, etc.\n// TODO: Use type intersections for TemplateObject, etc.\n// so I don't have to make properties mandatory\n\nfunction parseHelper (\n env: SqrlConfig,\n res: string,\n descendants: Array,\n params: string,\n name?: string\n) {\n var ret = '{exec:' + ParseScopeIntoFunction(descendants, res, env) + ',params:[' + params + ']'\n if (name) {\n ret += \",name:'\" + name + \"'\"\n }\n ret += '}'\n return ret\n}\n\nfunction parseBlocks (blocks: Array, env: SqrlConfig) {\n var ret = '['\n for (var i = 0; i < blocks.length; i++) {\n var block = blocks[i]\n ret += parseHelper(env, block.res || '', block.d || [], block.p || '', block.n || '')\n if (i < blocks.length) {\n ret += ','\n }\n }\n ret += ']'\n return ret\n}\n\nexport function ParseScopeIntoFunction (buff: Array, res: string, env: SqrlConfig) {\n return 'function(' + res + \"){var tR='';\" + ParseScope(buff, env) + 'return tR}'\n}\n\nexport function ParseScope (buff: Array, env: SqrlConfig) {\n var i = 0\n var buffLength = buff.length\n var returnStr = ''\n\n for (i; i < buffLength; i++) {\n var currentBlock = buff[i]\n if (typeof currentBlock === 'string') {\n var str = currentBlock\n\n // we know string exists\n returnStr += \"tR+='\" + str /*.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")*/ + \"';\"\n // I believe the above replace is already in Parse\n } else {\n var type = currentBlock.t // ~, s, !, ?, r\n var content = currentBlock.c || ''\n var filters = currentBlock.f || []\n var name = currentBlock.n || ''\n var params = currentBlock.p || ''\n var res = currentBlock.res || ''\n var blocks = currentBlock.b || []\n\n if (type === 'r') {\n var filtered = filter(content, filters)\n returnStr += 'tR+=' + filtered + ';'\n // reference\n } else if (type === '~') {\n // helper\n // TODO: native helpers\n if (NativeHelpers.get(name)) {\n returnStr += NativeHelpers.get(name)(currentBlock, env)\n } else {\n var helperReturn =\n \"Sqrl.H.get('\" + name + \"')(\" + parseHelper(env, res, currentBlock.d, params)\n if (blocks) {\n helperReturn += ',' + parseBlocks(blocks, env)\n }\n helperReturn += ')'\n\n helperReturn = filter(helperReturn, filters)\n returnStr += 'tR+=' + helperReturn + ';'\n }\n } else if (type === 's') {\n returnStr += 'tR+=' + filter(\"Sqrl.H.get('\" + name + \"')(\" + params + ')', filters) + ';'\n // self-closing helper\n } else if (type === '!') {\n // execute\n returnStr += content + ';'\n } else if (type === '?') {\n // custom (implement later)\n }\n }\n }\n return returnStr\n}\n\nfunction filter (str: string, filters: Array) {\n for (var i = 0; i < filters.length; i++) {\n var name = filters[i][0]\n var params = filters[i][1]\n str = \"Sqrl.F.get('\" + name + \"')(\" + str\n if (params) {\n str += ',' + params\n }\n str += ')'\n }\n return str\n}\n\nexport default CompileToString\n","interface Dict {\n [key: string]: SqrlConfig\n}\n\ninterface IEnv {\n cache: Dict\n define: (key: string, val: SqrlConfig) => void\n get: (key: string) => SqrlConfig\n remove: (key: string) => void\n clear: () => void\n load: (cacheObj: Dict) => void\n}\n\nexport interface SqrlConfig {\n varName: string\n autoTrim: boolean | 'nl'\n autoEscape: boolean\n defaultFilter: false | Function\n [index: string]: any\n}\n\ntype PartialConfig = {\n [P in keyof SqrlConfig]?: SqrlConfig[P]\n}\n\nvar defaultConfig: SqrlConfig = {\n varName: 'it',\n autoTrim: false,\n autoEscape: true,\n defaultFilter: false\n}\n\nvar Env: IEnv = {\n cache: {\n default: defaultConfig\n },\n define: function (key: string, newConfig: PartialConfig) {\n if (!this.cache[key]) {\n this.cache[key] = defaultConfig\n }\n for (var attrname in newConfig) {\n this.cache[key][attrname] = newConfig[attrname]\n }\n },\n get: function (key: string) {\n // string | array.\n // TODO: allow array of keys to look down\n return this.cache[key]\n },\n remove: function (key: string) {\n delete this.cache[key]\n },\n clear: function () {\n this.cache = {}\n },\n load: function (cacheObj: Dict) {\n this.cache = cacheObj\n }\n}\n\nexport { Env }\n\n// Have different envs. Sqrl.Render, Compile, etc. all use default env\n// Use class for env\n","import CompileToString from './compile-string'\nimport { Env } from './config'\n\nfunction Compile (str: string, tagOpen: string, tagClose: string, envName: string) {\n var SqrlEnv = Env.get(envName || 'default')\n return new Function(SqrlEnv.varName, 'Sqrl', CompileToString(str, tagOpen, tagClose, SqrlEnv)) // eslint-disable-line no-new-func\n}\n\nexport default Compile\n// console.log(Compile('hi {{this}} hey', '{{', '}}').toString())\n","import Compile from './compile'\nimport { Helpers, Filters } from './containers'\n\ntype TemplateFunction = (data: object, Sqrl: object) => string\ntype DetermineEnvFunction = (options?: object) => string\n\nfunction Render (\n template: string | TemplateFunction,\n data: object,\n env?: string | DetermineEnvFunction,\n options?: object\n) {\n if (!env) {\n env = 'default'\n } else if (typeof env === 'function') {\n env = env(options) // this can be used to dynamically pick an env based on name, etc.\n }\n\n if (typeof template === 'function') {\n return template(data, { H: Helpers, F: Filters })\n }\n // else\n var templateFunc = Compile(template, '{{', '}}', env)\n return templateFunc(data, { H: Helpers, F: Filters })\n}\n\nexport default Render\n"],"names":[],"mappings":"AAAA;AAEA,SAAS,cAAc,CAAE,GAAQ,EAAE,KAAU;IAC3C,IAAI,MAAM,CAAC,cAAc,EAAE;QACzB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;KAClC;SAAM;QACL,GAAG,CAAC,SAAS,GAAG,KAAK,CAAA;KACtB;CACF;AAED,SAAwB,OAAO,CAAE,OAAe;IAC9C,IAAI,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5B,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IACtC,OAAO,GAAG,CAAA;CACX;AAED,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE;IACjD,IAAI,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,KAAK,EAAE;CACvD,CAAC,CAAA;;AAIF,SAAgB,QAAQ,CAAE,OAAe,EAAE,GAAW,EAAE,IAAY;IAClE,IAAI,UAAU,GAAG,GAAG;SACjB,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;SACd,KAAK,CAAC,IAAI,CAAC,CAAA;;IAGd,IAAI,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;IAC9B,IAAI,KAAK,GAAG,UAAU,CAAC,MAAM,GAAG,C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,GAAG,EAAE;QACR,GAAG,GAAG,SAAS,CAAA;KAChB;SAAM,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;QACpC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,CAAA;KACnB;IAED,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;QAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;KAClD;;IAED,IAAI,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;IACrD,OAAO,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;CACtD;;;;"} \ No newline at end of file diff --git a/dist/types/browser.d.ts b/dist/types/browser.d.ts deleted file mode 100644 index 37f38fe2..00000000 --- a/dist/types/browser.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export { default as CompileToString, ParseScope, ParseScopeIntoFunction } from './compile-string'; -export { default as Compile } from './compile'; -export { default as Parse } from './parse'; -export { default as Render } from './render'; -export { Helpers as H, NativeHelpers as NH, Filters as F, Partials as P, Layouts as L } from './containers'; -export { Config } from './config'; diff --git a/dist/types/compile-string.d.ts b/dist/types/compile-string.d.ts index 12814a27..2a015c57 100644 --- a/dist/types/compile-string.d.ts +++ b/dist/types/compile-string.d.ts @@ -1,5 +1,6 @@ import { AstObject } from './parse'; -declare function CompileToString(str: string, tagOpen: string, tagClose: string): string; -export declare function ParseScopeIntoFunction(buff: Array, res: string): string; -export declare function ParseScope(buff: Array): string; +import { SqrlConfig } from './config'; +declare function CompileToString(str: string, tagOpen: string, tagClose: string, env: SqrlConfig): string; +export declare function ParseScopeIntoFunction(buff: Array, res: string, env: SqrlConfig): string; +export declare function ParseScope(buff: Array, env: SqrlConfig): string; export default CompileToString; diff --git a/dist/types/compile.d.ts b/dist/types/compile.d.ts index c9ec2e5b..387a9c08 100644 --- a/dist/types/compile.d.ts +++ b/dist/types/compile.d.ts @@ -1,2 +1,2 @@ -declare function Compile(str: string, tagOpen: string, tagClose: string): Function; +declare function Compile(str: string, tagOpen: string, tagClose: string, envName: string): Function; export default Compile; diff --git a/dist/types/config.d.ts b/dist/types/config.d.ts index 3f96b97c..7b051706 100644 --- a/dist/types/config.d.ts +++ b/dist/types/config.d.ts @@ -1,9 +1,20 @@ -interface SqrlConfiguration { +interface Dict { + [key: string]: SqrlConfig; +} +interface IEnv { + cache: Dict; + define: (key: string, val: SqrlConfig) => void; + get: (key: string) => SqrlConfig; + remove: (key: string) => void; + clear: () => void; + load: (cacheObj: Dict) => void; +} +export interface SqrlConfig { varName: string; autoTrim: boolean | 'nl'; autoEscape: boolean; + defaultFilter: false | Function; [index: string]: any; } -declare var Conf: SqrlConfiguration; -declare function Config(key: string, val: any): void; -export { Conf, Config }; +declare var Env: IEnv; +export { Env }; diff --git a/dist/types/index.d.ts b/dist/types/index.d.ts index 37f38fe2..621b548c 100644 --- a/dist/types/index.d.ts +++ b/dist/types/index.d.ts @@ -2,5 +2,5 @@ export { default as CompileToString, ParseScope, ParseScopeIntoFunction } from ' export { default as Compile } from './compile'; export { default as Parse } from './parse'; export { default as Render } from './render'; -export { Helpers as H, NativeHelpers as NH, Filters as F, Partials as P, Layouts as L } from './containers'; -export { Config } from './config'; +export { Helpers, NativeHelpers, Filters, Partials, Layouts } from './containers'; +export { Env } from './config'; diff --git a/dist/types/parse.d.ts b/dist/types/parse.d.ts index 3b063b49..ac2fedab 100644 --- a/dist/types/parse.d.ts +++ b/dist/types/parse.d.ts @@ -1,3 +1,4 @@ +import { SqrlConfig } from './config'; export declare type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's'; export declare type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err'; export declare type TemplateObjectAttribute = 'c' | 'p' | 'n' | 'res'; @@ -13,4 +14,4 @@ export interface TemplateObject { d: Array; b?: Array; } -export default function Parse(str: string, tagOpen: string, tagClose: string): Array; +export default function Parse(str: string, tagOpen: string, tagClose: string, env: SqrlConfig): Array; diff --git a/dist/types/render.d.ts b/dist/types/render.d.ts index d1d10f2a..1a73a31e 100644 --- a/dist/types/render.d.ts +++ b/dist/types/render.d.ts @@ -1,3 +1,4 @@ -declare function Render(template: string, options: object): string; +declare type TemplateFunction = (data: object, Sqrl: object) => string; +declare type DetermineEnvFunction = (options?: object) => string; +declare function Render(template: string | TemplateFunction, data: object, env?: string | DetermineEnvFunction, options?: object): any; export default Render; -export declare type TemplateFunction = (options: object, Sqrl: object) => string; diff --git a/dist/types/utils.d.ts b/dist/types/utils.d.ts index e70472eb..6a34354d 100644 --- a/dist/types/utils.d.ts +++ b/dist/types/utils.d.ts @@ -22,5 +22,4 @@ declare function trimLeft(str: string, type: string): string; * */ declare function trimRight(str: string, type: string): string; -declare function XMLEscape(str: any): string; -export { trimLeft, trimRight, XMLEscape }; +export { trimLeft, trimRight }; diff --git a/examples/conditionals.ts b/examples/conditionals.ts index 8d1b71ae..b5040e46 100644 --- a/examples/conditionals.ts +++ b/examples/conditionals.ts @@ -1,4 +1,4 @@ -var Sqrl = require('../dist/squirrelly-next.umd') +var Sqrl = require('../dist/squirrelly.cjs') var template = ` The Daugherty's have 8 kids. Their names are: {{~each (it.riceKids) => val, index}} @@ -9,7 +9,7 @@ The Daugherty's have 8 kids. Their names are: {{_/if}} {{_/each}} ` -Sqrl.F.define('capitalize', function (str) { +Sqrl.Filters.define('capitalize', function (str) { return str.toUpperCase() }) diff --git a/examples/trycatch.ts b/examples/trycatch.ts new file mode 100644 index 00000000..314d7170 --- /dev/null +++ b/examples/trycatch.ts @@ -0,0 +1,19 @@ +var Sqrl = require('../dist/squirrelly.cjs') +var template = ` +{{~try}} +This won't work: {{it.hi | validate}} +{{#catch => err}} +Uh-oh, error! Message was '{{err}} '' +{{/try}} +` +Sqrl.Filters.define('validate', function (str) { + if (typeof str === 'undefined') { + throw Error("str doesn't fit expected format") + } +}) + +console.log(Sqrl.Parse(template, '{{', '}}')) +console.log('===========================') +console.log(Sqrl.Compile(template, '{{', '}}').toString()) +console.log('===========================') +console.log(Sqrl.Render(template, { riceKids: ['Ben', 'Polly', 'Joel', 'Phronsie', 'Davie'] })) diff --git a/rollup.config.ts b/rollup.config.ts index 01603686..077313ef 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -10,7 +10,7 @@ const pkg = require('./package.json') export default [ { - input: 'src/browser.ts', + input: 'src/index.ts', // todo: use rollup-plugin-replace output: [ { file: 'dist/browser/squirrelly.dev.js', diff --git a/src/browser.ts b/src/browser.ts deleted file mode 100644 index 63a93833..00000000 --- a/src/browser.ts +++ /dev/null @@ -1,18 +0,0 @@ -// Import here Polyfills if needed. Recommended core-js (npm i -D core-js) -// import "core-js/fn/array.find" -// ... -export { default as CompileToString, ParseScope, ParseScopeIntoFunction } from './compile-string' -export { default as Compile } from './compile' -export { default as Parse } from './parse' -export { default as Render } from './render' -export { - Helpers as H, - NativeHelpers as NH, - Filters as F, - Partials as P, - Layouts as L -} from './containers' -export { Config } from './config' - -// TODO: Allow for configuring different Squirrelly environments -// Don't require it like Nunjucks though. Keep it simple diff --git a/src/compile-string.ts b/src/compile-string.ts index e0f64615..5c219be5 100644 --- a/src/compile-string.ts +++ b/src/compile-string.ts @@ -1,11 +1,12 @@ import Parse, { AstObject, Filter, TemplateObject } from './parse' import { NativeHelpers } from './containers' +import { SqrlConfig } from './config' -function CompileToString (str: string, tagOpen: string, tagClose: string) { - var buffer: Array = Parse(str, tagOpen, tagClose) +function CompileToString (str: string, tagOpen: string, tagClose: string, env: SqrlConfig) { + var buffer: Array = Parse(str, tagOpen, tagClose, env) return ( "var tR='';" + - ParseScope(buffer) + ParseScope(buffer, env) .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') + 'return tR' @@ -16,8 +17,14 @@ function CompileToString (str: string, tagOpen: string, tagClose: string) { // TODO: Use type intersections for TemplateObject, etc. // so I don't have to make properties mandatory -function parseHelper (res: string, descendants: Array, params: string, name?: string) { - var ret = '{exec:' + ParseScopeIntoFunction(descendants, res) + ',params:[' + params + ']' +function parseHelper ( + env: SqrlConfig, + res: string, + descendants: Array, + params: string, + name?: string +) { + var ret = '{exec:' + ParseScopeIntoFunction(descendants, res, env) + ',params:[' + params + ']' if (name) { ret += ",name:'" + name + "'" } @@ -25,11 +32,11 @@ function parseHelper (res: string, descendants: Array, params: string return ret } -function parseBlocks (blocks: Array) { +function parseBlocks (blocks: Array, env: SqrlConfig) { var ret = '[' for (var i = 0; i < blocks.length; i++) { var block = blocks[i] - ret += parseHelper(block.res || '', block.d || [], block.p || '', block.n || '') + ret += parseHelper(env, block.res || '', block.d || [], block.p || '', block.n || '') if (i < blocks.length) { ret += ',' } @@ -38,11 +45,11 @@ function parseBlocks (blocks: Array) { return ret } -export function ParseScopeIntoFunction (buff: Array, res: string) { - return 'function(' + res + "){var tR='';" + ParseScope(buff) + 'return tR}' +export function ParseScopeIntoFunction (buff: Array, res: string, env: SqrlConfig) { + return 'function(' + res + "){var tR='';" + ParseScope(buff, env) + 'return tR}' } -export function ParseScope (buff: Array) { +export function ParseScope (buff: Array, env: SqrlConfig) { var i = 0 var buffLength = buff.length var returnStr = '' @@ -72,12 +79,12 @@ export function ParseScope (buff: Array) { // helper // TODO: native helpers if (NativeHelpers.get(name)) { - returnStr += NativeHelpers.get(name)(currentBlock) + returnStr += NativeHelpers.get(name)(currentBlock, env) } else { var helperReturn = - "Sqrl.H.get('" + name + "')(" + parseHelper(res, currentBlock.d, params) + "Sqrl.H.get('" + name + "')(" + parseHelper(env, res, currentBlock.d, params) if (blocks) { - helperReturn += ',' + parseBlocks(blocks) + helperReturn += ',' + parseBlocks(blocks, env) } helperReturn += ')' diff --git a/src/compile.ts b/src/compile.ts index dafba34f..8440dc33 100644 --- a/src/compile.ts +++ b/src/compile.ts @@ -1,7 +1,9 @@ import CompileToString from './compile-string' +import { Env } from './config' -function Compile (str: string, tagOpen: string, tagClose: string) { - return new Function('it', 'Sqrl', CompileToString(str, tagOpen, tagClose)) // eslint-disable-line no-new-func +function Compile (str: string, tagOpen: string, tagClose: string, envName: string) { + var SqrlEnv = Env.get(envName || 'default') + return new Function(SqrlEnv.varName, 'Sqrl', CompileToString(str, tagOpen, tagClose, SqrlEnv)) // eslint-disable-line no-new-func } export default Compile diff --git a/src/config.ts b/src/config.ts index 9d409f91..2b3793a8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,23 +1,64 @@ -interface SqrlConfiguration { +interface Dict { + [key: string]: SqrlConfig +} + +interface IEnv { + cache: Dict + define: (key: string, val: SqrlConfig) => void + get: (key: string) => SqrlConfig + remove: (key: string) => void + clear: () => void + load: (cacheObj: Dict) => void +} + +export interface SqrlConfig { varName: string autoTrim: boolean | 'nl' autoEscape: boolean + defaultFilter: false | Function [index: string]: any } -var Conf: SqrlConfiguration = { +type PartialConfig = { + [P in keyof SqrlConfig]?: SqrlConfig[P] +} + +var defaultConfig: SqrlConfig = { varName: 'it', autoTrim: false, - autoEscape: true + autoEscape: true, + defaultFilter: false } -function Config (key: string, val: any): void { - Conf[key] = val +var Env: IEnv = { + cache: { + default: defaultConfig + }, + define: function (key: string, newConfig: PartialConfig) { + if (!this.cache[key]) { + this.cache[key] = defaultConfig + } + for (var attrname in newConfig) { + this.cache[key][attrname] = newConfig[attrname] + } + }, + get: function (key: string) { + // string | array. + // TODO: allow array of keys to look down + return this.cache[key] + }, + remove: function (key: string) { + delete this.cache[key] + }, + clear: function () { + this.cache = {} + }, + load: function (cacheObj: Dict) { + this.cache = cacheObj + } } -// TODO: Fix types for this - -export { Conf, Config } +export { Env } // Have different envs. Sqrl.Render, Compile, etc. all use default env // Use class for env diff --git a/src/containers.ts b/src/containers.ts index fad9fa94..f7ae1601 100644 --- a/src/containers.ts +++ b/src/containers.ts @@ -2,6 +2,7 @@ import { Cacher } from './storage' import { AstObject, Filter, TemplateObject } from './parse' import SqrlErr from './err' import { ParseScope } from './compile-string' +import { SqrlConfig } from './config' type TemplateFunction = (options: object, Sqrl: object) => string @@ -45,27 +46,75 @@ var Helpers = new Cacher({ }) var NativeHelpers = new Cacher({ - if: function (buffer: TemplateObject) { + if: function (buffer: TemplateObject, env: SqrlConfig) { if (buffer.f && buffer.f.length) { throw SqrlErr("native helper 'if' can't have filters") } - var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d) + '}' + var returnStr = 'if(' + buffer.p + '){' + ParseScope(buffer.d, env) + '}' if (buffer.b) { for (var i = 0; i < buffer.b.length; i++) { var currentBlock = buffer.b[i] if (currentBlock.n === 'else') { - returnStr += 'else{' + ParseScope(currentBlock.d) + '}' + returnStr += 'else{' + ParseScope(currentBlock.d, env) + '}' } else if (currentBlock.n === 'elif') { - returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d) + '}' + returnStr += 'else if(' + currentBlock.p + '){' + ParseScope(currentBlock.d, env) + '}' } } } return returnStr + }, + try: function (buffer: TemplateObject, env: SqrlConfig) { + if (buffer.f && buffer.f.length) { + throw SqrlErr("native helper 'try' can't have filters") + } + if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') { + throw SqrlErr("native helper 'try' only accepts 1 block, 'catch'") + } + var returnStr = 'try{' + ParseScope(buffer.d, env) + '}' + + var currentBlock = buffer.b[0] + returnStr += + 'catch' + + (currentBlock.res ? '(' + currentBlock.res + ')' : '') + + '{' + + ParseScope(currentBlock.d, env) + + '}' + + return returnStr } }) type FilterFunction = (str: string) => string -var Filters = new Cacher({}) +interface EscapeMap { + '&': '&' + '<': '<' + '"': '"' + "'": ''' + [index: string]: string +} + +var escMap: EscapeMap = { + '&': '&', + '<': '<', + '"': '"', + "'": ''' +} + +function replaceChar (s: string): string { + return escMap[s] +} + +function XMLEscape (str: any) { + // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized. + var newStr = String(str) + if (/[&<"']/.test(newStr)) { + return newStr.replace(/[&<"']/g, replaceChar) + } else { + return newStr + } +} + +var Filters = new Cacher({ e: XMLEscape }) export { Templates, Layouts, Partials, Helpers, NativeHelpers, Filters } diff --git a/src/index.ts b/src/index.ts index 63a93833..a711c290 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,14 +5,8 @@ export { default as CompileToString, ParseScope, ParseScopeIntoFunction } from ' export { default as Compile } from './compile' export { default as Parse } from './parse' export { default as Render } from './render' -export { - Helpers as H, - NativeHelpers as NH, - Filters as F, - Partials as P, - Layouts as L -} from './containers' -export { Config } from './config' +export { Helpers, NativeHelpers, Filters, Partials, Layouts } from './containers' +export { Env } from './config' // TODO: Allow for configuring different Squirrelly environments // Don't require it like Nunjucks though. Keep it simple diff --git a/src/parse.ts b/src/parse.ts index 0d4b67bc..43ab3f02 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -1,6 +1,7 @@ // Version 1.0.32 import { ParseErr } from './err' import { trimLeft, trimRight } from './utils' +import { SqrlConfig } from './config' export type TagType = '~' | '/' | '#' | '?' | 'r' | '!' | 's' export type TemplateAttribute = 'c' | 'f' | 'fp' | 'p' | 'n' | 'res' | 'err' @@ -21,7 +22,12 @@ export interface TemplateObject { b?: Array } -export default function Parse (str: string, tagOpen: string, tagClose: string): Array { +export default function Parse ( + str: string, + tagOpen: string, + tagClose: string, + env: SqrlConfig +): Array { var powerchars = new RegExp( '([|()]|=>)|' + '\'(?:\\\\[\\s\\w"\'\\\\`]|[^\\n\\r\'\\\\])*?\'|`(?:\\\\[\\s\\w"\'\\\\`]|[^\\\\`])*?`|"(?:\\\\[\\s\\w"\'\\\\`]|[^\\n\\r"\\\\])*?"' + // matches strings diff --git a/src/render.ts b/src/render.ts index 84e6ca09..8b075c99 100644 --- a/src/render.ts +++ b/src/render.ts @@ -1,10 +1,27 @@ import Compile from './compile' import { Helpers, Filters } from './containers' -function Render (template: string, options: object): string { - var templateFunc = Compile(template, '{{', '}}') - return templateFunc(options, { H: Helpers, F: Filters }) +type TemplateFunction = (data: object, Sqrl: object) => string +type DetermineEnvFunction = (options?: object) => string + +function Render ( + template: string | TemplateFunction, + data: object, + env?: string | DetermineEnvFunction, + options?: object +) { + if (!env) { + env = 'default' + } else if (typeof env === 'function') { + env = env(options) // this can be used to dynamically pick an env based on name, etc. + } + + if (typeof template === 'function') { + return template(data, { H: Helpers, F: Filters }) + } + // else + var templateFunc = Compile(template, '{{', '}}', env) + return templateFunc(data, { H: Helpers, F: Filters }) } export default Render -export type TemplateFunction = (options: object, Sqrl: object) => string diff --git a/src/storage.ts b/src/storage.ts index 238bd799..d06fa90b 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -13,6 +13,7 @@ class Cacher { get (key: string) { // string | array. // TODO: allow array of keys to look down + // TODO: create plugin to allow referencing helpers, filters with dot notation return this.cache[key] } remove (key: string) { diff --git a/src/utils.ts b/src/utils.ts index 2e8683f3..009baf08 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -53,33 +53,4 @@ function trimRight (str: string, type: string): string { } } -interface EscapeMap { - '&': '&' - '<': '<' - '"': '"' - "'": ''' - [index: string]: string -} - -var escMap: EscapeMap = { - '&': '&', - '<': '<', - '"': '"', - "'": ''' -} - -function replaceChar (s: string): string { - return escMap[s] -} - -function XMLEscape (str: any) { - // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized. - var newStr = String(str) - if (/[&<"']/.test(newStr)) { - return newStr.replace(/[&<"']/g, replaceChar) - } else { - return newStr - } -} - -export { trimLeft, trimRight, XMLEscape } +export { trimLeft, trimRight }