From 1bfabb7c5ccf1893c5b373ed6e3778f64a9aec39 Mon Sep 17 00:00:00 2001 From: Rohit Paul <113459757+RohitPaul0007@users.noreply.github.com> Date: Tue, 12 Sep 2023 12:45:21 +0530 Subject: [PATCH] Update ejs.js --- lib/ejs.js | 56 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/ejs.js b/lib/ejs.js index ca304a13..db7135d0 100644 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -8,7 +8,7 @@ * Module dependencies. */ -var utils = require('./utils') +let utils = require('./utils') , path = require('path') , dirname = path.dirname , extname = path.extname @@ -22,7 +22,7 @@ var utils = require('./utils') * @type Object */ -var filters = exports.filters = require('./filters'); +let filters = exports.filters = require('./filters'); /** * Intermediate js cache. @@ -30,7 +30,7 @@ var filters = exports.filters = require('./filters'); * @type Object */ -var cache = {}; +let cache = {}; /** * Clear intermediate js cache. @@ -52,7 +52,7 @@ exports.clearCache = function(){ function filtered(js) { return js.substr(1).split('|').reduce(function(js, filter){ - var parts = filter.split(':') + let parts = filter.split(':') , name = parts.shift() , args = parts.join(':') || ''; if (args) args = ', ' + args; @@ -72,13 +72,13 @@ function filtered(js) { */ function rethrow(err, str, filename, lineno){ - var lines = str.split('\n') + let lines = str.split('\n') , start = Math.max(lineno - 3, 0) , end = Math.min(lines.length, lineno + 3); // Error context - var context = lines.slice(start, end).map(function(line, i){ - var curr = i + start + 1; + let context = lines.slice(start, end).map(function(line, i){ + let curr = i + start + 1; return (curr == lineno ? ' >> ' : ' ') + curr + '| ' @@ -103,8 +103,8 @@ function rethrow(err, str, filename, lineno){ * @api public */ -var parse = exports.parse = function(str, options){ - var options = options || {} +let parse = exports.parse = function(str, options){ + let options = options || {} , open = options.open || exports.open || '<%' , close = options.close || exports.close || '%>' , filename = options.filename @@ -115,15 +115,15 @@ var parse = exports.parse = function(str, options){ if (false !== options._with) buf += '\nwith (locals || {}) { (function(){ '; buf += '\n buf.push(\''; - var lineno = 1; + let lineno = 1; - var consumeEOL = false; - for (var i = 0, len = str.length; i < len; ++i) { - var stri = str[i]; + let consumeEOL = false; + for (let i = 0, len = str.length; i < len; ++i) { + let stri = str[i]; if (str.slice(i, open.length + i) == open) { i += open.length - var prefix, postfix, line = (compileDebug ? '__stack.lineno=' : '') + lineno; + let prefix, postfix, line = (compileDebug ? '__stack.lineno=' : '') + lineno; switch (str[i]) { case '=': prefix = "', escape((" + line + ', '; @@ -140,13 +140,13 @@ var parse = exports.parse = function(str, options){ postfix = "; buf.push('"; } - var end = str.indexOf(close, i); + let end = str.indexOf(close, i); if (end < 0){ throw new Error('Could not find matching close tag "' + close + '".'); } - var js = str.substring(i, end) + let js = str.substring(i, end) , start = i , include = null , n = 0; @@ -157,9 +157,9 @@ var parse = exports.parse = function(str, options){ } if (0 == js.trim().indexOf('include')) { - var name = js.trim().slice(7).trim(); + let name = js.trim().slice(7).trim(); if (!filename) throw new Error('filename option is required for includes'); - var path = resolveInclude(name, filename); + let path = resolveInclude(name, filename); include = read(path, 'utf8'); include = exports.parse(include, { filename: path, _with: false, open: open, close: close, compileDebug: compileDebug }); buf += "' + (function(){" + include + "})() + '"; @@ -220,11 +220,11 @@ var parse = exports.parse = function(str, options){ * @api public */ -var compile = exports.compile = function(str, options){ +let compile = exports.compile = function(str, options){ options = options || {}; - var escape = options.escape || utils.escape; + let escape = options.escape || utils.escape; - var input = JSON.stringify(str) + let input = JSON.stringify(str) , compileDebug = options.compileDebug !== false , client = options.client , filename = options.filename @@ -250,7 +250,7 @@ var compile = exports.compile = function(str, options){ if (client) str = 'escape = escape || ' + escape.toString() + ';\n' + str; try { - var fn = new Function('locals, filters, escape, rethrow', str); + let fn = new Function('locals, filters, escape, rethrow', str); } catch (err) { if ('SyntaxError' == err.name) { err.message += options.filename @@ -287,7 +287,7 @@ var compile = exports.compile = function(str, options){ */ exports.render = function(str, options){ - var fn + let fn , options = options || {}; if (options.cache) { @@ -314,7 +314,7 @@ exports.render = function(str, options){ */ exports.renderFile = function(path, options, fn){ - var key = path + ':string'; + let key = path + ':string'; if ('function' == typeof options) { fn = options, options = {}; @@ -322,7 +322,7 @@ exports.renderFile = function(path, options, fn){ options.filename = path; - var str; + let str; try { str = options.cache ? cache[key] || (cache[key] = read(path, 'utf8')) @@ -344,8 +344,8 @@ exports.renderFile = function(path, options, fn){ */ function resolveInclude(name, filename) { - var path = join(dirname(filename), name); - var ext = extname(name); + let path = join(dirname(filename), name); + let ext = extname(name); if (!ext) path += '.ejs'; return path; } @@ -361,7 +361,7 @@ exports.__express = exports.renderFile; if (require.extensions) { require.extensions['.ejs'] = function (module, filename) { filename = filename || module.filename; - var options = { filename: filename, client: true } + let options = { filename: filename, client: true } , template = fs.readFileSync(filename).toString() , fn = compile(template, options); module._compile('module.exports = ' + fn.toString() + ';', filename);