diff --git a/src/compile-string.ts b/src/compile-string.ts index 83cc8fc..2ab2e3b 100644 --- a/src/compile-string.ts +++ b/src/compile-string.ts @@ -19,7 +19,7 @@ import type { AstObject } from './parse' */ export default function compileToString(str: string, config: EtaConfig): string { - var buffer: Array = Parse(str, config) + const buffer: Array = Parse(str, config) var res = "var tR='',__l,__lP" + @@ -42,7 +42,7 @@ export default function compileToString(str: string, config: EtaConfig): string if (config.plugins) { for (var i = 0; i < config.plugins.length; i++) { - var plugin = config.plugins[i] + const plugin = config.plugins[i] if (plugin.processFnString) { res = plugin.processFnString(res, config) } @@ -67,18 +67,18 @@ export default function compileToString(str: string, config: EtaConfig): string function compileScope(buff: Array, config: EtaConfig) { var i = 0 - var buffLength = buff.length + const buffLength = buff.length var returnStr = '' for (i; i < buffLength; i++) { - var currentBlock = buff[i] + const currentBlock = buff[i] if (typeof currentBlock === 'string') { - var str = currentBlock + const str = currentBlock // we know string exists returnStr += "tR+='" + str + "'\n" } else { - var type = currentBlock.t // ~, s, !, ?, r + const type = currentBlock.t // ~, s, !, ?, r var content = currentBlock.val || '' if (type === 'r') { diff --git a/src/compile.ts b/src/compile.ts index c9442c4..234ce8f 100644 --- a/src/compile.ts +++ b/src/compile.ts @@ -28,7 +28,7 @@ export type TemplateFunction = (data: object, config: EtaConfig, cb?: CallbackFn */ export default function compile(str: string, config?: PartialConfig): TemplateFunction { - var options: EtaConfig = getConfig(config || {}) + const options: EtaConfig = getConfig(config || {}) var ctor // constructor /* ASYNC HANDLING */ diff --git a/src/config.ts b/src/config.ts index adc225a..563c36c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -100,7 +100,7 @@ export type PartialConfig = Partial */ function includeHelper(this: EtaConfig, templateNameOrPath: string, data: object): string { - var template = this.templates.get(templateNameOrPath) + const template = this.templates.get(templateNameOrPath) if (!template) { throw EtaErr('Could not fetch template "' + templateNameOrPath + '"') } @@ -108,7 +108,7 @@ function includeHelper(this: EtaConfig, templateNameOrPath: string, data: object } /** Eta's base (global) configuration */ -var config: EtaConfig = { +const config: EtaConfig = { async: false, autoEscape: true, autoTrim: [false, 'nl'], @@ -144,7 +144,7 @@ var config: EtaConfig = { function getConfig(override: PartialConfig, baseConfig?: EtaConfig): EtaConfig { // TODO: run more tests on this - var res: PartialConfig = {} // Linked + const res: PartialConfig = {} // Linked copyProps(res, config) // Creates deep clone of eta.config, 1 layer deep if (baseConfig) { diff --git a/src/containers.ts b/src/containers.ts index dc13616..6357c05 100644 --- a/src/containers.ts +++ b/src/containers.ts @@ -12,6 +12,6 @@ import type { TemplateFunction } from './compile' * Stores partials and cached templates */ -var templates = new Cacher({}) +const templates = new Cacher({}) export { templates } diff --git a/src/err.ts b/src/err.ts index 6e5930b..b4e8fdd 100755 --- a/src/err.ts +++ b/src/err.ts @@ -23,7 +23,7 @@ function setPrototypeOf(obj: any, proto: any) { */ export default function EtaErr(message: string): Error { - var err = new Error(message) + const err = new Error(message) setPrototypeOf(err, EtaErr.prototype) return err } @@ -37,10 +37,10 @@ EtaErr.prototype = Object.create(Error.prototype, { */ export function ParseErr(message: string, str: string, indx: number): void { - var whitespace = str.slice(0, indx).split(/\n/) + const whitespace = str.slice(0, indx).split(/\n/) - var lineNo = whitespace.length - var colNo = whitespace[lineNo - 1].length + 1 + const lineNo = whitespace.length + const colNo = whitespace[lineNo - 1].length + 1 message += ' at line ' + lineNo + diff --git a/src/file-handlers.ts b/src/file-handlers.ts index 3fa4b47..751d97c 100644 --- a/src/file-handlers.ts +++ b/src/file-handlers.ts @@ -41,10 +41,10 @@ export function loadFile( options: PartialConfigWithFilename, noCache?: boolean ): TemplateFunction { - var config = getConfig(options) - var template = readFile(filePath) + const config = getConfig(options) + const template = readFile(filePath) try { - var compiledTemplate = compile(template, config) + const compiledTemplate = compile(template, config) if (!noCache) { config.templates.define((config as EtaConfigWithFilename).filename, compiledTemplate) } @@ -66,10 +66,10 @@ export function loadFile( */ function handleCache(options: EtaConfigWithFilename): TemplateFunction { - var filename = options.filename + const filename = options.filename if (options.cache) { - var func = options.templates.get(filename) + const func = options.templates.get(filename) if (func) { return func } @@ -96,7 +96,7 @@ function tryHandleCache(data: object, options: EtaConfigWithFilename, cb: Callba try { // Note: if there is an error while rendering the template, // It will bubble up and be caught here - var templateFn = handleCache(options) + const templateFn = handleCache(options) templateFn(data, options, cb) } catch (err) { return cb(err) @@ -106,8 +106,8 @@ function tryHandleCache(data: object, options: EtaConfigWithFilename, cb: Callba if (typeof promiseImpl === 'function') { return new promiseImpl(function (resolve: Function, reject: Function) { try { - var templateFn = handleCache(options) - var result = templateFn(data, options) + const templateFn = handleCache(options) + const result = templateFn(data, options) resolve(result) } catch (err) { reject(err) @@ -138,7 +138,7 @@ function tryHandleCache(data: object, options: EtaConfigWithFilename, cb: Callba function includeFile(path: string, options: EtaConfig): [TemplateFunction, EtaConfig] { // the below creates a new options object, using the parent filepath of the old options object and the path - var newFileOptions = getConfig({ filename: getPath(path, options) }, options) + const newFileOptions = getConfig({ filename: getPath(path, options) }, options) // TODO: make sure properties are currectly copied over return [handleCache(newFileOptions as EtaConfigWithFilename), newFileOptions] } @@ -226,7 +226,7 @@ function renderFile( } // Undocumented after Express 2, but still usable, esp. for // items that are unsafe to be passed along with data, like `root` - var viewOpts = data.settings['view options'] + const viewOpts = data.settings['view options'] if (viewOpts) { copyProps(renderConfig, viewOpts) diff --git a/src/file-helpers.ts b/src/file-helpers.ts index 488aaab..b8a717d 100644 --- a/src/file-helpers.ts +++ b/src/file-helpers.ts @@ -15,6 +15,6 @@ interface GenericData { */ export function includeFileHelper(this: EtaConfig, path: string, data: GenericData): string { - var templateAndConfig = includeFile(path, this) + const templateAndConfig = includeFile(path, this) return templateAndConfig[0](data, templateAndConfig[1]) } diff --git a/src/file-methods.deno.ts b/src/file-methods.deno.ts index f2cce45..f6b9edc 100644 --- a/src/file-methods.deno.ts +++ b/src/file-methods.deno.ts @@ -1,4 +1,4 @@ export * as fs from "https://deno.land/std@0.66.0/fs/mod.ts" export * as path from "https://deno.land/std@0.66.0/path/mod.ts" -export var readFileSync = Deno.readTextFileSync +export const readFileSync = Deno.readTextFileSync diff --git a/src/file-utils.ts b/src/file-utils.ts index 90ae4f0..2b55646 100644 --- a/src/file-utils.ts +++ b/src/file-utils.ts @@ -1,5 +1,5 @@ import { fs, path, readFileSync } from './file-methods' -var _BOM = /^\uFEFF/ +const _BOM = /^\uFEFF/ // express is set like: app.engine('html', require('eta').renderFile) @@ -28,7 +28,7 @@ function getWholeFilePath(name: string, parentfile: string, isDirectory?: boolea isDirectory ? parentfile : path.dirname(parentfile), // returns directory the parent file is in name // file ) - var ext = path.extname(name) + const ext = path.extname(name) if (!ext) { includePath += '.eta' } @@ -55,14 +55,14 @@ function getWholeFilePath(name: string, parentfile: string, isDirectory?: boolea function getPath(path: string, options: EtaConfig): string { var includePath: string | false = false - var views = options.views + const views = options.views var searchedPaths: Array = [] // If these four values are the same, // getPath() will return the same result every time. // We can cache the result to avoid expensive // file operations. - var pathOptions = JSON.stringify({ + const pathOptions = JSON.stringify({ filename: options.filename, // filename of the template which called includeFile() path: path, root: options.root, @@ -123,20 +123,20 @@ function getPath(path: string, options: EtaConfig): string { } // Path starts with '/', 'C:\', etc. - var match = /^[A-Za-z]+:\\|^\//.exec(path) + const match = /^[A-Za-z]+:\\|^\//.exec(path) // Absolute path, like /partials/partial.eta if (match && match.length) { // We have to trim the beginning '/' off the path, or else // path.resolve(dir, path) will always resolve to just path - var formattedPath = path.replace(/^\/*/, '') + const formattedPath = path.replace(/^\/*/, '') // First, try to resolve the path within options.views includePath = searchViews(views, formattedPath) if (!includePath) { // If that fails, searchViews will return false. Try to find the path // inside options.root (by default '/', the base of the filesystem) - var pathFromRoot = getWholeFilePath(formattedPath, options.root || '/', true) + const pathFromRoot = getWholeFilePath(formattedPath, options.root || '/', true) addPathToSearched(pathFromRoot) @@ -146,7 +146,7 @@ function getPath(path: string, options: EtaConfig): string { // Relative paths // Look relative to a passed filename first if (options.filename) { - var filePath = getWholeFilePath(path, options.filename) + const filePath = getWholeFilePath(path, options.filename) addPathToSearched(filePath) diff --git a/src/parse.ts b/src/parse.ts index df2d1df..20e2bbf 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -16,11 +16,11 @@ export type AstObject = string | TemplateObject /* END TYPES */ -var templateLitReg = /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})*}|(?!\${)[^\\`])*`/g +const templateLitReg = /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})*}|(?!\${)[^\\`])*`/g -var singleQuoteReg = /'(?:\\[\s\w"'\\`]|[^\n\r'\\])*?'/g +const singleQuoteReg = /'(?:\\[\s\w"'\\`]|[^\n\r'\\])*?'/g -var doubleQuoteReg = /"(?:\\[\s\w"'\\`]|[^\n\r"\\])*?"/g +const doubleQuoteReg = /"(?:\\[\s\w"'\\`]|[^\n\r"\\])*?"/g /** Escape special regular expression characters inside a string */ @@ -33,11 +33,11 @@ export default function parse(str: string, config: EtaConfig): Array var buffer: Array = [] var trimLeftOfNextStr: string | false = false var lastIndex = 0 - var parseOptions = config.parse + const parseOptions = config.parse if (config.plugins) { for (var i = 0; i < config.plugins.length; i++) { - var plugin = config.plugins[i] + const plugin = config.plugins[i] if (plugin.processTemplate) { str = plugin.processTemplate(str, config) } @@ -81,7 +81,7 @@ export default function parse(str: string, config: EtaConfig): Array } } - var prefixes = [parseOptions.exec, parseOptions.interpolate, parseOptions.raw].reduce(function ( + const prefixes = [parseOptions.exec, parseOptions.interpolate, parseOptions.raw].reduce(function ( accumulator, prefix ) { @@ -97,12 +97,12 @@ export default function parse(str: string, config: EtaConfig): Array }, '') - var parseOpenReg = new RegExp( + const parseOpenReg = new RegExp( '([^]*?)' + escapeRegExp(config.tags[0]) + '(-|_)?\\s*(' + prefixes + ')?\\s*', 'g' ) - var parseCloseReg = new RegExp( + const parseCloseReg = new RegExp( '\'|"|`|\\/\\*|(\\s*(-|_)?' + escapeRegExp(config.tags[1]) + ')', 'g' ) @@ -113,9 +113,9 @@ export default function parse(str: string, config: EtaConfig): Array while ((m = parseOpenReg.exec(str))) { lastIndex = m[0].length + m.index - var precedingString = m[1] - var wsLeft = m[2] - var prefix = m[3] || '' // by default either ~, =, or empty + const precedingString = m[1] + const wsLeft = m[2] + const prefix = m[3] || '' // by default either ~, =, or empty pushString(precedingString, wsLeft) @@ -143,9 +143,9 @@ export default function parse(str: string, config: EtaConfig): Array currentObj = { t: currentType, val: content } break } else { - var char = closeTag[0] + const char = closeTag[0] if (char === '/*') { - var commentCloseInd = str.indexOf('*/', parseCloseReg.lastIndex) + const commentCloseInd = str.indexOf('*/', parseCloseReg.lastIndex) if (commentCloseInd === -1) { ParseErr('unclosed comment', str, closeTag.index) @@ -154,7 +154,7 @@ export default function parse(str: string, config: EtaConfig): Array } else if (char === "'") { singleQuoteReg.lastIndex = closeTag.index - var singleQuoteMatch = singleQuoteReg.exec(str) + const singleQuoteMatch = singleQuoteReg.exec(str) if (singleQuoteMatch) { parseCloseReg.lastIndex = singleQuoteReg.lastIndex } else { @@ -162,7 +162,7 @@ export default function parse(str: string, config: EtaConfig): Array } } else if (char === '"') { doubleQuoteReg.lastIndex = closeTag.index - var doubleQuoteMatch = doubleQuoteReg.exec(str) + const doubleQuoteMatch = doubleQuoteReg.exec(str) if (doubleQuoteMatch) { parseCloseReg.lastIndex = doubleQuoteReg.lastIndex @@ -171,7 +171,7 @@ export default function parse(str: string, config: EtaConfig): Array } } else if (char === '`') { templateLitReg.lastIndex = closeTag.index - var templateLitMatch = templateLitReg.exec(str) + const templateLitMatch = templateLitReg.exec(str) if (templateLitMatch) { parseCloseReg.lastIndex = templateLitReg.lastIndex } else { @@ -191,7 +191,7 @@ export default function parse(str: string, config: EtaConfig): Array if (config.plugins) { for (var i = 0; i < config.plugins.length; i++) { - var plugin = config.plugins[i] + const plugin = config.plugins[i] if (plugin.processAST) { buffer = plugin.processAST(buffer, config) } diff --git a/src/polyfills.deno.ts b/src/polyfills.deno.ts index 333fea8..88e9884 100644 --- a/src/polyfills.deno.ts +++ b/src/polyfills.deno.ts @@ -1,4 +1,4 @@ -export var promiseImpl = Promise +export const promiseImpl = Promise export function getAsyncFunctionConstructor (): Function { return async function () {}.constructor diff --git a/src/render.ts b/src/render.ts index e58363e..569b10b 100644 --- a/src/render.ts +++ b/src/render.ts @@ -58,7 +58,7 @@ export default function render( config?: PartialConfig, cb?: CallbackFn ): string | Promise | void { - var options = getConfig(config || {}) + const options = getConfig(config || {}) if (options.async) { var result @@ -67,7 +67,7 @@ export default function render( try { // Note: if there is an error while rendering the template, // It will bubble up and be caught here - var templateFn = handleCache(template, options) + const templateFn = handleCache(template, options) templateFn(data, options, cb) } catch (err) { return cb(err) diff --git a/src/utils.ts b/src/utils.ts index 19401d0..db66342 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -23,7 +23,7 @@ export function hasOwnProp(obj: object, prop: string): boolean { } export function copyProps(toObj: T, fromObj: T): T { - for (var key in fromObj) { + for (const key in fromObj) { if (hasOwnProp((fromObj as unknown) as object, key)) { toObj[key] = fromObj[key] } @@ -94,7 +94,7 @@ function trimWS( * A map of special HTML characters to their XML-escaped equivalents */ -var escMap: EscapeMap = { +const escMap: EscapeMap = { '&': '&', '<': '<', '>': '>', @@ -116,7 +116,7 @@ function replaceChar(s: string): string { function XMLEscape(str: any): string { // eslint-disable-line @typescript-eslint/no-explicit-any // To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized. - var newStr = String(str) + const newStr = String(str) if (/[&<>"']/.test(newStr)) { return newStr.replace(/[&<>"']/g, replaceChar) } else { diff --git a/test/compile.spec.ts b/test/compile.spec.ts index 9eb830c..eb2db6a 100644 --- a/test/compile.spec.ts +++ b/test/compile.spec.ts @@ -3,7 +3,7 @@ import { compile } from '../src/index' import { buildRegEx } from './err.spec' -var fs = require('fs'), +const fs = require('fs'), path = require('path'), filePath = path.join(__dirname, 'templates/complex.eta') @@ -11,18 +11,18 @@ const complexTemplate = fs.readFileSync(filePath, 'utf8') describe('Compile test', () => { it('parses a simple template', () => { - var str = compile('hi <%= hey %>') + const str = compile('hi <%= hey %>') expect(str).toBeTruthy() }) it('works with plain string templates', () => { - var str = compile('hi this is a template') + const str = compile('hi this is a template') expect(str).toBeTruthy() }) // TODO: Update it('compiles complex template', () => { - var str = compile(complexTemplate) + const str = compile(complexTemplate) expect(str).toBeTruthy() }) diff --git a/test/config.spec.ts b/test/config.spec.ts index 8a1c4eb..4cfb9ef 100644 --- a/test/config.spec.ts +++ b/test/config.spec.ts @@ -5,17 +5,17 @@ import { config, configure, getConfig } from '../src/config' describe('Config Tests', () => { it('Renders a simple template with default env', () => { - var res = render('hi <%= it.name %>', { name: 'Ben' }, defaultConfig) + const res = render('hi <%= it.name %>', { name: 'Ben' }, defaultConfig) expect(res).toEqual('hi Ben') }) it('Renders a simple template with custom tags', () => { - var res = render('hi <<= it.name >>', { name: 'Ben' }, { tags: ['<<', '>>'] }) + const res = render('hi <<= it.name >>', { name: 'Ben' }, { tags: ['<<', '>>'] }) expect(res).toEqual('hi Ben') }) it('Renders a simple template with stored env', () => { - var res = render('<%= it.html %>', { html: '

Hi

' }, { autoEscape: false }) + const res = render('<%= it.html %>', { html: '

Hi

' }, { autoEscape: false }) expect(res).toEqual('

Hi

') // not escaped }) @@ -57,9 +57,9 @@ describe('Config Tests', () => { }) it('Configure command works', () => { - var updatedConfig = configure({ tags: ['{{', '}}'] }) + const updatedConfig = configure({ tags: ['{{', '}}'] }) - var res = render('{{= it.name }}', { name: 'John Appleseed' }) + const res = render('{{= it.name }}', { name: 'John Appleseed' }) expect(res).toEqual('John Appleseed') expect(defaultConfig).toEqual(updatedConfig) diff --git a/test/deno/config.spec.ts b/test/deno/config.spec.ts index 9ad684b..cd7100f 100644 --- a/test/deno/config.spec.ts +++ b/test/deno/config.spec.ts @@ -2,19 +2,19 @@ import { assertEquals } from 'https://deno.land/std@0.67.0/testing/asserts.ts' import * as eta from '../../deno_dist/mod.ts' Deno.test('Renders a simple template with default env', () => { - var res = eta.render('hi <%= it.name %>', { name: 'Ben' }, eta.defaultConfig) + const res = eta.render('hi <%= it.name %>', { name: 'Ben' }, eta.defaultConfig) assertEquals(res, 'hi Ben') }) Deno.test('Renders a simple template with custom tags', () => { - var res = eta.render('hi <<= it.name >>', { name: 'Ben' }, { tags: ['<<', '>>'] }) + const res = eta.render('hi <<= it.name >>', { name: 'Ben' }, { tags: ['<<', '>>'] }) assertEquals(res, 'hi Ben') }) Deno.test('Renders a simple template without autoescaping', () => { - var res = eta.render('<%= it.html %>', { html: '

Hi

' }, { autoEscape: false }) + const res = eta.render('<%= it.html %>', { html: '

Hi

' }, { autoEscape: false }) assertEquals(res, '

Hi

') // not escaped }) diff --git a/test/deno/file-helpers.spec.ts b/test/deno/file-helpers.spec.ts index 9305cb0..8a97f8b 100644 --- a/test/deno/file-helpers.spec.ts +++ b/test/deno/file-helpers.spec.ts @@ -7,13 +7,13 @@ import { render, templates, compile } from '../../deno_dist/mod.ts' templates.define('test-template', compile('Saluton <%=it.name%>')) Deno.test('include works', async () => { - var renderedTemplate = render('<%~ include("test-template", it) %>', { name: 'Ada' }) + const renderedTemplate = render('<%~ include("test-template", it) %>', { name: 'Ada' }) assertEquals(renderedTemplate, 'Saluton Ada') }) Deno.test('includeFile works w/ filename prop', async () => { - var renderedTemplate = render( + const renderedTemplate = render( '<%~ includeFile("simple", it) %>', { name: 'Ada' }, { filename: path.join(__dirname, '../templates/placeholder.eta') } @@ -23,7 +23,7 @@ Deno.test('includeFile works w/ filename prop', async () => { }) Deno.test('"E.includeFile" works with "views" array', async () => { - var renderedTemplate = render( + const renderedTemplate = render( '<%~ E.includeFile("randomtemplate", it) %>', { user: 'Ben' }, { views: [path.join(__dirname, '../templates'), path.join(__dirname, '../othertemplates')] } @@ -33,7 +33,7 @@ Deno.test('"E.includeFile" works with "views" array', async () => { }) Deno.test('"includeFile" works with "views" array', async () => { - var renderedTemplate = render( + const renderedTemplate = render( '<%~ includeFile("randomtemplate", it) %>', { user: 'Ben' }, { views: [path.join(__dirname, '../templates'), path.join(__dirname, '../othertemplates')] } @@ -43,7 +43,7 @@ Deno.test('"includeFile" works with "views" array', async () => { }) Deno.test('"includeFile" works with "views" string', async () => { - var renderedTemplate = render( + const renderedTemplate = render( '<%~ includeFile("randomtemplate", it) %>', { user: 'Ben' }, { views: path.join(__dirname, '../othertemplates') } diff --git a/test/deno/helpers.spec.ts b/test/deno/helpers.spec.ts index 17b144b..d929822 100644 --- a/test/deno/helpers.spec.ts +++ b/test/deno/helpers.spec.ts @@ -3,7 +3,7 @@ import { render } from '../../deno_dist/mod.ts' // SHOULD TEST COMMON ETA USAGE PATTERNS HERE -var eachTemplate = ` +const eachTemplate = ` The Daugherty's have 5 kids:
    <% it.kids.forEach(function(kid){ %> @@ -12,7 +12,7 @@ The Daugherty's have 5 kids:
` Deno.test('Loop over an array', () => { - var res = render(eachTemplate, { kids: ['Ben', 'Polly', 'Joel', 'Phronsie', 'Davie'] }) + const res = render(eachTemplate, { kids: ['Ben', 'Polly', 'Joel', 'Phronsie', 'Davie'] }) assertEquals( res, diff --git a/test/file-handlers.spec.ts b/test/file-handlers.spec.ts index fd93bba..7867c93 100644 --- a/test/file-handlers.spec.ts +++ b/test/file-handlers.spec.ts @@ -4,20 +4,20 @@ import { renderFile, renderFileAsync, __express, templates, compile } from '../s import { buildRegEx } from './err.spec' -var path = require('path'), +const path = require('path'), filePath = path.join(__dirname, 'templates/simple.eta'), errFilePath = path.join(__dirname, 'templates/badsyntax.eta'), fakeFilePath = path.join(__dirname, 'templates/fake.eta') describe('Simple renderFile tests', () => { it('renders a simple template file', async () => { - var renderedFile = await renderFile(filePath, { name: 'Ben' }) + const renderedFile = await renderFile(filePath, { name: 'Ben' }) expect(renderedFile).toEqual('Hi Ben') }) it('renderFile is aliased as __express', async () => { - var renderedFile = await __express(filePath, { name: 'Ben' }) + const renderedFile = await __express(filePath, { name: 'Ben' }) expect(renderedFile).toEqual('Hi Ben') }) @@ -52,12 +52,12 @@ describe('Simple renderFile tests', () => { }) it('renders an async template using Promises', async () => { - var res = await renderFile(filePath, { name: 'Ada', async: true }) + const res = await renderFile(filePath, { name: 'Ada', async: true }) expect(res).toEqual('Hi Ada') }) it('renders an async template with an explicit config using Promises', async () => { - var res = await renderFile(filePath, { name: 'Ada' }, { async: true }) + const res = await renderFile(filePath, { name: 'Ada' }, { async: true }) expect(res).toEqual('Hi Ada') }) diff --git a/test/file-helpers.spec.ts b/test/file-helpers.spec.ts index 5b6358f..22facdf 100644 --- a/test/file-helpers.spec.ts +++ b/test/file-helpers.spec.ts @@ -2,13 +2,13 @@ import { render, templates, compile } from '../src/index' -var path = require('path') +const path = require('path') templates.define('test-template', compile('HEY <%=it.name%>')) describe('include works', () => { it('simple parser works with "E.includeFile"', async () => { - var renderedTemplate = render( + const renderedTemplate = render( '<%~ E.includeFile("simple", it) %>', { name: 'Ben' }, { filename: path.join(__dirname, 'templates/placeholder.eta') } @@ -18,7 +18,7 @@ describe('include works', () => { }) it('simple parser works with "includeFile"', async () => { - var renderedTemplate = render( + const renderedTemplate = render( '<%~ includeFile("simple", it) %>', { name: 'Ben' }, { filename: path.join(__dirname, 'templates/placeholder.eta') } @@ -28,7 +28,7 @@ describe('include works', () => { }) it('"includeFile" works with "views" array', async () => { - var renderedTemplate = render( + const renderedTemplate = render( '<%~ includeFile("randomtemplate", it) %>', { user: 'Ben' }, { @@ -41,7 +41,7 @@ describe('include works', () => { }) it('simple parser works with "include"', async () => { - var renderedTemplate = render('<%~ include("test-template", it) %>', { name: 'Ben' }) + const renderedTemplate = render('<%~ include("test-template", it) %>', { name: 'Ben' }) expect(renderedTemplate).toEqual('HEY Ben') }) diff --git a/test/file-utils.spec.ts b/test/file-utils.spec.ts index cdd49a5..7603d76 100644 --- a/test/file-utils.spec.ts +++ b/test/file-utils.spec.ts @@ -3,7 +3,7 @@ import { renderFile, loadFile, templates } from '../src/index' import { config } from '../src/config' -var path = require('path'), +const path = require('path'), filePath = path.join(__dirname, 'templates/simple.eta') describe('File tests', () => { diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts index a623f8b..f7579fd 100644 --- a/test/helpers.spec.ts +++ b/test/helpers.spec.ts @@ -4,7 +4,7 @@ import { render } from '../src/index' // SHOULD TEST COMMON ETA USAGE PATTERNS HERE -var eachTemplate = ` +const eachTemplate = ` The Daugherty's have 5 kids:
    <% it.kids.forEach(function(kid){ %> @@ -14,7 +14,7 @@ The Daugherty's have 5 kids: describe('Helper tests', () => { it('parses a simple array foreach', () => { - var res = render(eachTemplate, { kids: ['Ben', 'Polly', 'Joel', 'Phronsie', 'Davie'] }) + const res = render(eachTemplate, { kids: ['Ben', 'Polly', 'Joel', 'Phronsie', 'Davie'] }) expect(res).toEqual( ` The Daugherty's have 5 kids: diff --git a/test/layouts.spec.ts b/test/layouts.spec.ts index 290a015..a0e7192 100644 --- a/test/layouts.spec.ts +++ b/test/layouts.spec.ts @@ -5,7 +5,7 @@ import { compile, render, renderFile, templates } from '../src/index' describe('Layout Tests', () => { it('Nested layouts work as expected', async () => { - var res = await renderFile( + const res = await renderFile( 'index.eta', { title: 'Cool Title' }, // Async can be true or false @@ -29,7 +29,7 @@ This is the template body. compile(`###<%= it.title %>###,<%~ it.body %>`, { includeFile: undefined }) ) - var res = await render( + const res = await render( `<% layout("my-layout") %> This is a layout`, { title: 'Cool Title' }, @@ -47,7 +47,7 @@ This is a layout`, }) ) - var res = await render( + const res = await render( `<% layout("my-layout", { title: 'Nifty title', content: 'Nice content'}) %> This is a layout`, { title: 'Cool Title', randomNum: 3 }, diff --git a/test/parse.spec.ts b/test/parse.spec.ts index e7493d0..60a12a9 100644 --- a/test/parse.spec.ts +++ b/test/parse.spec.ts @@ -3,7 +3,7 @@ import { parse } from '../src/index' import { config } from '../src/config' -var fs = require('fs'), +const fs = require('fs'), path = require('path'), filePath = path.join(__dirname, 'templates/complex.eta') @@ -11,32 +11,32 @@ const complexTemplate = fs.readFileSync(filePath, 'utf8') describe('parse test', () => { it('parses a simple template', () => { - var buff = parse('hi <%= hey %>', config) + const buff = parse('hi <%= hey %>', config) expect(buff).toEqual(['hi ', { val: 'hey', t: 'i' }]) }) it('parses a raw tag', () => { - var buff = parse('hi <%~ hey %>', config) + const buff = parse('hi <%~ hey %>', config) expect(buff).toEqual(['hi ', { val: 'hey', t: 'r' }]) }) it('works with whitespace trimming', () => { - var buff = parse('hi\n<%- = hey-%> <%_ = hi _%>', config) + const buff = parse('hi\n<%- = hey-%> <%_ = hi _%>', config) expect(buff).toEqual(['hi', { val: 'hey', t: 'i' }, { val: 'hi', t: 'i' }]) }) it('works with multiline comments', () => { - var buff = parse('hi <% /* comment contains delimiter %> */ %>', config) + const buff = parse('hi <% /* comment contains delimiter %> */ %>', config) expect(buff).toEqual(['hi ', { val: '/* comment contains delimiter %> */', t: 'e' }]) }) it('parses with simple template literal', () => { - var buff = parse('hi <%= `template %> ${value}` %>', config) + const buff = parse('hi <%= `template %> ${value}` %>', config) expect(buff).toEqual(['hi ', { val: '`template %> ${value}`', t: 'i' }]) }) it('compiles complex template', () => { - var buff = parse(complexTemplate, config) + const buff = parse(complexTemplate, config) expect(buff).toEqual([ 'Hi\\n', { t: 'e', val: 'console.log("Hope you like Eta!")' }, diff --git a/test/plugins.spec.ts b/test/plugins.spec.ts index b7e9a45..b93b38d 100644 --- a/test/plugins.spec.ts +++ b/test/plugins.spec.ts @@ -17,7 +17,7 @@ function myPlugin() { } } -var template = `<%= it.val %> <%= @@num@@ %>.` +const template = `<%= it.val %> <%= @@num@@ %>.` describe('Plugins', () => { it('Plugins function properly', () => { diff --git a/test/storage.spec.ts b/test/storage.spec.ts index 3367c6c..dcc94bb 100644 --- a/test/storage.spec.ts +++ b/test/storage.spec.ts @@ -2,7 +2,7 @@ import { Cacher } from '../src/storage' -var Container = new Cacher({ one: 1, two: 2 }) +const Container = new Cacher({ one: 1, two: 2 }) describe('Config Tests', () => { it('Cache.get works', () => {