ejs.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ejs = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
  2. /*
  3. * EJS Embedded JavaScript templates
  4. * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. */
  19. 'use strict';
  20. /**
  21. * @file Embedded JavaScript templating engine. {@link http://ejs.co}
  22. * @author Matthew Eernisse <mde@fleegix.org>
  23. * @author Tiancheng "Timothy" Gu <timothygu99@gmail.com>
  24. * @project EJS
  25. * @license {@link http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0}
  26. */
  27. /**
  28. * EJS internal functions.
  29. *
  30. * Technically this "module" lies in the same file as {@link module:ejs}, for
  31. * the sake of organization all the private functions re grouped into this
  32. * module.
  33. *
  34. * @module ejs-internal
  35. * @private
  36. */
  37. /**
  38. * Embedded JavaScript templating engine.
  39. *
  40. * @module ejs
  41. * @public
  42. */
  43. var fs = require('fs');
  44. var path = require('path');
  45. var utils = require('./utils');
  46. var scopeOptionWarned = false;
  47. var _VERSION_STRING = require('../package.json').version;
  48. var _DEFAULT_OPEN_DELIMITER = '<';
  49. var _DEFAULT_CLOSE_DELIMITER = '>';
  50. var _DEFAULT_DELIMITER = '%';
  51. var _DEFAULT_LOCALS_NAME = 'locals';
  52. var _NAME = 'ejs';
  53. var _REGEX_STRING = '(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)';
  54. var _OPTS_PASSABLE_WITH_DATA = ['delimiter', 'scope', 'context', 'debug', 'compileDebug',
  55. 'client', '_with', 'rmWhitespace', 'strict', 'filename', 'async'];
  56. // We don't allow 'cache' option to be passed in the data obj for
  57. // the normal `render` call, but this is where Express 2 & 3 put it
  58. // so we make an exception for `renderFile`
  59. var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat('cache');
  60. var _BOM = /^\uFEFF/;
  61. /**
  62. * EJS template function cache. This can be a LRU object from lru-cache NPM
  63. * module. By default, it is {@link module:utils.cache}, a simple in-process
  64. * cache that grows continuously.
  65. *
  66. * @type {Cache}
  67. */
  68. exports.cache = utils.cache;
  69. /**
  70. * Custom file loader. Useful for template preprocessing or restricting access
  71. * to a certain part of the filesystem.
  72. *
  73. * @type {fileLoader}
  74. */
  75. exports.fileLoader = fs.readFileSync;
  76. /**
  77. * Name of the object containing the locals.
  78. *
  79. * This variable is overridden by {@link Options}`.localsName` if it is not
  80. * `undefined`.
  81. *
  82. * @type {String}
  83. * @public
  84. */
  85. exports.localsName = _DEFAULT_LOCALS_NAME;
  86. /**
  87. * Promise implementation -- defaults to the native implementation if available
  88. * This is mostly just for testability
  89. *
  90. * @type {Function}
  91. * @public
  92. */
  93. exports.promiseImpl = (new Function('return this;'))().Promise;
  94. /**
  95. * Get the path to the included file from the parent file path and the
  96. * specified path.
  97. *
  98. * @param {String} name specified path
  99. * @param {String} filename parent file path
  100. * @param {Boolean} isDir parent file path whether is directory
  101. * @return {String}
  102. */
  103. exports.resolveInclude = function(name, filename, isDir) {
  104. var dirname = path.dirname;
  105. var extname = path.extname;
  106. var resolve = path.resolve;
  107. var includePath = resolve(isDir ? filename : dirname(filename), name);
  108. var ext = extname(name);
  109. if (!ext) {
  110. includePath += '.ejs';
  111. }
  112. return includePath;
  113. };
  114. /**
  115. * Get the path to the included file by Options
  116. *
  117. * @param {String} path specified path
  118. * @param {Options} options compilation options
  119. * @return {String}
  120. */
  121. function getIncludePath(path, options) {
  122. var includePath;
  123. var filePath;
  124. var views = options.views;
  125. var match = /^[A-Za-z]+:\\|^\//.exec(path);
  126. // Abs path
  127. if (match && match.length) {
  128. includePath = exports.resolveInclude(path.replace(/^\/*/,''), options.root || '/', true);
  129. }
  130. // Relative paths
  131. else {
  132. // Look relative to a passed filename first
  133. if (options.filename) {
  134. filePath = exports.resolveInclude(path, options.filename);
  135. if (fs.existsSync(filePath)) {
  136. includePath = filePath;
  137. }
  138. }
  139. // Then look in any views directories
  140. if (!includePath) {
  141. if (Array.isArray(views) && views.some(function (v) {
  142. filePath = exports.resolveInclude(path, v, true);
  143. return fs.existsSync(filePath);
  144. })) {
  145. includePath = filePath;
  146. }
  147. }
  148. if (!includePath) {
  149. throw new Error('Could not find the include file "' +
  150. options.escapeFunction(path) + '"');
  151. }
  152. }
  153. return includePath;
  154. }
  155. /**
  156. * Get the template from a string or a file, either compiled on-the-fly or
  157. * read from cache (if enabled), and cache the template if needed.
  158. *
  159. * If `template` is not set, the file specified in `options.filename` will be
  160. * read.
  161. *
  162. * If `options.cache` is true, this function reads the file from
  163. * `options.filename` so it must be set prior to calling this function.
  164. *
  165. * @memberof module:ejs-internal
  166. * @param {Options} options compilation options
  167. * @param {String} [template] template source
  168. * @return {(TemplateFunction|ClientFunction)}
  169. * Depending on the value of `options.client`, either type might be returned.
  170. * @static
  171. */
  172. function handleCache(options, template) {
  173. var func;
  174. var filename = options.filename;
  175. var hasTemplate = arguments.length > 1;
  176. if (options.cache) {
  177. if (!filename) {
  178. throw new Error('cache option requires a filename');
  179. }
  180. func = exports.cache.get(filename);
  181. if (func) {
  182. return func;
  183. }
  184. if (!hasTemplate) {
  185. template = fileLoader(filename).toString().replace(_BOM, '');
  186. }
  187. }
  188. else if (!hasTemplate) {
  189. // istanbul ignore if: should not happen at all
  190. if (!filename) {
  191. throw new Error('Internal EJS error: no file name or template '
  192. + 'provided');
  193. }
  194. template = fileLoader(filename).toString().replace(_BOM, '');
  195. }
  196. func = exports.compile(template, options);
  197. if (options.cache) {
  198. exports.cache.set(filename, func);
  199. }
  200. return func;
  201. }
  202. /**
  203. * Try calling handleCache with the given options and data and call the
  204. * callback with the result. If an error occurs, call the callback with
  205. * the error. Used by renderFile().
  206. *
  207. * @memberof module:ejs-internal
  208. * @param {Options} options compilation options
  209. * @param {Object} data template data
  210. * @param {RenderFileCallback} cb callback
  211. * @static
  212. */
  213. function tryHandleCache(options, data, cb) {
  214. var result;
  215. if (!cb) {
  216. if (typeof exports.promiseImpl == 'function') {
  217. return new exports.promiseImpl(function (resolve, reject) {
  218. try {
  219. result = handleCache(options)(data);
  220. resolve(result);
  221. }
  222. catch (err) {
  223. reject(err);
  224. }
  225. });
  226. }
  227. else {
  228. throw new Error('Please provide a callback function');
  229. }
  230. }
  231. else {
  232. try {
  233. result = handleCache(options)(data);
  234. }
  235. catch (err) {
  236. return cb(err);
  237. }
  238. cb(null, result);
  239. }
  240. }
  241. /**
  242. * fileLoader is independent
  243. *
  244. * @param {String} filePath ejs file path.
  245. * @return {String} The contents of the specified file.
  246. * @static
  247. */
  248. function fileLoader(filePath){
  249. return exports.fileLoader(filePath);
  250. }
  251. /**
  252. * Get the template function.
  253. *
  254. * If `options.cache` is `true`, then the template is cached.
  255. *
  256. * @memberof module:ejs-internal
  257. * @param {String} path path for the specified file
  258. * @param {Options} options compilation options
  259. * @return {(TemplateFunction|ClientFunction)}
  260. * Depending on the value of `options.client`, either type might be returned
  261. * @static
  262. */
  263. function includeFile(path, options) {
  264. var opts = utils.shallowCopy({}, options);
  265. opts.filename = getIncludePath(path, opts);
  266. return handleCache(opts);
  267. }
  268. /**
  269. * Get the JavaScript source of an included file.
  270. *
  271. * @memberof module:ejs-internal
  272. * @param {String} path path for the specified file
  273. * @param {Options} options compilation options
  274. * @return {Object}
  275. * @static
  276. */
  277. function includeSource(path, options) {
  278. var opts = utils.shallowCopy({}, options);
  279. var includePath;
  280. var template;
  281. includePath = getIncludePath(path, opts);
  282. template = fileLoader(includePath).toString().replace(_BOM, '');
  283. opts.filename = includePath;
  284. var templ = new Template(template, opts);
  285. templ.generateSource();
  286. return {
  287. source: templ.source,
  288. filename: includePath,
  289. template: template
  290. };
  291. }
  292. /**
  293. * Re-throw the given `err` in context to the `str` of ejs, `filename`, and
  294. * `lineno`.
  295. *
  296. * @implements RethrowCallback
  297. * @memberof module:ejs-internal
  298. * @param {Error} err Error object
  299. * @param {String} str EJS source
  300. * @param {String} filename file name of the EJS file
  301. * @param {String} lineno line number of the error
  302. * @static
  303. */
  304. function rethrow(err, str, flnm, lineno, esc){
  305. var lines = str.split('\n');
  306. var start = Math.max(lineno - 3, 0);
  307. var end = Math.min(lines.length, lineno + 3);
  308. var filename = esc(flnm); // eslint-disable-line
  309. // Error context
  310. var context = lines.slice(start, end).map(function (line, i){
  311. var curr = i + start + 1;
  312. return (curr == lineno ? ' >> ' : ' ')
  313. + curr
  314. + '| '
  315. + line;
  316. }).join('\n');
  317. // Alter exception message
  318. err.path = filename;
  319. err.message = (filename || 'ejs') + ':'
  320. + lineno + '\n'
  321. + context + '\n\n'
  322. + err.message;
  323. throw err;
  324. }
  325. function stripSemi(str){
  326. return str.replace(/;(\s*$)/, '$1');
  327. }
  328. /**
  329. * Compile the given `str` of ejs into a template function.
  330. *
  331. * @param {String} template EJS template
  332. *
  333. * @param {Options} opts compilation options
  334. *
  335. * @return {(TemplateFunction|ClientFunction)}
  336. * Depending on the value of `opts.client`, either type might be returned.
  337. * Note that the return type of the function also depends on the value of `opts.async`.
  338. * @public
  339. */
  340. exports.compile = function compile(template, opts) {
  341. var templ;
  342. // v1 compat
  343. // 'scope' is 'context'
  344. // FIXME: Remove this in a future version
  345. if (opts && opts.scope) {
  346. if (!scopeOptionWarned){
  347. console.warn('`scope` option is deprecated and will be removed in EJS 3');
  348. scopeOptionWarned = true;
  349. }
  350. if (!opts.context) {
  351. opts.context = opts.scope;
  352. }
  353. delete opts.scope;
  354. }
  355. templ = new Template(template, opts);
  356. return templ.compile();
  357. };
  358. /**
  359. * Render the given `template` of ejs.
  360. *
  361. * If you would like to include options but not data, you need to explicitly
  362. * call this function with `data` being an empty object or `null`.
  363. *
  364. * @param {String} template EJS template
  365. * @param {Object} [data={}] template data
  366. * @param {Options} [opts={}] compilation and rendering options
  367. * @return {(String|Promise<String>)}
  368. * Return value type depends on `opts.async`.
  369. * @public
  370. */
  371. exports.render = function (template, d, o) {
  372. var data = d || {};
  373. var opts = o || {};
  374. // No options object -- if there are optiony names
  375. // in the data, copy them to options
  376. if (arguments.length == 2) {
  377. utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
  378. }
  379. return handleCache(opts, template)(data);
  380. };
  381. /**
  382. * Render an EJS file at the given `path` and callback `cb(err, str)`.
  383. *
  384. * If you would like to include options but not data, you need to explicitly
  385. * call this function with `data` being an empty object or `null`.
  386. *
  387. * @param {String} path path to the EJS file
  388. * @param {Object} [data={}] template data
  389. * @param {Options} [opts={}] compilation and rendering options
  390. * @param {RenderFileCallback} cb callback
  391. * @public
  392. */
  393. exports.renderFile = function () {
  394. var args = Array.prototype.slice.call(arguments);
  395. var filename = args.shift();
  396. var cb;
  397. var opts = {filename: filename};
  398. var data;
  399. var viewOpts;
  400. // Do we have a callback?
  401. if (typeof arguments[arguments.length - 1] == 'function') {
  402. cb = args.pop();
  403. }
  404. // Do we have data/opts?
  405. if (args.length) {
  406. // Should always have data obj
  407. data = args.shift();
  408. // Normal passed opts (data obj + opts obj)
  409. if (args.length) {
  410. // Use shallowCopy so we don't pollute passed in opts obj with new vals
  411. utils.shallowCopy(opts, args.pop());
  412. }
  413. // Special casing for Express (settings + opts-in-data)
  414. else {
  415. // Express 3 and 4
  416. if (data.settings) {
  417. // Pull a few things from known locations
  418. if (data.settings.views) {
  419. opts.views = data.settings.views;
  420. }
  421. if (data.settings['view cache']) {
  422. opts.cache = true;
  423. }
  424. // Undocumented after Express 2, but still usable, esp. for
  425. // items that are unsafe to be passed along with data, like `root`
  426. viewOpts = data.settings['view options'];
  427. if (viewOpts) {
  428. utils.shallowCopy(opts, viewOpts);
  429. }
  430. }
  431. // Express 2 and lower, values set in app.locals, or people who just
  432. // want to pass options in their data. NOTE: These values will override
  433. // anything previously set in settings or settings['view options']
  434. utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
  435. }
  436. opts.filename = filename;
  437. }
  438. else {
  439. data = {};
  440. }
  441. return tryHandleCache(opts, data, cb);
  442. };
  443. /**
  444. * Clear intermediate JavaScript cache. Calls {@link Cache#reset}.
  445. * @public
  446. */
  447. /**
  448. * EJS template class
  449. * @public
  450. */
  451. exports.Template = Template;
  452. exports.clearCache = function () {
  453. exports.cache.reset();
  454. };
  455. function Template(text, opts) {
  456. opts = opts || {};
  457. var options = {};
  458. this.templateText = text;
  459. this.mode = null;
  460. this.truncate = false;
  461. this.currentLine = 1;
  462. this.source = '';
  463. this.dependencies = [];
  464. options.client = opts.client || false;
  465. options.escapeFunction = opts.escape || opts.escapeFunction || utils.escapeXML;
  466. options.compileDebug = opts.compileDebug !== false;
  467. options.debug = !!opts.debug;
  468. options.filename = opts.filename;
  469. options.openDelimiter = opts.openDelimiter || exports.openDelimiter || _DEFAULT_OPEN_DELIMITER;
  470. options.closeDelimiter = opts.closeDelimiter || exports.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
  471. options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
  472. options.strict = opts.strict || false;
  473. options.context = opts.context;
  474. options.cache = opts.cache || false;
  475. options.rmWhitespace = opts.rmWhitespace;
  476. options.root = opts.root;
  477. options.outputFunctionName = opts.outputFunctionName;
  478. options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
  479. options.views = opts.views;
  480. options.async = opts.async;
  481. if (options.strict) {
  482. options._with = false;
  483. }
  484. else {
  485. options._with = typeof opts._with != 'undefined' ? opts._with : true;
  486. }
  487. this.opts = options;
  488. this.regex = this.createRegex();
  489. }
  490. Template.modes = {
  491. EVAL: 'eval',
  492. ESCAPED: 'escaped',
  493. RAW: 'raw',
  494. COMMENT: 'comment',
  495. LITERAL: 'literal'
  496. };
  497. Template.prototype = {
  498. createRegex: function () {
  499. var str = _REGEX_STRING;
  500. var delim = utils.escapeRegExpChars(this.opts.delimiter);
  501. var open = utils.escapeRegExpChars(this.opts.openDelimiter);
  502. var close = utils.escapeRegExpChars(this.opts.closeDelimiter);
  503. str = str.replace(/%/g, delim)
  504. .replace(/</g, open)
  505. .replace(/>/g, close);
  506. return new RegExp(str);
  507. },
  508. compile: function () {
  509. var src;
  510. var fn;
  511. var opts = this.opts;
  512. var prepended = '';
  513. var appended = '';
  514. var escapeFn = opts.escapeFunction;
  515. var ctor;
  516. if (!this.source) {
  517. this.generateSource();
  518. prepended += ' var __output = [], __append = __output.push.bind(__output);' + '\n';
  519. if (opts.outputFunctionName) {
  520. prepended += ' var ' + opts.outputFunctionName + ' = __append;' + '\n';
  521. }
  522. if (opts._with !== false) {
  523. prepended += ' with (' + opts.localsName + ' || {}) {' + '\n';
  524. appended += ' }' + '\n';
  525. }
  526. appended += ' return __output.join("");' + '\n';
  527. this.source = prepended + this.source + appended;
  528. }
  529. if (opts.compileDebug) {
  530. src = 'var __line = 1' + '\n'
  531. + ' , __lines = ' + JSON.stringify(this.templateText) + '\n'
  532. + ' , __filename = ' + (opts.filename ?
  533. JSON.stringify(opts.filename) : 'undefined') + ';' + '\n'
  534. + 'try {' + '\n'
  535. + this.source
  536. + '} catch (e) {' + '\n'
  537. + ' rethrow(e, __lines, __filename, __line, escapeFn);' + '\n'
  538. + '}' + '\n';
  539. }
  540. else {
  541. src = this.source;
  542. }
  543. if (opts.client) {
  544. src = 'escapeFn = escapeFn || ' + escapeFn.toString() + ';' + '\n' + src;
  545. if (opts.compileDebug) {
  546. src = 'rethrow = rethrow || ' + rethrow.toString() + ';' + '\n' + src;
  547. }
  548. }
  549. if (opts.strict) {
  550. src = '"use strict";\n' + src;
  551. }
  552. if (opts.debug) {
  553. console.log(src);
  554. }
  555. try {
  556. if (opts.async) {
  557. // Have to use generated function for this, since in envs without support,
  558. // it breaks in parsing
  559. try {
  560. ctor = (new Function('return (async function(){}).constructor;'))();
  561. }
  562. catch(e) {
  563. if (e instanceof SyntaxError) {
  564. throw new Error('This environment does not support async/await');
  565. }
  566. else {
  567. throw e;
  568. }
  569. }
  570. }
  571. else {
  572. ctor = Function;
  573. }
  574. fn = new ctor(opts.localsName + ', escapeFn, include, rethrow', src);
  575. }
  576. catch(e) {
  577. // istanbul ignore else
  578. if (e instanceof SyntaxError) {
  579. if (opts.filename) {
  580. e.message += ' in ' + opts.filename;
  581. }
  582. e.message += ' while compiling ejs\n\n';
  583. e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n';
  584. e.message += 'https://github.com/RyanZim/EJS-Lint';
  585. if (!e.async) {
  586. e.message += '\n';
  587. e.message += 'Or, if you meant to create an async function, pass async: true as an option.';
  588. }
  589. }
  590. throw e;
  591. }
  592. if (opts.client) {
  593. fn.dependencies = this.dependencies;
  594. return fn;
  595. }
  596. // Return a callable function which will execute the function
  597. // created by the source-code, with the passed data as locals
  598. // Adds a local `include` function which allows full recursive include
  599. var returnedFn = function (data) {
  600. var include = function (path, includeData) {
  601. var d = utils.shallowCopy({}, data);
  602. if (includeData) {
  603. d = utils.shallowCopy(d, includeData);
  604. }
  605. return includeFile(path, opts)(d);
  606. };
  607. return fn.apply(opts.context, [data || {}, escapeFn, include, rethrow]);
  608. };
  609. returnedFn.dependencies = this.dependencies;
  610. return returnedFn;
  611. },
  612. generateSource: function () {
  613. var opts = this.opts;
  614. if (opts.rmWhitespace) {
  615. // Have to use two separate replace here as `^` and `$` operators don't
  616. // work well with `\r` and empty lines don't work well with the `m` flag.
  617. this.templateText =
  618. this.templateText.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
  619. }
  620. // Slurp spaces and tabs before <%_ and after _%>
  621. this.templateText =
  622. this.templateText.replace(/[ \t]*<%_/gm, '<%_').replace(/_%>[ \t]*/gm, '_%>');
  623. var self = this;
  624. var matches = this.parseTemplateText();
  625. var d = this.opts.delimiter;
  626. var o = this.opts.openDelimiter;
  627. var c = this.opts.closeDelimiter;
  628. if (matches && matches.length) {
  629. matches.forEach(function (line, index) {
  630. var opening;
  631. var closing;
  632. var include;
  633. var includeOpts;
  634. var includeObj;
  635. var includeSrc;
  636. // If this is an opening tag, check for closing tags
  637. // FIXME: May end up with some false positives here
  638. // Better to store modes as k/v with openDelimiter + delimiter as key
  639. // Then this can simply check against the map
  640. if ( line.indexOf(o + d) === 0 // If it is a tag
  641. && line.indexOf(o + d + d) !== 0) { // and is not escaped
  642. closing = matches[index + 2];
  643. if (!(closing == d + c || closing == '-' + d + c || closing == '_' + d + c)) {
  644. throw new Error('Could not find matching close tag for "' + line + '".');
  645. }
  646. }
  647. // HACK: backward-compat `include` preprocessor directives
  648. if ((include = line.match(/^\s*include\s+(\S+)/))) {
  649. opening = matches[index - 1];
  650. // Must be in EVAL or RAW mode
  651. if (opening && (opening == o + d || opening == o + d + '-' || opening == o + d + '_')) {
  652. includeOpts = utils.shallowCopy({}, self.opts);
  653. includeObj = includeSource(include[1], includeOpts);
  654. if (self.opts.compileDebug) {
  655. includeSrc =
  656. ' ; (function(){' + '\n'
  657. + ' var __line = 1' + '\n'
  658. + ' , __lines = ' + JSON.stringify(includeObj.template) + '\n'
  659. + ' , __filename = ' + JSON.stringify(includeObj.filename) + ';' + '\n'
  660. + ' try {' + '\n'
  661. + includeObj.source
  662. + ' } catch (e) {' + '\n'
  663. + ' rethrow(e, __lines, __filename, __line, escapeFn);' + '\n'
  664. + ' }' + '\n'
  665. + ' ; }).call(this)' + '\n';
  666. }else{
  667. includeSrc = ' ; (function(){' + '\n' + includeObj.source +
  668. ' ; }).call(this)' + '\n';
  669. }
  670. self.source += includeSrc;
  671. self.dependencies.push(exports.resolveInclude(include[1],
  672. includeOpts.filename));
  673. return;
  674. }
  675. }
  676. self.scanLine(line);
  677. });
  678. }
  679. },
  680. parseTemplateText: function () {
  681. var str = this.templateText;
  682. var pat = this.regex;
  683. var result = pat.exec(str);
  684. var arr = [];
  685. var firstPos;
  686. while (result) {
  687. firstPos = result.index;
  688. if (firstPos !== 0) {
  689. arr.push(str.substring(0, firstPos));
  690. str = str.slice(firstPos);
  691. }
  692. arr.push(result[0]);
  693. str = str.slice(result[0].length);
  694. result = pat.exec(str);
  695. }
  696. if (str) {
  697. arr.push(str);
  698. }
  699. return arr;
  700. },
  701. _addOutput: function (line) {
  702. if (this.truncate) {
  703. // Only replace single leading linebreak in the line after
  704. // -%> tag -- this is the single, trailing linebreak
  705. // after the tag that the truncation mode replaces
  706. // Handle Win / Unix / old Mac linebreaks -- do the \r\n
  707. // combo first in the regex-or
  708. line = line.replace(/^(?:\r\n|\r|\n)/, '');
  709. this.truncate = false;
  710. }
  711. if (!line) {
  712. return line;
  713. }
  714. // Preserve literal slashes
  715. line = line.replace(/\\/g, '\\\\');
  716. // Convert linebreaks
  717. line = line.replace(/\n/g, '\\n');
  718. line = line.replace(/\r/g, '\\r');
  719. // Escape double-quotes
  720. // - this will be the delimiter during execution
  721. line = line.replace(/"/g, '\\"');
  722. this.source += ' ; __append("' + line + '")' + '\n';
  723. },
  724. scanLine: function (line) {
  725. var self = this;
  726. var d = this.opts.delimiter;
  727. var o = this.opts.openDelimiter;
  728. var c = this.opts.closeDelimiter;
  729. var newLineCount = 0;
  730. newLineCount = (line.split('\n').length - 1);
  731. switch (line) {
  732. case o + d:
  733. case o + d + '_':
  734. this.mode = Template.modes.EVAL;
  735. break;
  736. case o + d + '=':
  737. this.mode = Template.modes.ESCAPED;
  738. break;
  739. case o + d + '-':
  740. this.mode = Template.modes.RAW;
  741. break;
  742. case o + d + '#':
  743. this.mode = Template.modes.COMMENT;
  744. break;
  745. case o + d + d:
  746. this.mode = Template.modes.LITERAL;
  747. this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")' + '\n';
  748. break;
  749. case d + d + c:
  750. this.mode = Template.modes.LITERAL;
  751. this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")' + '\n';
  752. break;
  753. case d + c:
  754. case '-' + d + c:
  755. case '_' + d + c:
  756. if (this.mode == Template.modes.LITERAL) {
  757. this._addOutput(line);
  758. }
  759. this.mode = null;
  760. this.truncate = line.indexOf('-') === 0 || line.indexOf('_') === 0;
  761. break;
  762. default:
  763. // In script mode, depends on type of tag
  764. if (this.mode) {
  765. // If '//' is found without a line break, add a line break.
  766. switch (this.mode) {
  767. case Template.modes.EVAL:
  768. case Template.modes.ESCAPED:
  769. case Template.modes.RAW:
  770. if (line.lastIndexOf('//') > line.lastIndexOf('\n')) {
  771. line += '\n';
  772. }
  773. }
  774. switch (this.mode) {
  775. // Just executing code
  776. case Template.modes.EVAL:
  777. this.source += ' ; ' + line + '\n';
  778. break;
  779. // Exec, esc, and output
  780. case Template.modes.ESCAPED:
  781. this.source += ' ; __append(escapeFn(' + stripSemi(line) + '))' + '\n';
  782. break;
  783. // Exec and output
  784. case Template.modes.RAW:
  785. this.source += ' ; __append(' + stripSemi(line) + ')' + '\n';
  786. break;
  787. case Template.modes.COMMENT:
  788. // Do nothing
  789. break;
  790. // Literal <%% mode, append as raw output
  791. case Template.modes.LITERAL:
  792. this._addOutput(line);
  793. break;
  794. }
  795. }
  796. // In string mode, just add the output
  797. else {
  798. this._addOutput(line);
  799. }
  800. }
  801. if (self.opts.compileDebug && newLineCount) {
  802. this.currentLine += newLineCount;
  803. this.source += ' ; __line = ' + this.currentLine + '\n';
  804. }
  805. }
  806. };
  807. /**
  808. * Escape characters reserved in XML.
  809. *
  810. * This is simply an export of {@link module:utils.escapeXML}.
  811. *
  812. * If `markup` is `undefined` or `null`, the empty string is returned.
  813. *
  814. * @param {String} markup Input string
  815. * @return {String} Escaped string
  816. * @public
  817. * @func
  818. * */
  819. exports.escapeXML = utils.escapeXML;
  820. /**
  821. * Express.js support.
  822. *
  823. * This is an alias for {@link module:ejs.renderFile}, in order to support
  824. * Express.js out-of-the-box.
  825. *
  826. * @func
  827. */
  828. exports.__express = exports.renderFile;
  829. // Add require support
  830. /* istanbul ignore else */
  831. if (require.extensions) {
  832. require.extensions['.ejs'] = function (module, flnm) {
  833. var filename = flnm || /* istanbul ignore next */ module.filename;
  834. var options = {
  835. filename: filename,
  836. client: true
  837. };
  838. var template = fileLoader(filename).toString();
  839. var fn = exports.compile(template, options);
  840. module._compile('module.exports = ' + fn.toString() + ';', filename);
  841. };
  842. }
  843. /**
  844. * Version of EJS.
  845. *
  846. * @readonly
  847. * @type {String}
  848. * @public
  849. */
  850. exports.VERSION = _VERSION_STRING;
  851. /**
  852. * Name for detection of EJS.
  853. *
  854. * @readonly
  855. * @type {String}
  856. * @public
  857. */
  858. exports.name = _NAME;
  859. /* istanbul ignore if */
  860. if (typeof window != 'undefined') {
  861. window.ejs = exports;
  862. }
  863. },{"../package.json":6,"./utils":2,"fs":3,"path":4}],2:[function(require,module,exports){
  864. /*
  865. * EJS Embedded JavaScript templates
  866. * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
  867. *
  868. * Licensed under the Apache License, Version 2.0 (the "License");
  869. * you may not use this file except in compliance with the License.
  870. * You may obtain a copy of the License at
  871. *
  872. * http://www.apache.org/licenses/LICENSE-2.0
  873. *
  874. * Unless required by applicable law or agreed to in writing, software
  875. * distributed under the License is distributed on an "AS IS" BASIS,
  876. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  877. * See the License for the specific language governing permissions and
  878. * limitations under the License.
  879. *
  880. */
  881. /**
  882. * Private utility functions
  883. * @module utils
  884. * @private
  885. */
  886. 'use strict';
  887. var regExpChars = /[|\\{}()[\]^$+*?.]/g;
  888. /**
  889. * Escape characters reserved in regular expressions.
  890. *
  891. * If `string` is `undefined` or `null`, the empty string is returned.
  892. *
  893. * @param {String} string Input string
  894. * @return {String} Escaped string
  895. * @static
  896. * @private
  897. */
  898. exports.escapeRegExpChars = function (string) {
  899. // istanbul ignore if
  900. if (!string) {
  901. return '';
  902. }
  903. return String(string).replace(regExpChars, '\\$&');
  904. };
  905. var _ENCODE_HTML_RULES = {
  906. '&': '&amp;',
  907. '<': '&lt;',
  908. '>': '&gt;',
  909. '"': '&#34;',
  910. "'": '&#39;'
  911. };
  912. var _MATCH_HTML = /[&<>'"]/g;
  913. function encode_char(c) {
  914. return _ENCODE_HTML_RULES[c] || c;
  915. }
  916. /**
  917. * Stringified version of constants used by {@link module:utils.escapeXML}.
  918. *
  919. * It is used in the process of generating {@link ClientFunction}s.
  920. *
  921. * @readonly
  922. * @type {String}
  923. */
  924. var escapeFuncStr =
  925. 'var _ENCODE_HTML_RULES = {\n'
  926. + ' "&": "&amp;"\n'
  927. + ' , "<": "&lt;"\n'
  928. + ' , ">": "&gt;"\n'
  929. + ' , \'"\': "&#34;"\n'
  930. + ' , "\'": "&#39;"\n'
  931. + ' }\n'
  932. + ' , _MATCH_HTML = /[&<>\'"]/g;\n'
  933. + 'function encode_char(c) {\n'
  934. + ' return _ENCODE_HTML_RULES[c] || c;\n'
  935. + '};\n';
  936. /**
  937. * Escape characters reserved in XML.
  938. *
  939. * If `markup` is `undefined` or `null`, the empty string is returned.
  940. *
  941. * @implements {EscapeCallback}
  942. * @param {String} markup Input string
  943. * @return {String} Escaped string
  944. * @static
  945. * @private
  946. */
  947. exports.escapeXML = function (markup) {
  948. return markup == undefined
  949. ? ''
  950. : String(markup)
  951. .replace(_MATCH_HTML, encode_char);
  952. };
  953. exports.escapeXML.toString = function () {
  954. return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr;
  955. };
  956. /**
  957. * Naive copy of properties from one object to another.
  958. * Does not recurse into non-scalar properties
  959. * Does not check to see if the property has a value before copying
  960. *
  961. * @param {Object} to Destination object
  962. * @param {Object} from Source object
  963. * @return {Object} Destination object
  964. * @static
  965. * @private
  966. */
  967. exports.shallowCopy = function (to, from) {
  968. from = from || {};
  969. for (var p in from) {
  970. to[p] = from[p];
  971. }
  972. return to;
  973. };
  974. /**
  975. * Naive copy of a list of key names, from one object to another.
  976. * Only copies property if it is actually defined
  977. * Does not recurse into non-scalar properties
  978. *
  979. * @param {Object} to Destination object
  980. * @param {Object} from Source object
  981. * @param {Array} list List of properties to copy
  982. * @return {Object} Destination object
  983. * @static
  984. * @private
  985. */
  986. exports.shallowCopyFromList = function (to, from, list) {
  987. for (var i = 0; i < list.length; i++) {
  988. var p = list[i];
  989. if (typeof from[p] != 'undefined') {
  990. to[p] = from[p];
  991. }
  992. }
  993. return to;
  994. };
  995. /**
  996. * Simple in-process cache implementation. Does not implement limits of any
  997. * sort.
  998. *
  999. * @implements Cache
  1000. * @static
  1001. * @private
  1002. */
  1003. exports.cache = {
  1004. _data: {},
  1005. set: function (key, val) {
  1006. this._data[key] = val;
  1007. },
  1008. get: function (key) {
  1009. return this._data[key];
  1010. },
  1011. remove: function (key) {
  1012. delete this._data[key];
  1013. },
  1014. reset: function () {
  1015. this._data = {};
  1016. }
  1017. };
  1018. },{}],3:[function(require,module,exports){
  1019. },{}],4:[function(require,module,exports){
  1020. (function (process){
  1021. // Copyright Joyent, Inc. and other Node contributors.
  1022. //
  1023. // Permission is hereby granted, free of charge, to any person obtaining a
  1024. // copy of this software and associated documentation files (the
  1025. // "Software"), to deal in the Software without restriction, including
  1026. // without limitation the rights to use, copy, modify, merge, publish,
  1027. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1028. // persons to whom the Software is furnished to do so, subject to the
  1029. // following conditions:
  1030. //
  1031. // The above copyright notice and this permission notice shall be included
  1032. // in all copies or substantial portions of the Software.
  1033. //
  1034. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1035. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1036. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1037. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1038. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1039. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1040. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1041. // resolves . and .. elements in a path array with directory names there
  1042. // must be no slashes, empty elements, or device names (c:\) in the array
  1043. // (so also no leading and trailing slashes - it does not distinguish
  1044. // relative and absolute paths)
  1045. function normalizeArray(parts, allowAboveRoot) {
  1046. // if the path tries to go above the root, `up` ends up > 0
  1047. var up = 0;
  1048. for (var i = parts.length - 1; i >= 0; i--) {
  1049. var last = parts[i];
  1050. if (last === '.') {
  1051. parts.splice(i, 1);
  1052. } else if (last === '..') {
  1053. parts.splice(i, 1);
  1054. up++;
  1055. } else if (up) {
  1056. parts.splice(i, 1);
  1057. up--;
  1058. }
  1059. }
  1060. // if the path is allowed to go above the root, restore leading ..s
  1061. if (allowAboveRoot) {
  1062. for (; up--; up) {
  1063. parts.unshift('..');
  1064. }
  1065. }
  1066. return parts;
  1067. }
  1068. // Split a filename into [root, dir, basename, ext], unix version
  1069. // 'root' is just a slash, or nothing.
  1070. var splitPathRe =
  1071. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  1072. var splitPath = function(filename) {
  1073. return splitPathRe.exec(filename).slice(1);
  1074. };
  1075. // path.resolve([from ...], to)
  1076. // posix version
  1077. exports.resolve = function() {
  1078. var resolvedPath = '',
  1079. resolvedAbsolute = false;
  1080. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  1081. var path = (i >= 0) ? arguments[i] : process.cwd();
  1082. // Skip empty and invalid entries
  1083. if (typeof path !== 'string') {
  1084. throw new TypeError('Arguments to path.resolve must be strings');
  1085. } else if (!path) {
  1086. continue;
  1087. }
  1088. resolvedPath = path + '/' + resolvedPath;
  1089. resolvedAbsolute = path.charAt(0) === '/';
  1090. }
  1091. // At this point the path should be resolved to a full absolute path, but
  1092. // handle relative paths to be safe (might happen when process.cwd() fails)
  1093. // Normalize the path
  1094. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  1095. return !!p;
  1096. }), !resolvedAbsolute).join('/');
  1097. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  1098. };
  1099. // path.normalize(path)
  1100. // posix version
  1101. exports.normalize = function(path) {
  1102. var isAbsolute = exports.isAbsolute(path),
  1103. trailingSlash = substr(path, -1) === '/';
  1104. // Normalize the path
  1105. path = normalizeArray(filter(path.split('/'), function(p) {
  1106. return !!p;
  1107. }), !isAbsolute).join('/');
  1108. if (!path && !isAbsolute) {
  1109. path = '.';
  1110. }
  1111. if (path && trailingSlash) {
  1112. path += '/';
  1113. }
  1114. return (isAbsolute ? '/' : '') + path;
  1115. };
  1116. // posix version
  1117. exports.isAbsolute = function(path) {
  1118. return path.charAt(0) === '/';
  1119. };
  1120. // posix version
  1121. exports.join = function() {
  1122. var paths = Array.prototype.slice.call(arguments, 0);
  1123. return exports.normalize(filter(paths, function(p, index) {
  1124. if (typeof p !== 'string') {
  1125. throw new TypeError('Arguments to path.join must be strings');
  1126. }
  1127. return p;
  1128. }).join('/'));
  1129. };
  1130. // path.relative(from, to)
  1131. // posix version
  1132. exports.relative = function(from, to) {
  1133. from = exports.resolve(from).substr(1);
  1134. to = exports.resolve(to).substr(1);
  1135. function trim(arr) {
  1136. var start = 0;
  1137. for (; start < arr.length; start++) {
  1138. if (arr[start] !== '') break;
  1139. }
  1140. var end = arr.length - 1;
  1141. for (; end >= 0; end--) {
  1142. if (arr[end] !== '') break;
  1143. }
  1144. if (start > end) return [];
  1145. return arr.slice(start, end - start + 1);
  1146. }
  1147. var fromParts = trim(from.split('/'));
  1148. var toParts = trim(to.split('/'));
  1149. var length = Math.min(fromParts.length, toParts.length);
  1150. var samePartsLength = length;
  1151. for (var i = 0; i < length; i++) {
  1152. if (fromParts[i] !== toParts[i]) {
  1153. samePartsLength = i;
  1154. break;
  1155. }
  1156. }
  1157. var outputParts = [];
  1158. for (var i = samePartsLength; i < fromParts.length; i++) {
  1159. outputParts.push('..');
  1160. }
  1161. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  1162. return outputParts.join('/');
  1163. };
  1164. exports.sep = '/';
  1165. exports.delimiter = ':';
  1166. exports.dirname = function(path) {
  1167. var result = splitPath(path),
  1168. root = result[0],
  1169. dir = result[1];
  1170. if (!root && !dir) {
  1171. // No dirname whatsoever
  1172. return '.';
  1173. }
  1174. if (dir) {
  1175. // It has a dirname, strip trailing slash
  1176. dir = dir.substr(0, dir.length - 1);
  1177. }
  1178. return root + dir;
  1179. };
  1180. exports.basename = function(path, ext) {
  1181. var f = splitPath(path)[2];
  1182. // TODO: make this comparison case-insensitive on windows?
  1183. if (ext && f.substr(-1 * ext.length) === ext) {
  1184. f = f.substr(0, f.length - ext.length);
  1185. }
  1186. return f;
  1187. };
  1188. exports.extname = function(path) {
  1189. return splitPath(path)[3];
  1190. };
  1191. function filter (xs, f) {
  1192. if (xs.filter) return xs.filter(f);
  1193. var res = [];
  1194. for (var i = 0; i < xs.length; i++) {
  1195. if (f(xs[i], i, xs)) res.push(xs[i]);
  1196. }
  1197. return res;
  1198. }
  1199. // String.prototype.substr - negative index don't work in IE8
  1200. var substr = 'ab'.substr(-1) === 'b'
  1201. ? function (str, start, len) { return str.substr(start, len) }
  1202. : function (str, start, len) {
  1203. if (start < 0) start = str.length + start;
  1204. return str.substr(start, len);
  1205. }
  1206. ;
  1207. }).call(this,require('_process'))
  1208. },{"_process":5}],5:[function(require,module,exports){
  1209. // shim for using process in browser
  1210. var process = module.exports = {};
  1211. // cached from whatever global is present so that test runners that stub it
  1212. // don't break things. But we need to wrap it in a try catch in case it is
  1213. // wrapped in strict mode code which doesn't define any globals. It's inside a
  1214. // function because try/catches deoptimize in certain engines.
  1215. var cachedSetTimeout;
  1216. var cachedClearTimeout;
  1217. function defaultSetTimout() {
  1218. throw new Error('setTimeout has not been defined');
  1219. }
  1220. function defaultClearTimeout () {
  1221. throw new Error('clearTimeout has not been defined');
  1222. }
  1223. (function () {
  1224. try {
  1225. if (typeof setTimeout === 'function') {
  1226. cachedSetTimeout = setTimeout;
  1227. } else {
  1228. cachedSetTimeout = defaultSetTimout;
  1229. }
  1230. } catch (e) {
  1231. cachedSetTimeout = defaultSetTimout;
  1232. }
  1233. try {
  1234. if (typeof clearTimeout === 'function') {
  1235. cachedClearTimeout = clearTimeout;
  1236. } else {
  1237. cachedClearTimeout = defaultClearTimeout;
  1238. }
  1239. } catch (e) {
  1240. cachedClearTimeout = defaultClearTimeout;
  1241. }
  1242. } ())
  1243. function runTimeout(fun) {
  1244. if (cachedSetTimeout === setTimeout) {
  1245. //normal enviroments in sane situations
  1246. return setTimeout(fun, 0);
  1247. }
  1248. // if setTimeout wasn't available but was latter defined
  1249. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  1250. cachedSetTimeout = setTimeout;
  1251. return setTimeout(fun, 0);
  1252. }
  1253. try {
  1254. // when when somebody has screwed with setTimeout but no I.E. maddness
  1255. return cachedSetTimeout(fun, 0);
  1256. } catch(e){
  1257. try {
  1258. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  1259. return cachedSetTimeout.call(null, fun, 0);
  1260. } catch(e){
  1261. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  1262. return cachedSetTimeout.call(this, fun, 0);
  1263. }
  1264. }
  1265. }
  1266. function runClearTimeout(marker) {
  1267. if (cachedClearTimeout === clearTimeout) {
  1268. //normal enviroments in sane situations
  1269. return clearTimeout(marker);
  1270. }
  1271. // if clearTimeout wasn't available but was latter defined
  1272. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  1273. cachedClearTimeout = clearTimeout;
  1274. return clearTimeout(marker);
  1275. }
  1276. try {
  1277. // when when somebody has screwed with setTimeout but no I.E. maddness
  1278. return cachedClearTimeout(marker);
  1279. } catch (e){
  1280. try {
  1281. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  1282. return cachedClearTimeout.call(null, marker);
  1283. } catch (e){
  1284. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  1285. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  1286. return cachedClearTimeout.call(this, marker);
  1287. }
  1288. }
  1289. }
  1290. var queue = [];
  1291. var draining = false;
  1292. var currentQueue;
  1293. var queueIndex = -1;
  1294. function cleanUpNextTick() {
  1295. if (!draining || !currentQueue) {
  1296. return;
  1297. }
  1298. draining = false;
  1299. if (currentQueue.length) {
  1300. queue = currentQueue.concat(queue);
  1301. } else {
  1302. queueIndex = -1;
  1303. }
  1304. if (queue.length) {
  1305. drainQueue();
  1306. }
  1307. }
  1308. function drainQueue() {
  1309. if (draining) {
  1310. return;
  1311. }
  1312. var timeout = runTimeout(cleanUpNextTick);
  1313. draining = true;
  1314. var len = queue.length;
  1315. while(len) {
  1316. currentQueue = queue;
  1317. queue = [];
  1318. while (++queueIndex < len) {
  1319. if (currentQueue) {
  1320. currentQueue[queueIndex].run();
  1321. }
  1322. }
  1323. queueIndex = -1;
  1324. len = queue.length;
  1325. }
  1326. currentQueue = null;
  1327. draining = false;
  1328. runClearTimeout(timeout);
  1329. }
  1330. process.nextTick = function (fun) {
  1331. var args = new Array(arguments.length - 1);
  1332. if (arguments.length > 1) {
  1333. for (var i = 1; i < arguments.length; i++) {
  1334. args[i - 1] = arguments[i];
  1335. }
  1336. }
  1337. queue.push(new Item(fun, args));
  1338. if (queue.length === 1 && !draining) {
  1339. runTimeout(drainQueue);
  1340. }
  1341. };
  1342. // v8 likes predictible objects
  1343. function Item(fun, array) {
  1344. this.fun = fun;
  1345. this.array = array;
  1346. }
  1347. Item.prototype.run = function () {
  1348. this.fun.apply(null, this.array);
  1349. };
  1350. process.title = 'browser';
  1351. process.browser = true;
  1352. process.env = {};
  1353. process.argv = [];
  1354. process.version = ''; // empty string to avoid regexp issues
  1355. process.versions = {};
  1356. function noop() {}
  1357. process.on = noop;
  1358. process.addListener = noop;
  1359. process.once = noop;
  1360. process.off = noop;
  1361. process.removeListener = noop;
  1362. process.removeAllListeners = noop;
  1363. process.emit = noop;
  1364. process.prependListener = noop;
  1365. process.prependOnceListener = noop;
  1366. process.listeners = function (name) { return [] }
  1367. process.binding = function (name) {
  1368. throw new Error('process.binding is not supported');
  1369. };
  1370. process.cwd = function () { return '/' };
  1371. process.chdir = function (dir) {
  1372. throw new Error('process.chdir is not supported');
  1373. };
  1374. process.umask = function() { return 0; };
  1375. },{}],6:[function(require,module,exports){
  1376. module.exports={
  1377. "name": "ejs",
  1378. "description": "Embedded JavaScript templates",
  1379. "keywords": [
  1380. "template",
  1381. "engine",
  1382. "ejs"
  1383. ],
  1384. "version": "2.6.1",
  1385. "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
  1386. "contributors": [
  1387. "Timothy Gu <timothygu99@gmail.com> (https://timothygu.github.io)"
  1388. ],
  1389. "license": "Apache-2.0",
  1390. "main": "./lib/ejs.js",
  1391. "repository": {
  1392. "type": "git",
  1393. "url": "git://github.com/mde/ejs.git"
  1394. },
  1395. "bugs": "https://github.com/mde/ejs/issues",
  1396. "homepage": "https://github.com/mde/ejs",
  1397. "dependencies": {},
  1398. "devDependencies": {
  1399. "browserify": "^13.1.1",
  1400. "eslint": "^4.14.0",
  1401. "git-directory-deploy": "^1.5.1",
  1402. "istanbul": "~0.4.3",
  1403. "jake": "^8.0.16",
  1404. "jsdoc": "^3.4.0",
  1405. "lru-cache": "^4.0.1",
  1406. "mocha": "^5.0.5",
  1407. "uglify-js": "^3.3.16"
  1408. },
  1409. "engines": {
  1410. "node": ">=0.10.0"
  1411. },
  1412. "scripts": {
  1413. "test": "jake test",
  1414. "lint": "eslint \"**/*.js\" Jakefile",
  1415. "coverage": "istanbul cover node_modules/mocha/bin/_mocha",
  1416. "doc": "jake doc",
  1417. "devdoc": "jake doc[dev]"
  1418. }
  1419. }
  1420. },{}]},{},[1])(1)
  1421. });