Skip to content

Commit

Permalink
refactor: use let instead of var where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowtime2000 committed Dec 5, 2020
1 parent 0c9410f commit 82a83b1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/compile-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { AstObject } from './parse'
export default function compileToString(str: string, config: EtaConfig): string {
const buffer: Array<AstObject> = Parse(str, config)

var res =
let res =
"var tR='',__l,__lP" +
(config.include ? ',include=E.include.bind(E)' : '') +
(config.includeFile ? ',includeFile=E.includeFile.bind(E)' : '') +
Expand All @@ -41,7 +41,7 @@ export default function compileToString(str: string, config: EtaConfig): string
(config.useWith ? '}' : '')

if (config.plugins) {
for (var i = 0; i < config.plugins.length; i++) {
for (let i = 0; i < config.plugins.length; i++) {
const plugin = config.plugins[i]
if (plugin.processFnString) {
res = plugin.processFnString(res, config)
Expand All @@ -66,9 +66,9 @@ export default function compileToString(str: string, config: EtaConfig): string
*/

function compileScope(buff: Array<AstObject>, config: EtaConfig) {
var i = 0
let i = 0
const buffLength = buff.length
var returnStr = ''
let returnStr = ''

for (i; i < buffLength; i++) {
const currentBlock = buff[i]
Expand All @@ -79,7 +79,7 @@ function compileScope(buff: Array<AstObject>, config: EtaConfig) {
returnStr += "tR+='" + str + "'\n"
} else {
const type = currentBlock.t // ~, s, !, ?, r
var content = currentBlock.val || ''
let content = currentBlock.val || ''

if (type === 'r') {
// raw
Expand Down
2 changes: 1 addition & 1 deletion src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type TemplateFunction = (data: object, config: EtaConfig, cb?: CallbackFn

export default function compile(str: string, config?: PartialConfig): TemplateFunction {
const options: EtaConfig = getConfig(config || {})
var ctor // constructor
let ctor // constructor

/* ASYNC HANDLING */
// The below code is modified from mde/ejs. All credit should go to them.
Expand Down
4 changes: 2 additions & 2 deletions src/file-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ function renderFile(
And we want to also make (filename, data, options, cb) available
*/

var renderConfig: EtaConfigWithFilename
var callback: CallbackFn | undefined
let renderConfig: EtaConfigWithFilename
let callback: CallbackFn | undefined
data = data || {} // If data is undefined, we don't want accessing data.settings to error

// First, assign our callback function to `callback`
Expand Down
8 changes: 4 additions & 4 deletions src/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { EtaConfig } from './config'
*/

function getWholeFilePath(name: string, parentfile: string, isDirectory?: boolean): string {
var includePath = path.resolve(
let includePath = path.resolve(
isDirectory ? parentfile : path.dirname(parentfile), // returns directory the parent file is in
name // file
)
Expand Down Expand Up @@ -54,9 +54,9 @@ function getWholeFilePath(name: string, parentfile: string, isDirectory?: boolea
*/

function getPath(path: string, options: EtaConfig): string {
var includePath: string | false = false
let includePath: string | false = false
const views = options.views
var searchedPaths: Array<string> = []
let searchedPaths: Array<string> = []

// If these four values are the same,
// getPath() will return the same result every time.
Expand Down Expand Up @@ -90,7 +90,7 @@ function getPath(path: string, options: EtaConfig): string {
*/

function searchViews(views: Array<string> | string | undefined, path: string): string | false {
var filePath
let filePath

// If views is an array, then loop through each directory
// And attempt to find the template
Expand Down
20 changes: 10 additions & 10 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ function escapeRegExp(string: string) {
}

export default function parse(str: string, config: EtaConfig): Array<AstObject> {
var buffer: Array<AstObject> = []
var trimLeftOfNextStr: string | false = false
var lastIndex = 0
let buffer: Array<AstObject> = []
let trimLeftOfNextStr: string | false = false
let lastIndex = 0
const parseOptions = config.parse

if (config.plugins) {
for (var i = 0; i < config.plugins.length; i++) {
for (let i = 0; i < config.plugins.length; i++) {
const plugin = config.plugins[i]
if (plugin.processTemplate) {
str = plugin.processTemplate(str, config)
Expand Down Expand Up @@ -108,7 +108,7 @@ export default function parse(str: string, config: EtaConfig): Array<AstObject>
)
// TODO: benchmark having the \s* on either side vs using str.trim()

var m
let m

while ((m = parseOpenReg.exec(str))) {
lastIndex = m[0].length + m.index
Expand All @@ -120,18 +120,18 @@ export default function parse(str: string, config: EtaConfig): Array<AstObject>
pushString(precedingString, wsLeft)

parseCloseReg.lastIndex = lastIndex
var closeTag
var currentObj: AstObject | false = false
let closeTag
let currentObj: AstObject | false = false

while ((closeTag = parseCloseReg.exec(str))) {
if (closeTag[1]) {
var content = str.slice(lastIndex, closeTag.index)
let content = str.slice(lastIndex, closeTag.index)

parseOpenReg.lastIndex = lastIndex = parseCloseReg.lastIndex

trimLeftOfNextStr = closeTag[2]

var currentType: TagType = ''
let currentType: TagType = ''
if (prefix === parseOptions.exec) {
currentType = 'e'
} else if (prefix === parseOptions.raw) {
Expand Down Expand Up @@ -190,7 +190,7 @@ export default function parse(str: string, config: EtaConfig): Array<AstObject>
pushString(str.slice(lastIndex, str.length), false)

if (config.plugins) {
for (var i = 0; i < config.plugins.length; i++) {
for (let i = 0; i < config.plugins.length; i++) {
const plugin = config.plugins[i]
if (plugin.processAST) {
buffer = plugin.processAST(buffer, config)
Expand Down
4 changes: 2 additions & 2 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { CallbackFn } from './file-handlers'
/* END TYPES */

function handleCache(template: string | TemplateFunction, options: EtaConfig): TemplateFunction {
var templateFunc
let templateFunc

if (options.cache && options.name && options.templates.get(options.name)) {
return options.templates.get(options.name)
Expand Down Expand Up @@ -61,7 +61,7 @@ export default function render(
const options = getConfig(config || {})

if (options.async) {
var result
let result
if (cb) {
// If user passes callback
try {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ function trimWS(
wsLeft: string | false,
wsRight?: string | false
): string {
var leftTrim
var rightTrim
let leftTrim
let rightTrim

if (Array.isArray(config.autoTrim)) {
// kinda confusing
Expand Down

0 comments on commit 82a83b1

Please sign in to comment.