Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ejs.js #271

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions lib/ejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Module dependencies.
*/

var utils = require('./utils')
let utils = require('./utils')
, path = require('path')
, dirname = path.dirname
, extname = path.extname
Expand All @@ -22,15 +22,15 @@ var utils = require('./utils')
* @type Object
*/

var filters = exports.filters = require('./filters');
let filters = exports.filters = require('./filters');

/**
* Intermediate js cache.
*
* @type Object
*/

var cache = {};
let cache = {};

/**
* Clear intermediate js cache.
Expand All @@ -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;
Expand All @@ -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
+ '| '
Expand All @@ -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
Expand All @@ -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 + ', ';
Expand All @@ -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;
Expand All @@ -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 + "})() + '";
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -314,15 +314,15 @@ 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 = {};
}

options.filename = path;

var str;
let str;
try {
str = options.cache
? cache[key] || (cache[key] = read(path, 'utf8'))
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down