janja 1.0.0 → 1.1.0

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.
package/dist/index.cjs.js CHANGED
@@ -114,15 +114,16 @@ class Context {
114
114
  });
115
115
  }
116
116
  in() {
117
- const len = this.contexts.push(`${this.context}_${this.index++}`);
118
- return (this.context = this.contexts[len - 1]);
117
+ this.context = `${this.context}_${this.index++}`;
118
+ this.contexts.push(this.context);
119
+ return this.context;
119
120
  }
120
121
  out() {
121
122
  if (this.context === CONTEXT) {
122
123
  return;
123
124
  }
124
125
  this.contexts.pop();
125
- this.context = this.contexts[this.contexts.length - 1];
126
+ this.context = this.contexts.at(-1) ?? CONTEXT;
126
127
  }
127
128
  expect(name) {
128
129
  this.expected.push(name);
@@ -287,32 +288,32 @@ class Compiler {
287
288
  value: options
288
289
  });
289
290
  }
290
- async compile(tagToken, filepath) {
291
+ async compile(tag, filepath) {
291
292
  const ctx = new Context(this.options);
292
293
  const out = new OutScript(this.options);
293
294
  const sourcemap = new SourceMap(this.options);
294
295
  out.start();
295
- while (tagToken) {
296
- const compilers = (this.options.compilers[tagToken.name] ?? []);
296
+ while (tag) {
297
+ const compilers = (this.options.compilers[tag.name] ?? []);
297
298
  for (const compiler of compilers) {
298
299
  try {
299
300
  const r = await compiler.compile({
300
- token: tagToken,
301
+ tag,
301
302
  ctx,
302
303
  out,
303
304
  });
304
305
  if (r !== false) {
305
306
  if (r) {
306
- sourcemap.addMapping(tagToken, r);
307
+ sourcemap.addMapping(tag, r);
307
308
  }
308
309
  break;
309
310
  }
310
311
  }
311
312
  catch (error) {
312
- throw new CompileError(error.message, tagToken, filepath);
313
+ throw new CompileError(error.message, tag, filepath);
313
314
  }
314
315
  }
315
- tagToken = tagToken.next;
316
+ tag = tag.next;
316
317
  }
317
318
  try {
318
319
  ctx.validate();
@@ -525,6 +526,7 @@ var filters = /*#__PURE__*/Object.freeze({
525
526
  const expTokenOperators = {
526
527
  AND: '&&',
527
528
  OR: '||',
529
+ IS: '',
528
530
  NOT: '!',
529
531
  EQ: '===',
530
532
  NE: '!==',
@@ -547,11 +549,9 @@ const expTokenOperators = {
547
549
  COMMA: ',',
548
550
  DOT: '.',
549
551
  ID: '',
550
- STR: '',
551
- NUM: '',
552
+ LIT: '',
552
553
  IF: '',
553
554
  ELSE: '',
554
- BOOL: '',
555
555
  };
556
556
 
557
557
  class ExpCompiler {
@@ -580,18 +580,16 @@ class ExpCompiler {
580
580
  return this.compileNot(expression);
581
581
  case 'ID':
582
582
  return this.compileId(expression);
583
- case 'STR':
584
- return this.compileStr(expression);
585
- case 'NUM':
586
- return this.compileNum(expression);
587
- case 'BOOL':
588
- return this.compileBool(expression);
583
+ case 'LIT':
584
+ return this.compileLit(expression);
589
585
  case 'PIPE':
590
586
  return this.compilePipe(expression);
591
587
  case 'OF':
592
588
  return this.compileOf(expression);
593
589
  case 'SET':
594
590
  return this.compileSet(expression);
591
+ case 'IS':
592
+ return this.compileIs(expression);
595
593
  case 'AND':
596
594
  case 'OR':
597
595
  case 'EQ':
@@ -627,14 +625,8 @@ class ExpCompiler {
627
625
  }
628
626
  return s;
629
627
  }
630
- compileStr({ value }) {
631
- return JSON.stringify(value);
632
- }
633
- compileNum({ value }) {
634
- return value.toString();
635
- }
636
- compileBool({ value }) {
637
- return value.toString();
628
+ compileLit({ value }) {
629
+ return value === undefined ? 'undefined' : JSON.stringify(value);
638
630
  }
639
631
  compileSeq({ elements }) {
640
632
  return elements.map(element => this.compileExp(element)).toString();
@@ -661,6 +653,9 @@ class ExpCompiler {
661
653
  // destructuring
662
654
  return `Object.assign(${this.context},${this.filters}.pick.call(${this.context},${this.compileExp(right)},[${left.elements.map(({ value }) => `"${value}"`).join(',')}]));`;
663
655
  }
656
+ compileIs({ left, right }) {
657
+ return `(typeof ${this.compileExp(left)}===${this.compileExp(right)})`;
658
+ }
664
659
  compileBinary({ type, left, right }) {
665
660
  const ret = `(${this.compileExp(left)}${expTokenOperators[type]}${this.compileExp(right)})`;
666
661
  return type === 'NI' ? `(!${ret})` : ret;
@@ -679,6 +674,7 @@ const expTokenPrecedences = {
679
674
  RP: 20,
680
675
  OR: 25,
681
676
  AND: 30,
677
+ IS: 40,
682
678
  EQ: 40,
683
679
  NE: 40,
684
680
  GT: 40,
@@ -697,15 +693,14 @@ const expTokenPrecedences = {
697
693
  PIPE: 80,
698
694
  DOT: 90,
699
695
  ID: 90,
700
- STR: 90,
701
- NUM: 90,
702
- BOOL: 90,
696
+ LIT: 90,
703
697
  };
704
698
 
705
699
  const expTokenTypes = {
706
700
  'and': 'AND',
707
701
  'or': 'OR',
708
702
  'not': 'NOT',
703
+ 'is': 'IS',
709
704
  'eq': 'EQ',
710
705
  'ne': 'NE',
711
706
  'gt': 'GT',
@@ -722,8 +717,10 @@ const expTokenTypes = {
722
717
  '%': 'MOD',
723
718
  'if': 'IF',
724
719
  'else': 'ELSE',
725
- 'true': 'BOOL',
726
- 'false': 'BOOL',
720
+ 'true': 'LIT',
721
+ 'false': 'LIT',
722
+ 'null': 'LIT',
723
+ 'undefined': 'LIT',
727
724
  '|': 'PIPE',
728
725
  '=': 'SET',
729
726
  '(': 'LP',
@@ -837,7 +834,7 @@ class ExpTokenizer {
837
834
  // skip closing quote char
838
835
  this.cursor++;
839
836
  this.tokens.push({
840
- type: 'STR',
837
+ type: 'LIT',
841
838
  value,
842
839
  start,
843
840
  end: this.cursor,
@@ -863,7 +860,7 @@ class ExpTokenizer {
863
860
  this.cursor++;
864
861
  }
865
862
  this.tokens.push({
866
- type: 'NUM',
863
+ type: 'LIT',
867
864
  value: Number.parseFloat(value),
868
865
  start,
869
866
  end: this.cursor,
@@ -885,7 +882,17 @@ class ExpTokenizer {
885
882
  const type = value in expTokenTypes ? expTokenTypes[value] : 'ID';
886
883
  this.tokens.push({
887
884
  type,
888
- value: type === 'BOOL' ? value === 'true' : value,
885
+ value: type === 'LIT'
886
+ ? value === 'true'
887
+ ? true
888
+ : value === 'false'
889
+ ? false
890
+ : value === 'null'
891
+ ? null
892
+ : value === 'undefined'
893
+ ? undefined
894
+ : value
895
+ : value,
889
896
  start,
890
897
  end: this.cursor,
891
898
  raw: value,
@@ -1039,27 +1046,10 @@ class ExpParser {
1039
1046
  }
1040
1047
  continue;
1041
1048
  }
1042
- if (token.type === 'STR') {
1043
- left = {
1044
- ...token,
1045
- type: 'STR',
1046
- value: token.value,
1047
- };
1048
- continue;
1049
- }
1050
- if (token.type === 'NUM') {
1051
- left = {
1052
- ...token,
1053
- type: 'NUM',
1054
- value: token.value,
1055
- };
1056
- continue;
1057
- }
1058
- if (token.type === 'BOOL') {
1049
+ if (token.type === 'LIT') {
1059
1050
  left = {
1060
1051
  ...token,
1061
- type: 'BOOL',
1062
- value: token.value,
1052
+ type: 'LIT',
1063
1053
  };
1064
1054
  continue;
1065
1055
  }
@@ -1097,6 +1087,7 @@ class ExpParser {
1097
1087
  }
1098
1088
  if (token.type === 'AND'
1099
1089
  || token.type === 'OR'
1090
+ || token.type === 'IS'
1100
1091
  || token.type === 'EQ'
1101
1092
  || token.type === 'NE'
1102
1093
  || token.type === 'GT'
@@ -1275,7 +1266,7 @@ const ENDCALL = 'endcall';
1275
1266
  */
1276
1267
  const tag$7 = {
1277
1268
  names: [CALL, ENDCALL],
1278
- async compile({ token: { name, value }, ctx, out }) {
1269
+ async compile({ tag: { name, value }, ctx, out }) {
1279
1270
  if (name === CALL) {
1280
1271
  if (value?.type !== 'ID') {
1281
1272
  throw new Error(`"${CALL}" tag must specify a "macro" name`);
@@ -1301,7 +1292,7 @@ const ENDCOMMENT = 'endcomment';
1301
1292
  */
1302
1293
  const tag$6 = {
1303
1294
  names: [COMMENT, '#', ENDCOMMENT],
1304
- async compile({ token: { name, value }, ctx, out }) {
1295
+ async compile({ tag: { name, value }, ctx, out }) {
1305
1296
  // inline comment
1306
1297
  if (name === '#') {
1307
1298
  if (!value.value || out.options.stripComments) {
@@ -1330,7 +1321,7 @@ const EXPRESSION = '=';
1330
1321
  */
1331
1322
  const tag$5 = {
1332
1323
  names: [EXPRESSION],
1333
- compile({ token: { value }, ctx: { context }, out }) {
1324
+ compile({ tag: { value }, ctx: { context }, out }) {
1334
1325
  return out.pushVar(compiler.compile(value, context, FILTERS));
1335
1326
  },
1336
1327
  };
@@ -1345,15 +1336,16 @@ const ENDFOR = 'endfor';
1345
1336
  */
1346
1337
  const tag$4 = {
1347
1338
  names: [FOR, BREAK, CONTINUE, ENDFOR],
1348
- async compile({ token: { name, value }, ctx, out }) {
1339
+ async compile({ tag: { name, value }, ctx, out }) {
1349
1340
  if (name === FOR) {
1350
1341
  if (!value) {
1351
1342
  throw new Error(`"${FOR}" tag must have expression`);
1352
1343
  }
1353
1344
  ctx.expect(ENDFOR);
1354
1345
  const { context } = ctx;
1355
- if (value.left.type === 'SEQ') {
1356
- return out.pushLine(`{`, `for(${compiler.compile(value, context, FILTERS)}){`, `const ${ctx.in()}={`, `...${context},`, `${value.left.elements.map(({ value }) => value).join(',')}`, `};`);
1346
+ const { type, elements } = value.left;
1347
+ if (type === 'SEQ') {
1348
+ return out.pushLine(`{`, `for(${compiler.compile(value, context, FILTERS)}){`, `const ${ctx.in()}={`, `...${context},`, elements.map(({ value }) => value).join(','), `};`);
1357
1349
  }
1358
1350
  return out.pushLine(`{`, `for(${compiler.compile(value, context, FILTERS)}){`, `const ${ctx.in()}={`, `...${context},`, `${value.left.value},`, `};`);
1359
1351
  }
@@ -1388,7 +1380,7 @@ const ENDIF = 'endif';
1388
1380
  */
1389
1381
  const tag$3 = {
1390
1382
  names: [IF, ELIF, ELSE, ENDIF],
1391
- async compile({ token: { name, value }, ctx, out }) {
1383
+ async compile({ tag: { name, value }, ctx, out }) {
1392
1384
  if (name === IF) {
1393
1385
  if (!value) {
1394
1386
  throw new Error(`"${IF}" tag must have expression`);
@@ -1425,25 +1417,29 @@ const tag$3 = {
1425
1417
  const MACRO = 'macro';
1426
1418
  const CALLER = 'caller';
1427
1419
  const ENDMACRO = 'endmacro';
1420
+ const CALLER_PN = '_c';
1428
1421
  /**
1429
1422
  * @example {{ macro my_macro = (x, y) }}...{{ caller }}{{ endmacro }}{{ my_macro("foo", 1) }}
1430
1423
  */
1431
1424
  const tag$2 = {
1432
1425
  names: [MACRO, CALLER, ENDMACRO],
1433
- async compile({ token: { name, value }, ctx, out }) {
1426
+ async compile({ tag: { name, value }, ctx, out }) {
1434
1427
  if (name === MACRO) {
1435
1428
  if (value?.type !== 'SET') {
1436
1429
  throw new Error(`"${MACRO}" tag must have "SET" expression`);
1437
1430
  }
1438
1431
  ctx.expect(ENDMACRO);
1439
1432
  const { context } = ctx;
1440
- return out.pushLine(`${compiler.compile(value, context, FILTERS)}=>async(_c)=>{`, `const ${ctx.in()}={`, `...${context},`, `${(value.right.elements).map(el => el.type === 'SET' ? `${el.left.value}` : el.value).join(',')}`, `};`);
1433
+ const { elements } = value.right;
1434
+ return out.pushLine(`${compiler.compile(value, context, FILTERS)}=>async(${CALLER_PN})=>{`, `const ${ctx.in()}={`, `...${context},`, elements.map(el => el.type === 'SET'
1435
+ ? el.left.value
1436
+ : el.value).join(','), `};`);
1441
1437
  }
1442
1438
  if (name === CALLER) {
1443
1439
  if (!ctx.matchAny(ENDMACRO)) {
1444
1440
  throw new Error(`"${CALLER}" tag must inside a "${MACRO}" tag`);
1445
1441
  }
1446
- return out.pushLine(`await _c?.();`);
1442
+ return out.pushLine(`await ${CALLER_PN}?.();`);
1447
1443
  }
1448
1444
  if (name === ENDMACRO) {
1449
1445
  if (!ctx.consume(ENDMACRO)) {
@@ -1461,7 +1457,7 @@ const RAW = 'raw';
1461
1457
  */
1462
1458
  const tag$1 = {
1463
1459
  names: [RAW],
1464
- async compile({ token: { raw, previous, next }, out }) {
1460
+ async compile({ tag: { raw, previous, next }, out }) {
1465
1461
  return out.pushStr(raw, {
1466
1462
  trimStart: previous?.stripAfter,
1467
1463
  trimEnd: next?.stripBefore,
@@ -1477,7 +1473,7 @@ const ENDSET = 'endset';
1477
1473
  */
1478
1474
  const tag = {
1479
1475
  names: [SET, ENDSET],
1480
- async compile({ token: { name, value }, ctx, out }) {
1476
+ async compile({ tag: { name, value }, ctx, out }) {
1481
1477
  if (name === SET) {
1482
1478
  if (!value) {
1483
1479
  throw new Error(`"${SET}" tag must have expression`);
@@ -1585,30 +1581,29 @@ class Parser {
1585
1581
  let match;
1586
1582
  while ((match = tagRe.exec(template))) {
1587
1583
  if (match.index > this.index) {
1588
- this.strToken(this.index, match.index);
1584
+ this.addRaw(this.index, match.index);
1589
1585
  }
1590
- await this.tagToken(match);
1586
+ await this.addTag(match);
1591
1587
  this.index = match.index + match[0].length;
1592
1588
  }
1593
1589
  if (this.index < template.length) {
1594
- this.strToken(this.index, template.length);
1590
+ this.addRaw(this.index, template.length);
1595
1591
  }
1596
1592
  this.cursor = this.first;
1597
1593
  this.rebuildBlocks();
1598
1594
  return this.cursor;
1599
1595
  }
1600
- strToken(start, end) {
1601
- const raw = this.template.slice(start, end);
1596
+ addRaw(start, end) {
1602
1597
  this.push({
1603
1598
  name: RAW$1,
1604
- raw,
1599
+ raw: this.template.slice(start, end),
1605
1600
  previous: null,
1606
1601
  next: null,
1607
1602
  start,
1608
1603
  end,
1609
1604
  });
1610
1605
  }
1611
- async tagToken(match) {
1606
+ async addTag(match) {
1612
1607
  const start = match.index;
1613
1608
  const end = start + match[0].length;
1614
1609
  const base = {
@@ -1625,7 +1620,7 @@ class Parser {
1625
1620
  ...base,
1626
1621
  name: match[2],
1627
1622
  value: {
1628
- type: 'STR',
1623
+ type: 'LIT',
1629
1624
  value: unescapeTag(match[3]),
1630
1625
  },
1631
1626
  });
@@ -1656,7 +1651,7 @@ class Parser {
1656
1651
  }
1657
1652
  async layout(value) {
1658
1653
  const exp = parser.parse(value);
1659
- if (exp?.type !== 'STR' || !exp.value) {
1654
+ if (exp?.type !== 'LIT' || typeof exp.value !== 'string' || !exp.value) {
1660
1655
  throw new ParseError(`"layout" tag must have a file path`, {
1661
1656
  source: this.template,
1662
1657
  range: {
@@ -1669,7 +1664,7 @@ class Parser {
1669
1664
  }
1670
1665
  async include(value) {
1671
1666
  const exp = parser.parse(value.replace(/\?$/, ''));
1672
- if (exp?.type !== 'STR' || !exp.value) {
1667
+ if (exp?.type !== 'LIT' || typeof exp.value !== 'string' || !exp.value) {
1673
1668
  throw new ParseError(`"include" tag must have a file path`, {
1674
1669
  source: this.template,
1675
1670
  range: {
@@ -1700,9 +1695,9 @@ class Parser {
1700
1695
  cursor = cursor.next;
1701
1696
  }
1702
1697
  }
1703
- push(token) {
1704
- if (token.name === BLOCK) {
1705
- const { type, value } = token.value;
1698
+ push(tag) {
1699
+ if (tag.name === BLOCK) {
1700
+ const { type, value } = tag.value;
1706
1701
  if (type !== 'ID') {
1707
1702
  throw new ParseError(`"${BLOCK}" tag must have a title`, {
1708
1703
  source: this.template,
@@ -1715,31 +1710,31 @@ class Parser {
1715
1710
  this.group = value;
1716
1711
  // child blocks
1717
1712
  if (this.blocks[value]) {
1718
- this.blocks[value].push([token]);
1713
+ this.blocks[value].push([tag]);
1719
1714
  return;
1720
1715
  }
1721
1716
  // parent block
1722
- this.blocks[value] = [[token]];
1717
+ this.blocks[value] = [[tag]];
1723
1718
  }
1724
1719
  else if (this.group) {
1725
1720
  const chunks = this.blocks[this.group];
1726
- if (token.name === ENDBLOCK) {
1721
+ if (tag.name === ENDBLOCK) {
1727
1722
  this.group = '';
1728
1723
  }
1729
- chunks.at(-1).push(token);
1724
+ chunks.at(-1).push(tag);
1730
1725
  // child blocks
1731
1726
  if (chunks.length > 1) {
1732
1727
  return;
1733
1728
  }
1734
1729
  }
1735
1730
  if (this.cursor) {
1736
- token.previous = this.cursor;
1737
- this.cursor.next = token;
1731
+ tag.previous = this.cursor;
1732
+ this.cursor.next = tag;
1738
1733
  }
1739
1734
  else {
1740
- this.first = token;
1735
+ this.first = tag;
1741
1736
  }
1742
- this.cursor = token;
1737
+ this.cursor = tag;
1743
1738
  }
1744
1739
  /**
1745
1740
  * @note Block tags are hoisted to top level
@@ -1777,29 +1772,29 @@ class Parser {
1777
1772
  return [];
1778
1773
  }
1779
1774
  const chunk = [];
1780
- child.forEach((token) => {
1781
- if (token.name === SUPER) {
1775
+ child.forEach((tag) => {
1776
+ if (tag.name === SUPER) {
1782
1777
  this.rebuildBlockBody(parents.pop(), parents).forEach(t => chunk.push(t));
1783
1778
  }
1784
1779
  else {
1785
- chunk.push(token);
1780
+ chunk.push(tag);
1786
1781
  }
1787
1782
  });
1788
1783
  return chunk;
1789
1784
  }
1790
- rebuildBlockChain(tokens, previous, next) {
1791
- for (let i = 0; i < tokens.length; i++) {
1792
- tokens[i].previous = tokens[i - 1] || previous;
1793
- tokens[i].next = tokens[i + 1] || next;
1785
+ rebuildBlockChain(tags, previous, next) {
1786
+ for (let i = 0; i < tags.length; i++) {
1787
+ tags[i].previous = tags[i - 1] || previous;
1788
+ tags[i].next = tags[i + 1] || next;
1794
1789
  }
1795
1790
  if (previous) {
1796
- [previous.next] = tokens;
1791
+ [previous.next] = tags;
1797
1792
  }
1798
1793
  if (next) {
1799
- next.previous = tokens[tokens.length - 1];
1794
+ next.previous = tags[tags.length - 1];
1800
1795
  }
1801
1796
  if (!this.first) {
1802
- [this.first] = tokens;
1797
+ [this.first] = tags;
1803
1798
  this.cursor = this.first;
1804
1799
  }
1805
1800
  }
package/dist/index.d.ts CHANGED
@@ -71,14 +71,14 @@ interface Mapping {
71
71
  source: Range;
72
72
  target: Range;
73
73
  }
74
- type ExpTokenType = 'AND' | 'OR' | 'NOT' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'IF' | 'ELSE' | 'SET' | 'LP' | 'RP' | 'COMMA' | 'DOT' | 'STR' | 'NUM' | 'BOOL' | 'ID';
74
+ type ExpTokenType = 'AND' | 'OR' | 'IS' | 'NOT' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'IF' | 'ELSE' | 'SET' | 'LP' | 'RP' | 'COMMA' | 'DOT' | 'ID' | 'LIT';
75
75
  interface ExpToken<T = ExpTokenType> extends Range {
76
76
  type: T;
77
77
  value: string | number | boolean | null | undefined;
78
78
  raw?: string;
79
79
  }
80
80
  type Checker = (token: ExpToken) => 'BACK' | 'BREAK' | undefined;
81
- type ExpType = 'AND' | 'OR' | 'NOT' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'IF' | 'SET' | 'SEQ' | 'STR' | 'NUM' | 'BOOL' | 'ID';
81
+ type ExpType = 'AND' | 'OR' | 'IS' | 'NOT' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'IF' | 'SET' | 'SEQ' | 'ID' | 'LIT';
82
82
  interface BaseExp extends Range {
83
83
  type: ExpType;
84
84
  }
@@ -88,24 +88,16 @@ interface IdExp extends BaseExp {
88
88
  path?: IdExp[];
89
89
  args?: Exp[];
90
90
  }
91
- interface StrExp extends BaseExp {
92
- type: 'STR';
93
- value: string;
94
- }
95
- interface NumExp extends BaseExp {
96
- type: 'NUM';
97
- value: number;
98
- }
99
- interface BoolExp extends BaseExp {
100
- type: 'BOOL';
101
- value: boolean;
91
+ interface LitExp extends BaseExp {
92
+ type: 'LIT';
93
+ value: string | number | boolean | null | undefined;
102
94
  }
103
95
  interface NotExp extends BaseExp {
104
96
  type: 'NOT';
105
97
  argument: Exp;
106
98
  }
107
99
  interface BinaryExp extends BaseExp {
108
- type: 'AND' | 'OR' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'SET';
100
+ type: 'AND' | 'OR' | 'IS' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'SET';
109
101
  left: Exp;
110
102
  right: Exp;
111
103
  }
@@ -124,19 +116,19 @@ interface SeqExp extends BaseExp {
124
116
  type: 'SEQ';
125
117
  elements: Exp[];
126
118
  }
127
- type Exp = IdExp | StrExp | NumExp | BoolExp | NotExp | BinaryExp | IfExp | PipeExp | SeqExp;
119
+ type Exp = IdExp | LitExp | NotExp | BinaryExp | IfExp | PipeExp | SeqExp;
128
120
  interface Globals {
129
121
  translations?: Record<string, string>;
130
122
  [key: string]: any;
131
123
  }
132
124
  type Filters = Record<string, (value: any, ...args: any[]) => any>;
133
125
  type Script = (globals: Globals, filters: Filters, escape: (v: unknown) => unknown) => Promise<string>;
134
- interface TagToken extends Range {
126
+ interface Tag extends Range {
135
127
  name: string;
136
128
  value?: Exp | null;
137
129
  raw: string;
138
- previous: TagToken | null;
139
- next: TagToken | null;
130
+ previous: Tag | null;
131
+ next: Tag | null;
140
132
  stripBefore?: boolean;
141
133
  stripAfter?: boolean;
142
134
  }
@@ -148,7 +140,7 @@ interface TagCompiler {
148
140
  * - Return `void` to continue compiling.
149
141
  */
150
142
  compile: (arg: {
151
- token: TagToken;
143
+ tag: Tag;
152
144
  ctx: Context;
153
145
  out: OutScript;
154
146
  }) => MaybePromise<Range | void | false>;
@@ -181,13 +173,12 @@ declare class ExpCompiler {
181
173
  private compileExp;
182
174
  private compileNot;
183
175
  private compileId;
184
- private compileStr;
185
- private compileNum;
186
- private compileBool;
176
+ private compileLit;
187
177
  private compileSeq;
188
178
  private compilePipe;
189
179
  private compileOf;
190
180
  private compileSet;
181
+ private compileIs;
191
182
  private compileBinary;
192
183
  private compileTernary;
193
184
  }
@@ -224,4 +215,4 @@ declare function render(template: string, data: ObjectType, options?: Config): P
224
215
  declare function renderFile(filepath: string, data: ObjectType, options?: Config): Promise<string>;
225
216
 
226
217
  export { Engine, ExpCompiler, ExpParser, compiler, parser, render, renderFile };
227
- export type { BaseExp, BinaryExp, BoolExp, CacheValue, Checker, Config, Exp, ExpToken, ExpTokenType, ExpType, Filters, Globals, IdExp, IfExp, Mapping, MaybePromise, NotExp, NumExp, ObjectType, PipeExp, Range, Script, SeqExp, StrExp, TagCompiler, TagToken };
218
+ export type { BaseExp, BinaryExp, CacheValue, Checker, Config, Exp, ExpToken, ExpTokenType, ExpType, Filters, Globals, IdExp, IfExp, LitExp, Mapping, MaybePromise, NotExp, ObjectType, PipeExp, Range, Script, SeqExp, Tag, TagCompiler };