update deps
This commit is contained in:
125
node_modules/ejs/lib/ejs.js
generated
vendored
125
node_modules/ejs/lib/ejs.js
generated
vendored
@@ -50,6 +50,8 @@ var utils = require('./utils');
|
||||
|
||||
var scopeOptionWarned = false;
|
||||
var _VERSION_STRING = require('../package.json').version;
|
||||
var _DEFAULT_OPEN_DELIMITER = '<';
|
||||
var _DEFAULT_CLOSE_DELIMITER = '>';
|
||||
var _DEFAULT_DELIMITER = '%';
|
||||
var _DEFAULT_LOCALS_NAME = 'locals';
|
||||
var _NAME = 'ejs';
|
||||
@@ -135,9 +137,10 @@ function getIncludePath(path, options) {
|
||||
var includePath;
|
||||
var filePath;
|
||||
var views = options.views;
|
||||
var match = /^[A-Za-z]+:\\|^\//.exec(path);
|
||||
|
||||
// Abs path
|
||||
if (path.charAt(0) == '/') {
|
||||
if (match && match.length) {
|
||||
includePath = exports.resolveInclude(path.replace(/^\/*/,''), options.root || '/', true);
|
||||
}
|
||||
// Relative paths
|
||||
@@ -487,6 +490,12 @@ exports.renderFile = function () {
|
||||
* @public
|
||||
*/
|
||||
|
||||
/**
|
||||
* EJS template class
|
||||
* @public
|
||||
*/
|
||||
exports.Template = Template;
|
||||
|
||||
exports.clearCache = function () {
|
||||
exports.cache.reset();
|
||||
};
|
||||
@@ -501,10 +510,12 @@ function Template(text, opts) {
|
||||
this.source = '';
|
||||
this.dependencies = [];
|
||||
options.client = opts.client || false;
|
||||
options.escapeFunction = opts.escape || utils.escapeXML;
|
||||
options.escapeFunction = opts.escape || opts.escapeFunction || utils.escapeXML;
|
||||
options.compileDebug = opts.compileDebug !== false;
|
||||
options.debug = !!opts.debug;
|
||||
options.filename = opts.filename;
|
||||
options.openDelimiter = opts.openDelimiter || exports.openDelimiter || _DEFAULT_OPEN_DELIMITER;
|
||||
options.closeDelimiter = opts.closeDelimiter || exports.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
|
||||
options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
|
||||
options.strict = opts.strict || false;
|
||||
options.context = opts.context;
|
||||
@@ -515,6 +526,8 @@ function Template(text, opts) {
|
||||
options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
|
||||
options.views = opts.views;
|
||||
options.async = opts.async;
|
||||
options.destructuredLocals = opts.destructuredLocals;
|
||||
options.legacyInclude = typeof opts.legacyInclude != 'undefined' ? !!opts.legacyInclude : true;
|
||||
|
||||
if (options.strict) {
|
||||
options._with = false;
|
||||
@@ -540,7 +553,11 @@ Template.prototype = {
|
||||
createRegex: function () {
|
||||
var str = _REGEX_STRING;
|
||||
var delim = utils.escapeRegExpChars(this.opts.delimiter);
|
||||
str = str.replace(/%/g, delim);
|
||||
var open = utils.escapeRegExpChars(this.opts.openDelimiter);
|
||||
var close = utils.escapeRegExpChars(this.opts.closeDelimiter);
|
||||
str = str.replace(/%/g, delim)
|
||||
.replace(/</g, open)
|
||||
.replace(/>/g, close);
|
||||
return new RegExp(str);
|
||||
},
|
||||
|
||||
@@ -551,19 +568,32 @@ Template.prototype = {
|
||||
var prepended = '';
|
||||
var appended = '';
|
||||
var escapeFn = opts.escapeFunction;
|
||||
var asyncCtor;
|
||||
var ctor;
|
||||
|
||||
if (!this.source) {
|
||||
this.generateSource();
|
||||
prepended += ' var __output = [], __append = __output.push.bind(__output);' + '\n';
|
||||
prepended +=
|
||||
' var __output = "";\n' +
|
||||
' function __append(s) { if (s !== undefined && s !== null) __output += s }\n';
|
||||
if (opts.outputFunctionName) {
|
||||
prepended += ' var ' + opts.outputFunctionName + ' = __append;' + '\n';
|
||||
}
|
||||
if (opts.destructuredLocals && opts.destructuredLocals.length) {
|
||||
var destructuring = ' var __locals = (' + opts.localsName + ' || {}),\n';
|
||||
for (var i = 0; i < opts.destructuredLocals.length; i++) {
|
||||
var name = opts.destructuredLocals[i];
|
||||
if (i > 0) {
|
||||
destructuring += ',\n ';
|
||||
}
|
||||
destructuring += name + ' = __locals.' + name;
|
||||
}
|
||||
prepended += destructuring + ';\n';
|
||||
}
|
||||
if (opts._with !== false) {
|
||||
prepended += ' with (' + opts.localsName + ' || {}) {' + '\n';
|
||||
appended += ' }' + '\n';
|
||||
}
|
||||
appended += ' return __output.join("");' + '\n';
|
||||
appended += ' return __output;' + '\n';
|
||||
this.source = prepended + this.source + appended;
|
||||
}
|
||||
|
||||
@@ -595,13 +625,17 @@ Template.prototype = {
|
||||
if (opts.debug) {
|
||||
console.log(src);
|
||||
}
|
||||
if (opts.compileDebug && opts.filename) {
|
||||
src = src + '\n'
|
||||
+ '//# sourceURL=' + opts.filename + '\n';
|
||||
}
|
||||
|
||||
try {
|
||||
if (opts.async) {
|
||||
// Have to use generated function for this, since in envs without support,
|
||||
// it breaks in parsing
|
||||
try {
|
||||
asyncCtor = (new Function('return (async function(){}).constructor;'))();
|
||||
ctor = (new Function('return (async function(){}).constructor;'))();
|
||||
}
|
||||
catch(e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
@@ -613,9 +647,9 @@ Template.prototype = {
|
||||
}
|
||||
}
|
||||
else {
|
||||
asyncCtor = Function;
|
||||
ctor = Function;
|
||||
}
|
||||
fn = new asyncCtor(opts.localsName + ', escapeFn, include, rethrow', src);
|
||||
fn = new ctor(opts.localsName + ', escapeFn, include, rethrow', src);
|
||||
}
|
||||
catch(e) {
|
||||
// istanbul ignore else
|
||||
@@ -626,23 +660,18 @@ Template.prototype = {
|
||||
e.message += ' while compiling ejs\n\n';
|
||||
e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n';
|
||||
e.message += 'https://github.com/RyanZim/EJS-Lint';
|
||||
if (!e.async) {
|
||||
if (!opts.async) {
|
||||
e.message += '\n';
|
||||
e.message += 'Or, if you meant to create an async function, pass async: true as an option.';
|
||||
e.message += 'Or, if you meant to create an async function, pass `async: true` as an option.';
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (opts.client) {
|
||||
fn.dependencies = this.dependencies;
|
||||
return fn;
|
||||
}
|
||||
|
||||
// Return a callable function which will execute the function
|
||||
// created by the source-code, with the passed data as locals
|
||||
// Adds a local `include` function which allows full recursive include
|
||||
var returnedFn = function (data) {
|
||||
var returnedFn = opts.client ? fn : function anonymous(data) {
|
||||
var include = function (path, includeData) {
|
||||
var d = utils.shallowCopy({}, data);
|
||||
if (includeData) {
|
||||
@@ -653,6 +682,18 @@ Template.prototype = {
|
||||
return fn.apply(opts.context, [data || {}, escapeFn, include, rethrow]);
|
||||
};
|
||||
returnedFn.dependencies = this.dependencies;
|
||||
if (opts.filename && typeof Object.defineProperty === 'function') {
|
||||
var filename = opts.filename;
|
||||
var basename = path.basename(filename, path.extname(filename));
|
||||
try {
|
||||
Object.defineProperty(returnedFn, 'name', {
|
||||
value: basename,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
} catch (e) {/* ignore */}
|
||||
}
|
||||
return returnedFn;
|
||||
},
|
||||
|
||||
@@ -661,9 +702,9 @@ Template.prototype = {
|
||||
|
||||
if (opts.rmWhitespace) {
|
||||
// Have to use two separate replace here as `^` and `$` operators don't
|
||||
// work well with `\r`.
|
||||
// work well with `\r` and empty lines don't work well with the `m` flag.
|
||||
this.templateText =
|
||||
this.templateText.replace(/\r/g, '').replace(/^\s+|\s+$/gm, '');
|
||||
this.templateText.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
||||
}
|
||||
|
||||
// Slurp spaces and tabs before <%_ and after _%>
|
||||
@@ -673,6 +714,8 @@ Template.prototype = {
|
||||
var self = this;
|
||||
var matches = this.parseTemplateText();
|
||||
var d = this.opts.delimiter;
|
||||
var o = this.opts.openDelimiter;
|
||||
var c = this.opts.closeDelimiter;
|
||||
|
||||
if (matches && matches.length) {
|
||||
matches.forEach(function (line, index) {
|
||||
@@ -684,20 +727,20 @@ Template.prototype = {
|
||||
var includeSrc;
|
||||
// If this is an opening tag, check for closing tags
|
||||
// FIXME: May end up with some false positives here
|
||||
// Better to store modes as k/v with '<' + delimiter as key
|
||||
// Better to store modes as k/v with openDelimiter + delimiter as key
|
||||
// Then this can simply check against the map
|
||||
if ( line.indexOf('<' + d) === 0 // If it is a tag
|
||||
&& line.indexOf('<' + d + d) !== 0) { // and is not escaped
|
||||
if ( line.indexOf(o + d) === 0 // If it is a tag
|
||||
&& line.indexOf(o + d + d) !== 0) { // and is not escaped
|
||||
closing = matches[index + 2];
|
||||
if (!(closing == d + '>' || closing == '-' + d + '>' || closing == '_' + d + '>')) {
|
||||
if (!(closing == d + c || closing == '-' + d + c || closing == '_' + d + c)) {
|
||||
throw new Error('Could not find matching close tag for "' + line + '".');
|
||||
}
|
||||
}
|
||||
// HACK: backward-compat `include` preprocessor directives
|
||||
if ((include = line.match(/^\s*include\s+(\S+)/))) {
|
||||
if (opts.legacyInclude && (include = line.match(/^\s*include\s+(\S+)/))) {
|
||||
opening = matches[index - 1];
|
||||
// Must be in EVAL or RAW mode
|
||||
if (opening && (opening == '<' + d || opening == '<' + d + '-' || opening == '<' + d + '_')) {
|
||||
if (opening && (opening == o + d || opening == o + d + '-' || opening == o + d + '_')) {
|
||||
includeOpts = utils.shallowCopy({}, self.opts);
|
||||
includeObj = includeSource(include[1], includeOpts);
|
||||
if (self.opts.compileDebug) {
|
||||
@@ -765,11 +808,6 @@ Template.prototype = {
|
||||
line = line.replace(/^(?:\r\n|\r|\n)/, '');
|
||||
this.truncate = false;
|
||||
}
|
||||
else if (this.opts.rmWhitespace) {
|
||||
// rmWhitespace has already removed trailing spaces, just need
|
||||
// to remove linebreaks
|
||||
line = line.replace(/^\n/, '');
|
||||
}
|
||||
if (!line) {
|
||||
return line;
|
||||
}
|
||||
@@ -790,35 +828,37 @@ Template.prototype = {
|
||||
scanLine: function (line) {
|
||||
var self = this;
|
||||
var d = this.opts.delimiter;
|
||||
var o = this.opts.openDelimiter;
|
||||
var c = this.opts.closeDelimiter;
|
||||
var newLineCount = 0;
|
||||
|
||||
newLineCount = (line.split('\n').length - 1);
|
||||
|
||||
switch (line) {
|
||||
case '<' + d:
|
||||
case '<' + d + '_':
|
||||
case o + d:
|
||||
case o + d + '_':
|
||||
this.mode = Template.modes.EVAL;
|
||||
break;
|
||||
case '<' + d + '=':
|
||||
case o + d + '=':
|
||||
this.mode = Template.modes.ESCAPED;
|
||||
break;
|
||||
case '<' + d + '-':
|
||||
case o + d + '-':
|
||||
this.mode = Template.modes.RAW;
|
||||
break;
|
||||
case '<' + d + '#':
|
||||
case o + d + '#':
|
||||
this.mode = Template.modes.COMMENT;
|
||||
break;
|
||||
case '<' + d + d:
|
||||
case o + d + d:
|
||||
this.mode = Template.modes.LITERAL;
|
||||
this.source += ' ; __append("' + line.replace('<' + d + d, '<' + d) + '")' + '\n';
|
||||
this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")' + '\n';
|
||||
break;
|
||||
case d + d + '>':
|
||||
case d + d + c:
|
||||
this.mode = Template.modes.LITERAL;
|
||||
this.source += ' ; __append("' + line.replace(d + d + '>', d + '>') + '")' + '\n';
|
||||
this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")' + '\n';
|
||||
break;
|
||||
case d + '>':
|
||||
case '-' + d + '>':
|
||||
case '_' + d + '>':
|
||||
case d + c:
|
||||
case '-' + d + c:
|
||||
case '_' + d + c:
|
||||
if (this.mode == Template.modes.LITERAL) {
|
||||
this._addOutput(line);
|
||||
}
|
||||
@@ -902,6 +942,7 @@ exports.__express = exports.renderFile;
|
||||
/* istanbul ignore else */
|
||||
if (require.extensions) {
|
||||
require.extensions['.ejs'] = function (module, flnm) {
|
||||
console.log('Deprecated: this API will go away in EJS v2.8');
|
||||
var filename = flnm || /* istanbul ignore next */ module.filename;
|
||||
var options = {
|
||||
filename: filename,
|
||||
|
3
node_modules/ejs/lib/utils.js
generated
vendored
3
node_modules/ejs/lib/utils.js
generated
vendored
@@ -158,6 +158,9 @@ exports.cache = {
|
||||
get: function (key) {
|
||||
return this._data[key];
|
||||
},
|
||||
remove: function (key) {
|
||||
delete this._data[key];
|
||||
},
|
||||
reset: function () {
|
||||
this._data = {};
|
||||
}
|
||||
|
Reference in New Issue
Block a user