ejs.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  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. console.log('Deprecated: this API will go away in EJS v2.8');
  834. var filename = flnm || /* istanbul ignore next */ module.filename;
  835. var options = {
  836. filename: filename,
  837. client: true
  838. };
  839. var template = fileLoader(filename).toString();
  840. var fn = exports.compile(template, options);
  841. module._compile('module.exports = ' + fn.toString() + ';', filename);
  842. };
  843. }
  844. /**
  845. * Version of EJS.
  846. *
  847. * @readonly
  848. * @type {String}
  849. * @public
  850. */
  851. exports.VERSION = _VERSION_STRING;
  852. /**
  853. * Name for detection of EJS.
  854. *
  855. * @readonly
  856. * @type {String}
  857. * @public
  858. */
  859. exports.name = _NAME;
  860. /* istanbul ignore if */
  861. if (typeof window != 'undefined') {
  862. window.ejs = exports;
  863. }
  864. },{"../package.json":6,"./utils":2,"fs":3,"path":4}],2:[function(require,module,exports){
  865. /*
  866. * EJS Embedded JavaScript templates
  867. * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
  868. *
  869. * Licensed under the Apache License, Version 2.0 (the "License");
  870. * you may not use this file except in compliance with the License.
  871. * You may obtain a copy of the License at
  872. *
  873. * http://www.apache.org/licenses/LICENSE-2.0
  874. *
  875. * Unless required by applicable law or agreed to in writing, software
  876. * distributed under the License is distributed on an "AS IS" BASIS,
  877. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  878. * See the License for the specific language governing permissions and
  879. * limitations under the License.
  880. *
  881. */
  882. /**
  883. * Private utility functions
  884. * @module utils
  885. * @private
  886. */
  887. 'use strict';
  888. var regExpChars = /[|\\{}()[\]^$+*?.]/g;
  889. /**
  890. * Escape characters reserved in regular expressions.
  891. *
  892. * If `string` is `undefined` or `null`, the empty string is returned.
  893. *
  894. * @param {String} string Input string
  895. * @return {String} Escaped string
  896. * @static
  897. * @private
  898. */
  899. exports.escapeRegExpChars = function (string) {
  900. // istanbul ignore if
  901. if (!string) {
  902. return '';
  903. }
  904. return String(string).replace(regExpChars, '\\$&');
  905. };
  906. var _ENCODE_HTML_RULES = {
  907. '&': '&amp;',
  908. '<': '&lt;',
  909. '>': '&gt;',
  910. '"': '&#34;',
  911. "'": '&#39;'
  912. };
  913. var _MATCH_HTML = /[&<>'"]/g;
  914. function encode_char(c) {
  915. return _ENCODE_HTML_RULES[c] || c;
  916. }
  917. /**
  918. * Stringified version of constants used by {@link module:utils.escapeXML}.
  919. *
  920. * It is used in the process of generating {@link ClientFunction}s.
  921. *
  922. * @readonly
  923. * @type {String}
  924. */
  925. var escapeFuncStr =
  926. 'var _ENCODE_HTML_RULES = {\n'
  927. + ' "&": "&amp;"\n'
  928. + ' , "<": "&lt;"\n'
  929. + ' , ">": "&gt;"\n'
  930. + ' , \'"\': "&#34;"\n'
  931. + ' , "\'": "&#39;"\n'
  932. + ' }\n'
  933. + ' , _MATCH_HTML = /[&<>\'"]/g;\n'
  934. + 'function encode_char(c) {\n'
  935. + ' return _ENCODE_HTML_RULES[c] || c;\n'
  936. + '};\n';
  937. /**
  938. * Escape characters reserved in XML.
  939. *
  940. * If `markup` is `undefined` or `null`, the empty string is returned.
  941. *
  942. * @implements {EscapeCallback}
  943. * @param {String} markup Input string
  944. * @return {String} Escaped string
  945. * @static
  946. * @private
  947. */
  948. exports.escapeXML = function (markup) {
  949. return markup == undefined
  950. ? ''
  951. : String(markup)
  952. .replace(_MATCH_HTML, encode_char);
  953. };
  954. exports.escapeXML.toString = function () {
  955. return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr;
  956. };
  957. /**
  958. * Naive copy of properties from one object to another.
  959. * Does not recurse into non-scalar properties
  960. * Does not check to see if the property has a value before copying
  961. *
  962. * @param {Object} to Destination object
  963. * @param {Object} from Source object
  964. * @return {Object} Destination object
  965. * @static
  966. * @private
  967. */
  968. exports.shallowCopy = function (to, from) {
  969. from = from || {};
  970. for (var p in from) {
  971. to[p] = from[p];
  972. }
  973. return to;
  974. };
  975. /**
  976. * Naive copy of a list of key names, from one object to another.
  977. * Only copies property if it is actually defined
  978. * Does not recurse into non-scalar properties
  979. *
  980. * @param {Object} to Destination object
  981. * @param {Object} from Source object
  982. * @param {Array} list List of properties to copy
  983. * @return {Object} Destination object
  984. * @static
  985. * @private
  986. */
  987. exports.shallowCopyFromList = function (to, from, list) {
  988. for (var i = 0; i < list.length; i++) {
  989. var p = list[i];
  990. if (typeof from[p] != 'undefined') {
  991. to[p] = from[p];
  992. }
  993. }
  994. return to;
  995. };
  996. /**
  997. * Simple in-process cache implementation. Does not implement limits of any
  998. * sort.
  999. *
  1000. * @implements Cache
  1001. * @static
  1002. * @private
  1003. */
  1004. exports.cache = {
  1005. _data: {},
  1006. set: function (key, val) {
  1007. this._data[key] = val;
  1008. },
  1009. get: function (key) {
  1010. return this._data[key];
  1011. },
  1012. remove: function (key) {
  1013. delete this._data[key];
  1014. },
  1015. reset: function () {
  1016. this._data = {};
  1017. }
  1018. };
  1019. },{}],3:[function(require,module,exports){
  1020. },{}],4:[function(require,module,exports){
  1021. (function (process){
  1022. // Copyright Joyent, Inc. and other Node contributors.
  1023. //
  1024. // Permission is hereby granted, free of charge, to any person obtaining a
  1025. // copy of this software and associated documentation files (the
  1026. // "Software"), to deal in the Software without restriction, including
  1027. // without limitation the rights to use, copy, modify, merge, publish,
  1028. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1029. // persons to whom the Software is furnished to do so, subject to the
  1030. // following conditions:
  1031. //
  1032. // The above copyright notice and this permission notice shall be included
  1033. // in all copies or substantial portions of the Software.
  1034. //
  1035. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1036. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1037. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1038. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1039. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1040. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1041. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1042. // resolves . and .. elements in a path array with directory names there
  1043. // must be no slashes, empty elements, or device names (c:\) in the array
  1044. // (so also no leading and trailing slashes - it does not distinguish
  1045. // relative and absolute paths)
  1046. function normalizeArray(parts, allowAboveRoot) {
  1047. // if the path tries to go above the root, `up` ends up > 0
  1048. var up = 0;
  1049. for (var i = parts.length - 1; i >= 0; i--) {
  1050. var last = parts[i];
  1051. if (last === '.') {
  1052. parts.splice(i, 1);
  1053. } else if (last === '..') {
  1054. parts.splice(i, 1);
  1055. up++;
  1056. } else if (up) {
  1057. parts.splice(i, 1);
  1058. up--;
  1059. }
  1060. }
  1061. // if the path is allowed to go above the root, restore leading ..s
  1062. if (allowAboveRoot) {
  1063. for (; up--; up) {
  1064. parts.unshift('..');
  1065. }
  1066. }
  1067. return parts;
  1068. }
  1069. // Split a filename into [root, dir, basename, ext], unix version
  1070. // 'root' is just a slash, or nothing.
  1071. var splitPathRe =
  1072. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  1073. var splitPath = function(filename) {
  1074. return splitPathRe.exec(filename).slice(1);
  1075. };
  1076. // path.resolve([from ...], to)
  1077. // posix version
  1078. exports.resolve = function() {
  1079. var resolvedPath = '',
  1080. resolvedAbsolute = false;
  1081. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  1082. var path = (i >= 0) ? arguments[i] : process.cwd();
  1083. // Skip empty and invalid entries
  1084. if (typeof path !== 'string') {
  1085. throw new TypeError('Arguments to path.resolve must be strings');
  1086. } else if (!path) {
  1087. continue;
  1088. }
  1089. resolvedPath = path + '/' + resolvedPath;
  1090. resolvedAbsolute = path.charAt(0) === '/';
  1091. }
  1092. // At this point the path should be resolved to a full absolute path, but
  1093. // handle relative paths to be safe (might happen when process.cwd() fails)
  1094. // Normalize the path
  1095. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  1096. return !!p;
  1097. }), !resolvedAbsolute).join('/');
  1098. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  1099. };
  1100. // path.normalize(path)
  1101. // posix version
  1102. exports.normalize = function(path) {
  1103. var isAbsolute = exports.isAbsolute(path),
  1104. trailingSlash = substr(path, -1) === '/';
  1105. // Normalize the path
  1106. path = normalizeArray(filter(path.split('/'), function(p) {
  1107. return !!p;
  1108. }), !isAbsolute).join('/');
  1109. if (!path && !isAbsolute) {
  1110. path = '.';
  1111. }
  1112. if (path && trailingSlash) {
  1113. path += '/';
  1114. }
  1115. return (isAbsolute ? '/' : '') + path;
  1116. };
  1117. // posix version
  1118. exports.isAbsolute = function(path) {
  1119. return path.charAt(0) === '/';
  1120. };
  1121. // posix version
  1122. exports.join = function() {
  1123. var paths = Array.prototype.slice.call(arguments, 0);
  1124. return exports.normalize(filter(paths, function(p, index) {
  1125. if (typeof p !== 'string') {
  1126. throw new TypeError('Arguments to path.join must be strings');
  1127. }
  1128. return p;
  1129. }).join('/'));
  1130. };
  1131. // path.relative(from, to)
  1132. // posix version
  1133. exports.relative = function(from, to) {
  1134. from = exports.resolve(from).substr(1);
  1135. to = exports.resolve(to).substr(1);
  1136. function trim(arr) {
  1137. var start = 0;
  1138. for (; start < arr.length; start++) {
  1139. if (arr[start] !== '') break;
  1140. }
  1141. var end = arr.length - 1;
  1142. for (; end >= 0; end--) {
  1143. if (arr[end] !== '') break;
  1144. }
  1145. if (start > end) return [];
  1146. return arr.slice(start, end - start + 1);
  1147. }
  1148. var fromParts = trim(from.split('/'));
  1149. var toParts = trim(to.split('/'));
  1150. var length = Math.min(fromParts.length, toParts.length);
  1151. var samePartsLength = length;
  1152. for (var i = 0; i < length; i++) {
  1153. if (fromParts[i] !== toParts[i]) {
  1154. samePartsLength = i;
  1155. break;
  1156. }
  1157. }
  1158. var outputParts = [];
  1159. for (var i = samePartsLength; i < fromParts.length; i++) {
  1160. outputParts.push('..');
  1161. }
  1162. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  1163. return outputParts.join('/');
  1164. };
  1165. exports.sep = '/';
  1166. exports.delimiter = ':';
  1167. exports.dirname = function(path) {
  1168. var result = splitPath(path),
  1169. root = result[0],
  1170. dir = result[1];
  1171. if (!root && !dir) {
  1172. // No dirname whatsoever
  1173. return '.';
  1174. }
  1175. if (dir) {
  1176. // It has a dirname, strip trailing slash
  1177. dir = dir.substr(0, dir.length - 1);
  1178. }
  1179. return root + dir;
  1180. };
  1181. exports.basename = function(path, ext) {
  1182. var f = splitPath(path)[2];
  1183. // TODO: make this comparison case-insensitive on windows?
  1184. if (ext && f.substr(-1 * ext.length) === ext) {
  1185. f = f.substr(0, f.length - ext.length);
  1186. }
  1187. return f;
  1188. };
  1189. exports.extname = function(path) {
  1190. return splitPath(path)[3];
  1191. };
  1192. function filter (xs, f) {
  1193. if (xs.filter) return xs.filter(f);
  1194. var res = [];
  1195. for (var i = 0; i < xs.length; i++) {
  1196. if (f(xs[i], i, xs)) res.push(xs[i]);
  1197. }
  1198. return res;
  1199. }
  1200. // String.prototype.substr - negative index don't work in IE8
  1201. var substr = 'ab'.substr(-1) === 'b'
  1202. ? function (str, start, len) { return str.substr(start, len) }
  1203. : function (str, start, len) {
  1204. if (start < 0) start = str.length + start;
  1205. return str.substr(start, len);
  1206. }
  1207. ;
  1208. }).call(this,require('_process'))
  1209. },{"_process":5}],5:[function(require,module,exports){
  1210. // shim for using process in browser
  1211. var process = module.exports = {};
  1212. // cached from whatever global is present so that test runners that stub it
  1213. // don't break things. But we need to wrap it in a try catch in case it is
  1214. // wrapped in strict mode code which doesn't define any globals. It's inside a
  1215. // function because try/catches deoptimize in certain engines.
  1216. var cachedSetTimeout;
  1217. var cachedClearTimeout;
  1218. function defaultSetTimout() {
  1219. throw new Error('setTimeout has not been defined');
  1220. }
  1221. function defaultClearTimeout () {
  1222. throw new Error('clearTimeout has not been defined');
  1223. }
  1224. (function () {
  1225. try {
  1226. if (typeof setTimeout === 'function') {
  1227. cachedSetTimeout = setTimeout;
  1228. } else {
  1229. cachedSetTimeout = defaultSetTimout;
  1230. }
  1231. } catch (e) {
  1232. cachedSetTimeout = defaultSetTimout;
  1233. }
  1234. try {
  1235. if (typeof clearTimeout === 'function') {
  1236. cachedClearTimeout = clearTimeout;
  1237. } else {
  1238. cachedClearTimeout = defaultClearTimeout;
  1239. }
  1240. } catch (e) {
  1241. cachedClearTimeout = defaultClearTimeout;
  1242. }
  1243. } ())
  1244. function runTimeout(fun) {
  1245. if (cachedSetTimeout === setTimeout) {
  1246. //normal enviroments in sane situations
  1247. return setTimeout(fun, 0);
  1248. }
  1249. // if setTimeout wasn't available but was latter defined
  1250. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  1251. cachedSetTimeout = setTimeout;
  1252. return setTimeout(fun, 0);
  1253. }
  1254. try {
  1255. // when when somebody has screwed with setTimeout but no I.E. maddness
  1256. return cachedSetTimeout(fun, 0);
  1257. } catch(e){
  1258. try {
  1259. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  1260. return cachedSetTimeout.call(null, fun, 0);
  1261. } catch(e){
  1262. // 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
  1263. return cachedSetTimeout.call(this, fun, 0);
  1264. }
  1265. }
  1266. }
  1267. function runClearTimeout(marker) {
  1268. if (cachedClearTimeout === clearTimeout) {
  1269. //normal enviroments in sane situations
  1270. return clearTimeout(marker);
  1271. }
  1272. // if clearTimeout wasn't available but was latter defined
  1273. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  1274. cachedClearTimeout = clearTimeout;
  1275. return clearTimeout(marker);
  1276. }
  1277. try {
  1278. // when when somebody has screwed with setTimeout but no I.E. maddness
  1279. return cachedClearTimeout(marker);
  1280. } catch (e){
  1281. try {
  1282. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  1283. return cachedClearTimeout.call(null, marker);
  1284. } catch (e){
  1285. // 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.
  1286. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  1287. return cachedClearTimeout.call(this, marker);
  1288. }
  1289. }
  1290. }
  1291. var queue = [];
  1292. var draining = false;
  1293. var currentQueue;
  1294. var queueIndex = -1;
  1295. function cleanUpNextTick() {
  1296. if (!draining || !currentQueue) {
  1297. return;
  1298. }
  1299. draining = false;
  1300. if (currentQueue.length) {
  1301. queue = currentQueue.concat(queue);
  1302. } else {
  1303. queueIndex = -1;
  1304. }
  1305. if (queue.length) {
  1306. drainQueue();
  1307. }
  1308. }
  1309. function drainQueue() {
  1310. if (draining) {
  1311. return;
  1312. }
  1313. var timeout = runTimeout(cleanUpNextTick);
  1314. draining = true;
  1315. var len = queue.length;
  1316. while(len) {
  1317. currentQueue = queue;
  1318. queue = [];
  1319. while (++queueIndex < len) {
  1320. if (currentQueue) {
  1321. currentQueue[queueIndex].run();
  1322. }
  1323. }
  1324. queueIndex = -1;
  1325. len = queue.length;
  1326. }
  1327. currentQueue = null;
  1328. draining = false;
  1329. runClearTimeout(timeout);
  1330. }
  1331. process.nextTick = function (fun) {
  1332. var args = new Array(arguments.length - 1);
  1333. if (arguments.length > 1) {
  1334. for (var i = 1; i < arguments.length; i++) {
  1335. args[i - 1] = arguments[i];
  1336. }
  1337. }
  1338. queue.push(new Item(fun, args));
  1339. if (queue.length === 1 && !draining) {
  1340. runTimeout(drainQueue);
  1341. }
  1342. };
  1343. // v8 likes predictible objects
  1344. function Item(fun, array) {
  1345. this.fun = fun;
  1346. this.array = array;
  1347. }
  1348. Item.prototype.run = function () {
  1349. this.fun.apply(null, this.array);
  1350. };
  1351. process.title = 'browser';
  1352. process.browser = true;
  1353. process.env = {};
  1354. process.argv = [];
  1355. process.version = ''; // empty string to avoid regexp issues
  1356. process.versions = {};
  1357. function noop() {}
  1358. process.on = noop;
  1359. process.addListener = noop;
  1360. process.once = noop;
  1361. process.off = noop;
  1362. process.removeListener = noop;
  1363. process.removeAllListeners = noop;
  1364. process.emit = noop;
  1365. process.prependListener = noop;
  1366. process.prependOnceListener = noop;
  1367. process.listeners = function (name) { return [] }
  1368. process.binding = function (name) {
  1369. throw new Error('process.binding is not supported');
  1370. };
  1371. process.cwd = function () { return '/' };
  1372. process.chdir = function (dir) {
  1373. throw new Error('process.chdir is not supported');
  1374. };
  1375. process.umask = function() { return 0; };
  1376. },{}],6:[function(require,module,exports){
  1377. module.exports={
  1378. "name": "ejs",
  1379. "description": "Embedded JavaScript templates",
  1380. "keywords": [
  1381. "template",
  1382. "engine",
  1383. "ejs"
  1384. ],
  1385. "version": "2.7.0",
  1386. "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
  1387. "contributors": [
  1388. "Timothy Gu <timothygu99@gmail.com> (https://timothygu.github.io)"
  1389. ],
  1390. "license": "Apache-2.0",
  1391. "main": "./lib/ejs.js",
  1392. "repository": {
  1393. "type": "git",
  1394. "url": "git://github.com/mde/ejs.git"
  1395. },
  1396. "bugs": "https://github.com/mde/ejs/issues",
  1397. "homepage": "https://github.com/mde/ejs",
  1398. "dependencies": {},
  1399. "devDependencies": {
  1400. "browserify": "^13.1.1",
  1401. "eslint": "^4.14.0",
  1402. "git-directory-deploy": "^1.5.1",
  1403. "istanbul": "~0.4.3",
  1404. "jake": "^8.0.16",
  1405. "jsdoc": "^3.4.0",
  1406. "lru-cache": "^4.0.1",
  1407. "mocha": "^5.0.5",
  1408. "uglify-js": "^3.3.16"
  1409. },
  1410. "engines": {
  1411. "node": ">=0.10.0"
  1412. },
  1413. "scripts": {
  1414. "test": "jake test",
  1415. "lint": "eslint \"**/*.js\" Jakefile",
  1416. "coverage": "istanbul cover node_modules/mocha/bin/_mocha",
  1417. "doc": "jake doc",
  1418. "devdoc": "jake doc[dev]"
  1419. }
  1420. }
  1421. },{}]},{},[1])(1)
  1422. });