@kosatyi/ejs 0.0.110 → 0.0.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,68 @@
1
1
  'use strict';
2
2
 
3
+ function _assertClassBrand(e, t, n) {
4
+ if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
5
+ throw new TypeError("Private element is not present on this object");
6
+ }
7
+ function _checkPrivateRedeclaration(e, t) {
8
+ if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
9
+ }
10
+ function _classPrivateFieldGet2(s, a) {
11
+ return s.get(_assertClassBrand(s, a));
12
+ }
13
+ function _classPrivateFieldInitSpec(e, t, a) {
14
+ _checkPrivateRedeclaration(e, t), t.set(e, a);
15
+ }
16
+ function _classPrivateFieldSet2(s, a, r) {
17
+ return s.set(_assertClassBrand(s, a), r), r;
18
+ }
19
+ function _classPrivateMethodInitSpec(e, a) {
20
+ _checkPrivateRedeclaration(e, a), a.add(e);
21
+ }
22
+ function _defineProperty(e, r, t) {
23
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
24
+ value: t,
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true
28
+ }) : e[r] = t, e;
29
+ }
30
+ function ownKeys(e, r) {
31
+ var t = Object.keys(e);
32
+ if (Object.getOwnPropertySymbols) {
33
+ var o = Object.getOwnPropertySymbols(e);
34
+ r && (o = o.filter(function (r) {
35
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
36
+ })), t.push.apply(t, o);
37
+ }
38
+ return t;
39
+ }
40
+ function _objectSpread2(e) {
41
+ for (var r = 1; r < arguments.length; r++) {
42
+ var t = null != arguments[r] ? arguments[r] : {};
43
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
44
+ _defineProperty(e, r, t[r]);
45
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
46
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
47
+ });
48
+ }
49
+ return e;
50
+ }
51
+ function _toPrimitive(t, r) {
52
+ if ("object" != typeof t || !t) return t;
53
+ var e = t[Symbol.toPrimitive];
54
+ if (void 0 !== e) {
55
+ var i = e.call(t, r);
56
+ if ("object" != typeof i) return i;
57
+ throw new TypeError("@@toPrimitive must return a primitive value.");
58
+ }
59
+ return ("string" === r ? String : Number)(t);
60
+ }
61
+ function _toPropertyKey(t) {
62
+ var i = _toPrimitive(t, "string");
63
+ return "symbol" == typeof i ? i : i + "";
64
+ }
65
+
3
66
  /**
4
67
  * @type {EjsConfig}
5
68
  */
@@ -46,7 +109,7 @@ const isArrayOfVariables = value => {
46
109
  if (!isArray(value)) return false;
47
110
  return value.filter(name => {
48
111
  const valid = jsVariableName.test(name);
49
- if (valid === false) console.log(`ejsConfig.globals: expected '${name}' to be valid variable name --> skipped`);
112
+ if (valid === false) console.log("ejsConfig.globals: expected '".concat(name, "' to be valid variable name --> skipped"));
50
113
  return valid;
51
114
  });
52
115
  };
@@ -125,9 +188,7 @@ const each = (object, callback) => {
125
188
  }
126
189
  };
127
190
  const omit = (object, list) => {
128
- const result = {
129
- ...object
130
- };
191
+ const result = _objectSpread2({}, object);
131
192
  for (const key of list) {
132
193
  delete result[key];
133
194
  }
@@ -165,50 +226,56 @@ const error = (code, content) => {
165
226
  throw new EjsError(code, content);
166
227
  };
167
228
 
229
+ var _path$1 = /*#__PURE__*/new WeakMap();
230
+ var _resolver = /*#__PURE__*/new WeakMap();
231
+ var _cache$2 = /*#__PURE__*/new WeakMap();
232
+ var _compiler$1 = /*#__PURE__*/new WeakMap();
233
+ var _EjsTemplate_brand = /*#__PURE__*/new WeakSet();
168
234
  class EjsTemplate {
169
- #path;
170
- #resolver;
171
- #cache;
172
- #compiler;
173
- static exports = ['configure', 'get'];
174
235
  constructor(options, cache, compiler) {
236
+ _classPrivateMethodInitSpec(this, _EjsTemplate_brand);
237
+ _classPrivateFieldInitSpec(this, _path$1, void 0);
238
+ _classPrivateFieldInitSpec(this, _resolver, void 0);
239
+ _classPrivateFieldInitSpec(this, _cache$2, void 0);
240
+ _classPrivateFieldInitSpec(this, _compiler$1, void 0);
175
241
  bindContext(this, this.constructor.exports);
176
- this.#cache = cache;
177
- this.#compiler = compiler;
178
- this.configure(options ?? {});
242
+ _classPrivateFieldSet2(_cache$2, this, cache);
243
+ _classPrivateFieldSet2(_compiler$1, this, compiler);
244
+ this.configure(options !== null && options !== void 0 ? options : {});
179
245
  }
180
246
  configure(options) {
181
- this.#path = options.path;
247
+ _classPrivateFieldSet2(_path$1, this, options.path);
182
248
  if (isFunction(options.resolver)) {
183
- this.#resolver = options.resolver;
184
- }
185
- }
186
- #resolve(template) {
187
- const cached = this.#cache.get(template);
188
- if (cached instanceof Promise) return cached;
189
- const result = Promise.resolve(this.#resolver(this.#path, template, error));
190
- this.#cache.set(template, result);
191
- return result;
192
- }
193
- #compile(content, template) {
194
- const cached = this.#cache.get(template);
195
- if (typeof cached === 'function') return cached;
196
- if (typeof content === 'string') {
197
- content = this.#compiler.compile(content, template);
198
- }
199
- if (typeof content === 'function') {
200
- this.#cache.set(template, content);
201
- return content;
249
+ _classPrivateFieldSet2(_resolver, this, options.resolver);
202
250
  }
203
251
  }
204
252
  get(template) {
205
- return this.#resolve(template).then(content => {
206
- return this.#compile(content, template);
253
+ return _assertClassBrand(_EjsTemplate_brand, this, _resolve).call(this, template).then(content => {
254
+ return _assertClassBrand(_EjsTemplate_brand, this, _compile).call(this, content, template);
207
255
  });
208
256
  }
209
257
  }
258
+ function _resolve(template) {
259
+ const cached = _classPrivateFieldGet2(_cache$2, this).get(template);
260
+ if (cached instanceof Promise) return cached;
261
+ const result = Promise.resolve(_classPrivateFieldGet2(_resolver, this).call(this, _classPrivateFieldGet2(_path$1, this), template, error));
262
+ _classPrivateFieldGet2(_cache$2, this).set(template, result);
263
+ return result;
264
+ }
265
+ function _compile(content, template) {
266
+ const cached = _classPrivateFieldGet2(_cache$2, this).get(template);
267
+ if (typeof cached === 'function') return cached;
268
+ if (typeof content === 'string') {
269
+ content = _classPrivateFieldGet2(_compiler$1, this).compile(content, template);
270
+ }
271
+ if (typeof content === 'function') {
272
+ _classPrivateFieldGet2(_cache$2, this).set(template, content);
273
+ return content;
274
+ }
275
+ }
276
+ _defineProperty(EjsTemplate, "exports", ['configure', 'get']);
210
277
 
211
- const tokenList = [['-', (v, b, s) => `')\n${b}(${s}(${v},1))\n${b}('`], ['=', (v, b, s) => `')\n${b}(${s}(${v}))\n${b}('`], ['#', (v, b) => `')\n/**${v}**/\n${b}('`], ['', (v, b) => `')\n${v}\n${b}('`]];
278
+ const tokenList = [['-', (v, b, s) => "')\n".concat(b, "(").concat(s, "(").concat(v, ",1))\n").concat(b, "('")], ['=', (v, b, s) => "')\n".concat(b, "(").concat(s, "(").concat(v, "))\n").concat(b, "('")], ['#', (v, b) => "')\n/**".concat(v, "**/\n").concat(b, "('")], ['', (v, b) => "')\n".concat(v, "\n").concat(b, "('")]];
212
279
  const tokensMatch = (regex, content, callback) => {
213
280
  let index = 0;
214
281
  content.replace(regex, function () {
@@ -220,133 +287,138 @@ const tokensMatch = (regex, content, callback) => {
220
287
  return match;
221
288
  });
222
289
  };
290
+ var _config$1 = /*#__PURE__*/new WeakMap();
223
291
  class EjsCompiler {
224
- #config = {};
225
- static exports = ['configure', 'compile'];
226
292
  constructor(options) {
293
+ _classPrivateFieldInitSpec(this, _config$1, {});
227
294
  bindContext(this, this.constructor.exports);
228
295
  this.configure(options);
229
296
  }
230
297
  configure(options) {
231
- this.#config.strict = options.strict;
232
- this.#config.rmWhitespace = options.rmWhitespace;
233
- this.#config.token = options.token;
234
- this.#config.vars = options.vars;
235
- this.#config.globals = options.globals;
236
- this.#config.legacy = options.legacy ?? true;
237
- this.#config.slurp = {
298
+ var _options$legacy;
299
+ _classPrivateFieldGet2(_config$1, this).strict = options.strict;
300
+ _classPrivateFieldGet2(_config$1, this).rmWhitespace = options.rmWhitespace;
301
+ _classPrivateFieldGet2(_config$1, this).token = options.token;
302
+ _classPrivateFieldGet2(_config$1, this).vars = options.vars;
303
+ _classPrivateFieldGet2(_config$1, this).globals = options.globals;
304
+ _classPrivateFieldGet2(_config$1, this).legacy = (_options$legacy = options.legacy) !== null && _options$legacy !== void 0 ? _options$legacy : true;
305
+ _classPrivateFieldGet2(_config$1, this).slurp = {
238
306
  match: '[s\t\n]*',
239
- start: [this.#config.token.start, '_'],
240
- end: ['_', this.#config.token.end]
307
+ start: [_classPrivateFieldGet2(_config$1, this).token.start, '_'],
308
+ end: ['_', _classPrivateFieldGet2(_config$1, this).token.end]
241
309
  };
242
- this.#config.matches = [];
243
- this.#config.formats = [];
310
+ _classPrivateFieldGet2(_config$1, this).matches = [];
311
+ _classPrivateFieldGet2(_config$1, this).formats = [];
244
312
  for (const [symbol, format] of tokenList) {
245
- this.#config.matches.push(this.#config.token.start.concat(symbol).concat(this.#config.token.regex).concat(this.#config.token.end));
246
- this.#config.formats.push(format);
313
+ _classPrivateFieldGet2(_config$1, this).matches.push(_classPrivateFieldGet2(_config$1, this).token.start.concat(symbol).concat(_classPrivateFieldGet2(_config$1, this).token.regex).concat(_classPrivateFieldGet2(_config$1, this).token.end));
314
+ _classPrivateFieldGet2(_config$1, this).formats.push(format);
247
315
  }
248
- this.#config.regex = new RegExp(this.#config.matches.join('|').concat('|$'), 'g');
249
- this.#config.slurpStart = new RegExp([this.#config.slurp.match, this.#config.slurp.start.join('')].join(''), 'gm');
250
- this.#config.slurpEnd = new RegExp([this.#config.slurp.end.join(''), this.#config.slurp.match].join(''), 'gm');
251
- if (this.#config.globals.length) {
252
- if (this.#config.legacy) {
253
- this.#config.globalVariables = `const ${this.#config.globals.map(name => `${name}=${this.#config.vars.SCOPE}.${name}`).join(',')};`;
316
+ _classPrivateFieldGet2(_config$1, this).regex = new RegExp(_classPrivateFieldGet2(_config$1, this).matches.join('|').concat('|$'), 'g');
317
+ _classPrivateFieldGet2(_config$1, this).slurpStart = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.match, _classPrivateFieldGet2(_config$1, this).slurp.start.join('')].join(''), 'gm');
318
+ _classPrivateFieldGet2(_config$1, this).slurpEnd = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.end.join(''), _classPrivateFieldGet2(_config$1, this).slurp.match].join(''), 'gm');
319
+ if (_classPrivateFieldGet2(_config$1, this).globals.length) {
320
+ if (_classPrivateFieldGet2(_config$1, this).legacy) {
321
+ _classPrivateFieldGet2(_config$1, this).globalVariables = "const ".concat(_classPrivateFieldGet2(_config$1, this).globals.map(name => "".concat(name, "=").concat(_classPrivateFieldGet2(_config$1, this).vars.SCOPE, ".").concat(name)).join(','), ";");
254
322
  } else {
255
- this.#config.globalVariables = `const {${this.#config.globals.join(',')}} = ${this.#config.vars.SCOPE};`;
323
+ _classPrivateFieldGet2(_config$1, this).globalVariables = "const {".concat(_classPrivateFieldGet2(_config$1, this).globals.join(','), "} = ").concat(_classPrivateFieldGet2(_config$1, this).vars.SCOPE, ";");
256
324
  }
257
325
  }
258
326
  }
259
327
  compile(content, path) {
260
- const GLOBALS = this.#config.globalVariables;
328
+ const GLOBALS = _classPrivateFieldGet2(_config$1, this).globalVariables;
261
329
  const {
262
330
  SCOPE,
263
331
  SAFE,
264
332
  BUFFER,
265
333
  COMPONENT,
266
334
  ELEMENT
267
- } = this.#config.vars;
268
- if (this.#config.rmWhitespace) {
335
+ } = _classPrivateFieldGet2(_config$1, this).vars;
336
+ if (_classPrivateFieldGet2(_config$1, this).rmWhitespace) {
269
337
  content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
270
338
  }
271
- content = String(content).replace(this.#config.slurpStart, this.#config.token.start).replace(this.#config.slurpEnd, this.#config.token.end);
272
- let OUTPUT = `${BUFFER}('`;
273
- tokensMatch(this.#config.regex, content, (params, index, offset) => {
339
+ content = String(content).replace(_classPrivateFieldGet2(_config$1, this).slurpStart, _classPrivateFieldGet2(_config$1, this).token.start).replace(_classPrivateFieldGet2(_config$1, this).slurpEnd, _classPrivateFieldGet2(_config$1, this).token.end);
340
+ let OUTPUT = "".concat(BUFFER, "('");
341
+ tokensMatch(_classPrivateFieldGet2(_config$1, this).regex, content, (params, index, offset) => {
274
342
  OUTPUT += symbols(content.slice(index, offset));
275
343
  params.forEach((value, index) => {
276
344
  if (value) {
277
- OUTPUT += this.#config.formats[index](value.trim(), BUFFER, SAFE);
345
+ OUTPUT += _classPrivateFieldGet2(_config$1, this).formats[index](value.trim(), BUFFER, SAFE);
278
346
  }
279
347
  });
280
348
  });
281
- OUTPUT += `');`;
282
- OUTPUT = `try{${OUTPUT}}catch(e){return ${BUFFER}.error(e)}`;
283
- if (this.#config.strict === false) {
284
- OUTPUT = `with(${SCOPE}){${OUTPUT}}`;
349
+ OUTPUT += "');";
350
+ OUTPUT = "try{".concat(OUTPUT, "}catch(e){return ").concat(BUFFER, ".error(e)}");
351
+ if (_classPrivateFieldGet2(_config$1, this).strict === false) {
352
+ OUTPUT = "with(".concat(SCOPE, "){").concat(OUTPUT, "}");
285
353
  }
286
- OUTPUT = `${BUFFER}.start();${OUTPUT}return ${BUFFER}.end();`;
287
- OUTPUT += `\n//# sourceURL=${path}`;
354
+ OUTPUT = "".concat(BUFFER, ".start();").concat(OUTPUT, "return ").concat(BUFFER, ".end();");
355
+ OUTPUT += "\n//# sourceURL=".concat(path);
288
356
  if (GLOBALS) {
289
- OUTPUT = `${GLOBALS}\n${OUTPUT}`;
357
+ OUTPUT = "".concat(GLOBALS, "\n").concat(OUTPUT);
290
358
  }
291
359
  try {
292
360
  const params = [SCOPE, COMPONENT, ELEMENT, BUFFER, SAFE];
293
361
  const result = Function.apply(null, params.concat(OUTPUT));
294
- result.source = `(function(${params.join(',')}){\n${OUTPUT}\n});`;
362
+ result.source = "(function(".concat(params.join(','), "){\n").concat(OUTPUT, "\n});");
295
363
  return result;
296
- } catch (error) {
297
- error.filename = path;
298
- error.source = OUTPUT;
299
- throw error;
364
+ } catch (e) {
365
+ e.filename = path;
366
+ e.source = OUTPUT;
367
+ error(0, e);
300
368
  }
301
369
  }
302
370
  }
371
+ _defineProperty(EjsCompiler, "exports", ['configure', 'compile']);
303
372
 
373
+ var _cache$1 = /*#__PURE__*/new WeakMap();
374
+ var _precompiled = /*#__PURE__*/new WeakMap();
375
+ var _list = /*#__PURE__*/new WeakMap();
304
376
  class EjsCache {
305
- static exports = ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve'];
306
- #cache = true;
307
- #precompiled;
308
- #list = {};
309
377
  constructor(options) {
378
+ _classPrivateFieldInitSpec(this, _cache$1, true);
379
+ _classPrivateFieldInitSpec(this, _precompiled, void 0);
380
+ _classPrivateFieldInitSpec(this, _list, {});
310
381
  bindContext(this, this.constructor.exports);
311
382
  this.configure(options);
312
383
  }
313
384
  get(key) {
314
- if (this.#cache) {
315
- return this.#list[key];
385
+ if (_classPrivateFieldGet2(_cache$1, this)) {
386
+ return _classPrivateFieldGet2(_list, this)[key];
316
387
  }
317
388
  }
318
389
  set(key, value) {
319
- if (this.#cache) {
320
- this.#list[key] = value;
390
+ if (_classPrivateFieldGet2(_cache$1, this)) {
391
+ _classPrivateFieldGet2(_list, this)[key] = value;
321
392
  }
322
393
  }
323
394
  exist(key) {
324
- if (this.#cache) {
325
- return this.#list.hasOwnProperty(key);
395
+ if (_classPrivateFieldGet2(_cache$1, this)) {
396
+ return _classPrivateFieldGet2(_list, this).hasOwnProperty(key);
326
397
  }
327
398
  }
328
399
  clear() {
329
- Object.keys(this.#list).forEach(this.remove);
400
+ Object.keys(_classPrivateFieldGet2(_list, this)).forEach(this.remove);
330
401
  }
331
402
  remove(key) {
332
- delete this.#list[key];
403
+ delete _classPrivateFieldGet2(_list, this)[key];
333
404
  }
334
405
  resolve(key) {
335
406
  return Promise.resolve(this.get(key));
336
407
  }
337
408
  load(data) {
338
- if (this.#cache) {
339
- Object.assign(this.#list, data || {});
409
+ if (_classPrivateFieldGet2(_cache$1, this)) {
410
+ Object.assign(_classPrivateFieldGet2(_list, this), data || {});
340
411
  }
341
412
  }
342
413
  configure(options) {
343
- this.#cache = options.cache;
344
- this.#precompiled = options.precompiled;
414
+ _classPrivateFieldSet2(_cache$1, this, options.cache);
415
+ _classPrivateFieldSet2(_precompiled, this, options.precompiled);
345
416
  if (typeof window === 'object') {
346
- this.load(window[this.#precompiled]);
417
+ this.load(window[_classPrivateFieldGet2(_precompiled, this)]);
347
418
  }
348
419
  }
349
420
  }
421
+ _defineProperty(EjsCache, "exports", ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve']);
350
422
 
351
423
  const selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
352
424
  const space = ' ';
@@ -364,7 +436,7 @@ const eachAttribute = _ref => {
364
436
  const element = (tag, attrs, content) => {
365
437
  const result = [];
366
438
  const hasClosedTag = selfClosed.indexOf(tag) === -1;
367
- const attributes = Object.entries(attrs ?? {}).map(eachAttribute).filter(e => e).join(space);
439
+ const attributes = Object.entries(attrs !== null && attrs !== void 0 ? attrs : {}).map(eachAttribute).filter(e => e).join(space);
368
440
  result.push([lt, tag, space, attributes, gt].join(''));
369
441
  if (content && hasClosedTag) {
370
442
  result.push(Array.isArray(content) ? content.join('') : content);
@@ -376,12 +448,10 @@ const element = (tag, attrs, content) => {
376
448
  };
377
449
 
378
450
  const resolve = list => {
379
- return Promise.all(list || []).then(list => list.join('')).catch(e => {
380
- return error(500, e);
381
- });
451
+ return Promise.all(list || []).then(list => list.join('')).catch(e => error(0, e));
382
452
  };
383
453
  const reject = e => {
384
- return Promise.reject(error(500, e));
454
+ return Promise.reject(error(0, e));
385
455
  };
386
456
  const EjsBuffer = () => {
387
457
  let store = [];
@@ -417,6 +487,7 @@ const EjsBuffer = () => {
417
487
 
418
488
  const PARENT = Symbol('EjsContext.parentTemplate');
419
489
  const createContext$1 = (config, methods) => {
490
+ const globals = config.globals || [];
420
491
  const {
421
492
  BLOCKS,
422
493
  MACRO,
@@ -428,37 +499,38 @@ const createContext$1 = (config, methods) => {
428
499
  COMPONENT,
429
500
  ELEMENT
430
501
  } = config.vars;
431
- const globals = config.globals || [];
432
- function EjsContext(data) {
433
- this[PARENT] = null;
434
- this[BLOCKS] = {};
435
- this[MACRO] = {};
436
- Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]));
437
- }
438
- Object.defineProperty(EjsContext.prototype, BUFFER, {
439
- value: EjsBuffer()
440
- });
441
- Object.defineProperty(EjsContext.prototype, BLOCKS, {
442
- value: {},
443
- writable: true
444
- });
445
- Object.defineProperty(EjsContext.prototype, MACRO, {
446
- value: {},
447
- writable: true
448
- });
449
- Object.defineProperty(EjsContext.prototype, LAYOUT, {
450
- value: false,
451
- writable: true
452
- });
453
- Object.defineProperty(EjsContext.prototype, EXTEND, {
454
- value: false,
455
- writable: true
456
- });
457
- Object.defineProperty(EjsContext.prototype, PARENT, {
458
- value: null,
459
- writable: true
460
- });
461
- Object.defineProperties(EjsContext.prototype, {
502
+ class Context {
503
+ constructor(data) {
504
+ this[PARENT] = null;
505
+ this[BLOCKS] = {};
506
+ this[MACRO] = {};
507
+ Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]));
508
+ }
509
+ }
510
+ Object.defineProperties(Context.prototype, {
511
+ [BUFFER]: {
512
+ value: EjsBuffer()
513
+ },
514
+ [BLOCKS]: {
515
+ value: {},
516
+ writable: true
517
+ },
518
+ [MACRO]: {
519
+ value: {},
520
+ writable: true
521
+ },
522
+ [LAYOUT]: {
523
+ value: false,
524
+ writable: true
525
+ },
526
+ [EXTEND]: {
527
+ value: false,
528
+ writable: true
529
+ },
530
+ [PARENT]: {
531
+ value: null,
532
+ writable: true
533
+ },
462
534
  setParentTemplate: {
463
535
  value(value) {
464
536
  this[PARENT] = value;
@@ -471,32 +543,34 @@ const createContext$1 = (config, methods) => {
471
543
  }
472
544
  },
473
545
  useEscapeValue: {
474
- get: () => escapeValue
546
+ value() {
547
+ return escapeValue;
548
+ }
475
549
  },
476
550
  useComponent: {
477
- get() {
551
+ value() {
478
552
  if (isFunction(this[COMPONENT])) {
479
553
  return this[COMPONENT].bind(this);
480
554
  } else {
481
555
  return function () {
482
- throw new Error(`${COMPONENT} must be a function`);
556
+ error(2, "".concat(COMPONENT, " must be a function"));
483
557
  };
484
558
  }
485
559
  }
486
560
  },
487
561
  useElement: {
488
- get() {
562
+ value() {
489
563
  if (isFunction(this[ELEMENT])) {
490
564
  return this[ELEMENT].bind(this);
491
565
  } else {
492
566
  return () => {
493
- throw new Error(`${ELEMENT} must be a function`);
567
+ error(2, "".concat(ELEMENT, " must be a function"));
494
568
  };
495
569
  }
496
570
  }
497
571
  },
498
572
  useBuffer: {
499
- get() {
573
+ value() {
500
574
  return this[BUFFER];
501
575
  }
502
576
  },
@@ -549,17 +623,18 @@ const createContext$1 = (config, methods) => {
549
623
  },
550
624
  echo: {
551
625
  value() {
552
- return [].slice.call(arguments).forEach(this.useBuffer);
626
+ return [].slice.call(arguments).forEach(this.useBuffer());
553
627
  }
554
628
  },
555
629
  fn: {
556
630
  value(callback) {
631
+ const buffer = this.useBuffer();
557
632
  const context = this;
558
633
  return function () {
559
634
  if (isFunction(callback)) {
560
- context.useBuffer.backup();
561
- context.useBuffer(callback.apply(context, arguments));
562
- return context.useBuffer.restore();
635
+ buffer.backup();
636
+ buffer(callback.apply(context, arguments));
637
+ return buffer.restore();
563
638
  }
564
639
  };
565
640
  }
@@ -669,52 +744,72 @@ const createContext$1 = (config, methods) => {
669
744
  ui: {
670
745
  value() {},
671
746
  writable: true
747
+ },
748
+ require: {
749
+ value() {},
750
+ writable: true
751
+ },
752
+ render: {
753
+ value() {},
754
+ writable: true
672
755
  }
673
756
  });
674
757
  Object.entries(methods).forEach(_ref => {
675
758
  let [name, value] = _ref;
676
759
  if (isFunction(value) && globals.includes(name)) {
677
- value = value.bind(EjsContext.prototype);
760
+ value = value.bind(Context.prototype);
678
761
  }
679
- EjsContext.prototype[name] = value;
762
+ Context.prototype[name] = value;
680
763
  });
681
- return EjsContext;
764
+ return Context;
682
765
  };
766
+ var _context$1 = /*#__PURE__*/new WeakMap();
683
767
  class EjsContext {
684
- #context;
685
- static exports = ['create', 'globals', 'helpers'];
686
768
  constructor(options, methods) {
769
+ _classPrivateFieldInitSpec(this, _context$1, void 0);
687
770
  bindContext(this, this.constructor.exports);
688
771
  this.configure(options, methods);
689
772
  }
690
773
  create(data) {
691
- return new this.#context(data);
774
+ return new (_classPrivateFieldGet2(_context$1, this))(data);
692
775
  }
693
776
  helpers(methods) {
694
- Object.assign(this.#context.prototype, methods);
777
+ Object.assign(_classPrivateFieldGet2(_context$1, this).prototype, methods);
695
778
  }
696
779
  configure(options, methods) {
697
- this.#context = createContext$1(options, methods);
780
+ _classPrivateFieldSet2(_context$1, this, createContext$1(options, methods));
698
781
  }
699
782
  }
783
+ _defineProperty(EjsContext, "exports", ['create', 'globals', 'helpers']);
700
784
 
785
+ var _cache = /*#__PURE__*/new WeakMap();
786
+ var _context = /*#__PURE__*/new WeakMap();
787
+ var _compiler = /*#__PURE__*/new WeakMap();
788
+ var _template = /*#__PURE__*/new WeakMap();
789
+ var _config = /*#__PURE__*/new WeakMap();
790
+ var _methods = /*#__PURE__*/new WeakMap();
791
+ var _EjsInstance_brand = /*#__PURE__*/new WeakSet();
701
792
  class EjsInstance {
702
- #cache;
703
- #context;
704
- #compiler;
705
- #template;
706
- #config = {};
707
- #methods = {};
708
- static exports = ['configure', 'create', 'createContext', 'render', 'require', 'preload', 'compile', 'helpers'];
793
+ /**
794
+ *
795
+ * @param {EjsConfig} options
796
+ */
709
797
  constructor() {
710
798
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
799
+ _classPrivateMethodInitSpec(this, _EjsInstance_brand);
800
+ _classPrivateFieldInitSpec(this, _cache, void 0);
801
+ _classPrivateFieldInitSpec(this, _context, void 0);
802
+ _classPrivateFieldInitSpec(this, _compiler, void 0);
803
+ _classPrivateFieldInitSpec(this, _template, void 0);
804
+ _classPrivateFieldInitSpec(this, _config, {});
805
+ _classPrivateFieldInitSpec(this, _methods, {});
711
806
  bindContext(this, this.constructor.exports);
712
- this.#methods = {};
713
- this.#config = configSchema({}, options);
714
- this.#context = new EjsContext(this.#config, this.#methods);
715
- this.#compiler = new EjsCompiler(this.#config);
716
- this.#cache = new EjsCache(this.#config);
717
- this.#template = new EjsTemplate(this.#config, this.#cache, this.#compiler);
807
+ _classPrivateFieldSet2(_methods, this, {});
808
+ _classPrivateFieldSet2(_config, this, configSchema({}, options));
809
+ _classPrivateFieldSet2(_context, this, new EjsContext(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_methods, this)));
810
+ _classPrivateFieldSet2(_compiler, this, new EjsCompiler(_classPrivateFieldGet2(_config, this)));
811
+ _classPrivateFieldSet2(_cache, this, new EjsCache(_classPrivateFieldGet2(_config, this)));
812
+ _classPrivateFieldSet2(_template, this, new EjsTemplate(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_cache, this), _classPrivateFieldGet2(_compiler, this)));
718
813
  this.helpers({
719
814
  render: this.render,
720
815
  require: this.require
@@ -725,67 +820,67 @@ class EjsInstance {
725
820
  }
726
821
  configure(options) {
727
822
  if (options) {
728
- configSchema(this.#config, options);
729
- this.#context.configure(this.#config, this.#methods);
730
- this.#compiler.configure(this.#config);
731
- this.#cache.configure(this.#config);
732
- this.#template.configure(this.#config);
823
+ configSchema(_classPrivateFieldGet2(_config, this), options);
824
+ _classPrivateFieldGet2(_context, this).configure(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_methods, this));
825
+ _classPrivateFieldGet2(_compiler, this).configure(_classPrivateFieldGet2(_config, this));
826
+ _classPrivateFieldGet2(_cache, this).configure(_classPrivateFieldGet2(_config, this));
827
+ _classPrivateFieldGet2(_template, this).configure(_classPrivateFieldGet2(_config, this));
733
828
  }
734
- return this.#config;
829
+ return _classPrivateFieldGet2(_config, this);
735
830
  }
736
831
  createContext(data) {
737
- return this.#context.create(data);
832
+ return _classPrivateFieldGet2(_context, this).create(data);
738
833
  }
739
834
  preload(list) {
740
- return this.#cache.load(list || {});
835
+ return _classPrivateFieldGet2(_cache, this).load(list || {});
741
836
  }
742
837
  compile(content, path) {
743
- return this.#compiler.compile(content, path);
838
+ return _classPrivateFieldGet2(_compiler, this).compile(content, path);
744
839
  }
745
840
  helpers(methods) {
746
- this.#context.helpers(Object.assign(this.#methods, methods));
841
+ _classPrivateFieldGet2(_context, this).helpers(Object.assign(_classPrivateFieldGet2(_methods, this), methods));
747
842
  }
748
843
  async render(name, params) {
749
844
  const data = this.createContext(params);
750
- return this.#output(this.#path(name), data).then(this.#outputContent(name, data));
845
+ return _assertClassBrand(_EjsInstance_brand, this, _output).call(this, _assertClassBrand(_EjsInstance_brand, this, _path).call(this, name), data).then(_assertClassBrand(_EjsInstance_brand, this, _outputContent).call(this, name, data));
751
846
  }
752
847
  async require(name) {
753
848
  const data = this.createContext({});
754
- return this.#output(this.#path(name), data).then(() => data.getMacro());
755
- }
756
- #path(name) {
757
- const ext = name.split('.').pop();
758
- if (ext !== this.#config.extension) {
759
- name = [name, this.#config.extension].join('.');
760
- }
761
- return name;
849
+ return _assertClassBrand(_EjsInstance_brand, this, _output).call(this, _assertClassBrand(_EjsInstance_brand, this, _path).call(this, name), data).then(() => data.getMacro());
762
850
  }
763
- #output(path, data) {
764
- return this.#template.get(path).then(callback => callback.apply(data, [data, data.useComponent, data.useElement, data.useBuffer, data.useEscapeValue]));
765
- }
766
- #renderLayout(name, params, parentTemplate) {
767
- const data = this.createContext(params);
768
- if (parentTemplate) data.setParentTemplate(parentTemplate);
769
- return this.#output(this.#path(name), data).then(this.#outputContent(name, data));
770
- }
771
- #outputContent(name, data) {
772
- return content => {
773
- if (data.getExtend()) {
774
- data.setExtend(false);
775
- return this.#renderLayout(data.getLayout(), data, name);
776
- }
777
- return content;
778
- };
851
+ }
852
+ function _path(name) {
853
+ const ext = name.split('.').pop();
854
+ if (ext !== _classPrivateFieldGet2(_config, this).extension) {
855
+ name = [name, _classPrivateFieldGet2(_config, this).extension].join('.');
779
856
  }
857
+ return name;
858
+ }
859
+ function _output(path, data) {
860
+ return _classPrivateFieldGet2(_template, this).get(path).then(callback => callback.apply(data, [data, data.useComponent(), data.useElement(), data.useBuffer(), data.useEscapeValue()]));
861
+ }
862
+ function _renderLayout(name, params, parentTemplate) {
863
+ const data = this.createContext(params);
864
+ if (parentTemplate) data.setParentTemplate(parentTemplate);
865
+ return _assertClassBrand(_EjsInstance_brand, this, _output).call(this, _assertClassBrand(_EjsInstance_brand, this, _path).call(this, name), data).then(_assertClassBrand(_EjsInstance_brand, this, _outputContent).call(this, name, data));
780
866
  }
867
+ function _outputContent(name, data) {
868
+ return content => {
869
+ if (data.getExtend()) {
870
+ data.setExtend(false);
871
+ return _assertClassBrand(_EjsInstance_brand, this, _renderLayout).call(this, data.getLayout(), data, name);
872
+ }
873
+ return content;
874
+ };
875
+ }
876
+ _defineProperty(EjsInstance, "exports", ['configure', 'create', 'createContext', 'render', 'require', 'preload', 'compile', 'helpers']);
781
877
 
782
- const httpRequest = (path, template, error) => {
878
+ const resolver = async (path, template, error) => {
783
879
  return fetch(joinPath(path, template)).then(response => {
784
880
  if (response.ok) return response.text();
785
- return error(404, `template ${template} not found`);
786
- }, reason => error(500, reason));
881
+ return error(1, "template ".concat(template, " not found"));
882
+ }, reason => error(0, reason));
787
883
  };
788
-
789
884
  const {
790
885
  render,
791
886
  configure,
@@ -795,13 +890,15 @@ const {
795
890
  compile,
796
891
  preload
797
892
  } = new EjsInstance({
798
- resolver: httpRequest
893
+ resolver
799
894
  });
800
895
 
801
896
  exports.compile = compile;
802
897
  exports.configure = configure;
803
898
  exports.create = create;
804
899
  exports.createContext = createContext;
900
+ exports.element = element;
901
+ exports.escapeValue = escapeValue;
805
902
  exports.helpers = helpers;
806
903
  exports.preload = preload;
807
904
  exports.render = render;