From 53beb48e491b6efa9d2a5deae283bfc55460db5c Mon Sep 17 00:00:00 2001 From: Ben Gubler Date: Fri, 26 May 2023 23:55:08 -0600 Subject: [PATCH] chore: rebuild --- deno_dist/compile.ts | 6 ++---- deno_dist/file-handling.ts | 9 +++++---- deno_dist/render.ts | 32 ++++++++++++++------------------ deno_dist/utils.ts | 3 +-- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/deno_dist/compile.ts b/deno_dist/compile.ts index 15d1f0d..c4550a2 100644 --- a/deno_dist/compile.ts +++ b/deno_dist/compile.ts @@ -25,8 +25,6 @@ export function compile( str: string, options?: Partial, ): TemplateFunction { - const Eta = this; - const config: EtaConfig = this.config; /* ASYNC HANDLING (modified from mde/ejs) */ @@ -39,7 +37,7 @@ export function compile( return new ctor( config.varName, "options", - this.compileToString.call(Eta, str, options), + this.compileToString.call(this, str, options), ) as TemplateFunction; // eslint-disable-line no-new-func } catch (e) { if (e instanceof SyntaxError) { @@ -49,7 +47,7 @@ export function compile( "\n" + Array(e.message.length + 1).join("=") + "\n" + - this.compileToString.call(Eta, str, options) + + this.compileToString.call(this, str, options) + "\n", // This will put an extra newline before the callstack for extra readability ); } else { diff --git a/deno_dist/file-handling.ts b/deno_dist/file-handling.ts index ce335bd..078e5d2 100644 --- a/deno_dist/file-handling.ts +++ b/deno_dist/file-handling.ts @@ -14,6 +14,7 @@ export function readFile(this: EtaCore, path: string): string { try { res = fs.readFileSync(path, "utf8"); + // eslint-disable-line @typescript-eslint/no-explicit-any } catch (err: any) { if (err?.code === "ENOENT") { throw new EtaError(`Could not find template: ${path}`); @@ -34,13 +35,13 @@ export function resolvePath( template += path.extname(template) ? "" : ".eta"; - let views = this.config.views; + const views = this.config.views; if (!views) { throw new EtaError("Views directory is not defined"); } - let baseFilePath = options && options.filepath; + const baseFilePath = options && options.filepath; // if the file was included from another template if (baseFilePath) { @@ -49,7 +50,7 @@ export function resolvePath( return this.config.filepathCache[baseFilePath]; } - let absolutePathTest = absolutePathRegExp.exec(template); + const absolutePathTest = absolutePathRegExp.exec(template); if (absolutePathTest && absolutePathTest.length) { const formattedPath = template.replace(/^\/*/, ""); @@ -78,4 +79,4 @@ function dirIsChild(parent: string, dir: string) { return relative && !relative.startsWith("..") && !path.isAbsolute(relative); } -let absolutePathRegExp = /^\\|^\//; +const absolutePathRegExp = /^\\|^\//; diff --git a/deno_dist/render.ts b/deno_dist/render.ts index 6146ce2..f72f44b 100644 --- a/deno_dist/render.ts +++ b/deno_dist/render.ts @@ -11,28 +11,28 @@ function handleCache( template: string, options: Partial, ): TemplateFunction { - let templateStore = options && options.async + const templateStore = options && options.async ? this.templatesAsync : this.templatesSync; if (this.resolvePath && this.readFile && !template.startsWith("@")) { - let templatePath = options.filepath as string; + const templatePath = options.filepath as string; - let cachedTemplate = templateStore.get(templatePath); + const cachedTemplate = templateStore.get(templatePath); if (this.config.cache && cachedTemplate) { return cachedTemplate; } else { - let templateString = this.readFile(templatePath); + const templateString = this.readFile(templatePath); - let templateFn = this.compile(templateString, options); + const templateFn = this.compile(templateString, options); if (this.config.cache) templateStore.define(templatePath, templateFn); return templateFn; } } else { - let cachedTemplate = templateStore.get(template); + const cachedTemplate = templateStore.get(template); if (cachedTemplate) { return cachedTemplate; @@ -48,22 +48,20 @@ export function render( data: object, meta?: { filepath: string }, ): string { - let Eta = this; - let templateFn: TemplateFunction; - let options = { ...meta, async: false }; + const options = { ...meta, async: false }; if (typeof template === "string") { if (this.resolvePath && this.readFile && !template.startsWith("@")) { options.filepath = this.resolvePath(template, options); } - templateFn = handleCache.call(Eta, template, options); + templateFn = handleCache.call(this, template, options); } else { templateFn = template; } - let res = templateFn.call(Eta, data, options); + const res = templateFn.call(this, data, options); return res; } @@ -74,22 +72,20 @@ export function renderAsync( data: object, meta?: { filepath: string }, ): Promise { - let Eta = this; - let templateFn: TemplateFunction; - let options = { ...meta, async: true }; + const options = { ...meta, async: true }; if (typeof template === "string") { if (this.resolvePath && this.readFile && !template.startsWith("@")) { options.filepath = this.resolvePath(template, options); } - templateFn = handleCache.call(Eta, template, options); + templateFn = handleCache.call(this, template, options); } else { templateFn = template; } - let res = templateFn.call(Eta, data, options); + const res = templateFn.call(this, data, options); // Return a promise return new Promise(function (resolve: Function, reject: Function) { @@ -106,7 +102,7 @@ export function renderString( template: string, data: object, ): string { - let templateFn = this.compile(template, { async: false }); + const templateFn = this.compile(template, { async: false }); return render.call(this, templateFn, data); } @@ -116,7 +112,7 @@ export function renderStringAsync( template: string, data: object, ): Promise { - let templateFn = this.compile(template, { async: true }); + const templateFn = this.compile(template, { async: true }); return renderAsync.call(this, templateFn, data); } diff --git a/deno_dist/utils.ts b/deno_dist/utils.ts index bccdd0b..1001821 100644 --- a/deno_dist/utils.ts +++ b/deno_dist/utils.ts @@ -80,8 +80,7 @@ function replaceChar(s: string): string { * @returns XML-escaped string */ -export function XMLEscape(str: any): string { - // eslint-disable-line @typescript-eslint/no-explicit-any +export function XMLEscape(str: unknown): string { // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized. const newStr = String(str); if (/[&<>"']/.test(newStr)) {