1 line
35 KiB
Plaintext
1 line
35 KiB
Plaintext
|
{"version":3,"file":"browser.module.mjs","sources":["../src/storage.ts","../src/err.ts","../src/compile.ts","../src/compile-string.ts","../src/utils.ts","../src/config.ts","../src/parse.ts","../src/render.ts","../src/core.ts","../src/browser.ts"],"sourcesContent":["/**\n * Handles storage and accessing of values\n *\n * In this case, we use it to store compiled template functions\n * Indexed by their `name` or `filename`\n */\n\nexport class Cacher<T> {\n constructor(private cache: Record<string, T>) {}\n define(key: string, val: T): void {\n this.cache[key] = val;\n }\n get(key: string): T {\n return this.cache[key];\n }\n remove(key: string): void {\n delete this.cache[key];\n }\n reset(): void {\n this.cache = {};\n }\n load(cacheObj: Record<string, T>): void {\n this.cache = { ...this.cache, ...cacheObj };\n }\n}\n","export class EtaError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"Eta Error\";\n }\n}\n\nexport class EtaParseError extends EtaError {\n constructor(message: string) {\n super(message);\n this.name = \"EtaParser Error\";\n }\n}\n\nexport class EtaRuntimeError extends EtaError {\n constructor(message: string) {\n super(message);\n this.name = \"EtaRuntime Error\";\n }\n}\n\nexport class EtaFileResolutionError extends EtaError {\n constructor(message: string) {\n super(message);\n this.name = \"EtaFileResolution Error\";\n }\n}\n\nexport class EtaNameResolutionError extends EtaError {\n constructor(message: string) {\n super(message);\n this.name = \"EtaNameResolution Error\";\n }\n}\n\n/**\n * Throws an EtaError with a nicely formatted error and message showing where in the template the error occurred.\n */\n\nexport function ParseErr(message: string, str: string, indx: number): never {\n const whitespace = str.slice(0, indx).split(/\\n/);\n\n const lineNo = whitespace.length;\n const colNo = whitespace[lineNo - 1].length + 1;\n message += \" 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 new EtaParseError(message);\n}\n\nexport function RuntimeErr(\n originalError: Error,\n str: string,\n lineNo: number,\n path: string,\n): never {\n // code gratefully taken from https://github.com/mde/ejs and adapted\n\n const lines = str.split(\"\\n\");\n const start = Math.max(lineNo - 3, 0);\n const end = Math.min(lines.length, lineNo + 3);\n const filename = path;\n // Error context\n const context = lines\n .slice(start, end)\n .map(function (line, i) {\n const curr = i + start + 1;\n return (curr == lineNo ? \" >> \" : \" \") + curr + \"| \" + line;\n })\n .join(\"\\n\");\n\n const header = filename\n ? filename + \":\" + lineNo + \"\\n\"\n : \"line \" + lineNo + \"\\n\";\n\n const err = new EtaRuntimeError(\n header + context + \"\\n\\n\" + originalError.message,\n );\n\n err.name = originalError.name; // the original name (e.g. ReferenceError) may be useful\n\n throw err;\n}\n","import { EtaParseError } from \"./err.ts\";\n\n/* TYPES */\nimport type { Eta } from \"./core.ts\";\nimport type { EtaConfig, Options } from \"./config.ts\";\n\nexport type TemplateFunction = (\n this: Eta,\n data?: object,\n options?: Partial<Options>,\n) => string;\n/* END TYPES */\n\n/* istanbul ignore next */\nconst AsyncFunction = async function () {}.constructor; // eslint-disable-line @typescript-eslint/no-empty-function\n\n/**\n * Takes a template string and returns a template function that can be called with (data, config)\n *\n * @param str - The template string\n * @param config - A custom configuration object (optional)\n */\n\nexport function compile(\n this: Eta,\n str: string,\n options?: Partial<Options>,\n): TemplateFunction {\n const config: EtaConfig = this.config;\n\n /* ASYNC HANDLING */\n // code gratefully taken from https://github.com/mde/ejs and adapted\n const ctor = options && options.a
|