janja 2.3.0 β†’ 2.4.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/README.md CHANGED
@@ -1,3 +1,35 @@
1
+ ![](https://repository-images.githubusercontent.com/989161365/d61a6f29-b7e9-4fbe-8ea2-adac36ea8f44)
2
+
3
+ The Reeds
4
+ Tr. ZHAO Yanchun
5
+
6
+ The reeds sway, green and green;
7
+ The white dew becomes frost.
8
+ The lady fair I mean
9
+ Looms yonder, all but lost.
10
+ Upstream to her I row;
11
+ The course is long and high.
12
+ Upstream to her I go;
13
+ On the waves she looks shy.
14
+
15
+ The reeds sway, clean and clean;
16
+ The white dew has not dried.
17
+ The lady fair I mean
18
+ Looms by the riverside.
19
+ Upstream to her I row;
20
+ The course is hard and high.
21
+ Upstream to her I go;
22
+ On the strand she seems nigh.
23
+
24
+ The reeds sway, sheen and sheen;
25
+ The white dew as e’er gleams.
26
+ The lady fair I mean
27
+ Stands on the bank, it seems.
28
+ Upstream to her I row;
29
+ The course turns left and right.
30
+ Upstream to her I go;
31
+ On the shoal she beams bright.
32
+
1
33
  # Janja
2
34
 
3
35
  <p align="center">A simple, fast, lightweight, and extensible template engine for Node.js and browsers.</p>
@@ -18,7 +50,7 @@
18
50
  - 🎨 **Custom directives and filters**: Ability to define custom directives and filters.
19
51
  - πŸš€ **Pre-compilation**: Enhance rendering performance by precompiling.
20
52
  - πŸ› **Error handling and debugging**: Provides detailed error reporting and debugging support.
21
- - πŸ›‘οΈ **Security**: Sandbox mode, and automatic escaping.
53
+ - πŸ›‘οΈ **Security**: Automatic escaping.
22
54
  - πŸ›« **Asynchronous data loading**: Supports fetching and displaying remote data asynchronously.
23
55
  - 🌐 **Universal compatibility**: Works in both Node.js and browser environments.
24
56
  - πŸ“¦ **Zero dependencies**: Lightweight with no external dependencies.
package/dist/index.cjs.js CHANGED
@@ -884,6 +884,7 @@ class CommentNode extends Traversal {
884
884
  }
885
885
 
886
886
  async function* parseComment({ val, loc, strip }) {
887
+ console.log(val);
887
888
  yield 'NEXT';
888
889
  yield new CommentNode(val, loc, strip);
889
890
  }
@@ -896,20 +897,20 @@ const plugin$9 = {
896
897
  parsers: parsers$9,
897
898
  };
898
899
 
899
- async function compileFor({ loop, body }, compiler) {
900
+ async function compileFor({ loop: { left, right, loc }, body }, compiler) {
900
901
  const { context } = compiler;
901
902
  const expCompiler = new ExpCompiler();
902
- if (loop.left.type === 'SEQ') {
903
- compiler.pushRaw(loop.loc, '{', `const a_=${expCompiler.compile(loop.right, context)},n_=a_.length;`, 'let i_=0;', `for(const {${loop.left.elements
903
+ if (left.type === 'SEQ') {
904
+ compiler.pushRaw(loc, '{', `const a_=${expCompiler.compile(right, context)},n_=a_.length;`, 'let i_=0;', `for(const {${left.elements
904
905
  .map((el) => el.type === 'ASSIGN'
905
906
  ? `${el.left.value}=${expCompiler.compile(el.right, context)}`
906
907
  : el.value)
907
- .join(',')}} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${loop.left.elements
908
+ .join(',')}} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${left.elements
908
909
  .map((el) => (el.type === 'ASSIGN' ? el.left.value : el.value))
909
910
  .join(',')},`, '};');
910
911
  }
911
912
  else {
912
- compiler.pushRaw(loop.loc, '{', `const a_=${expCompiler.compile(loop.right, context)},n_=a_.length;`, 'let i_=0;', `for(const ${loop.left.value} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${loop.left.value},`, '};');
913
+ compiler.pushRaw(loc, '{', `const a_=${expCompiler.compile(right, context)},n_=a_.length;`, 'let i_=0;', `for(const ${left.value} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${left.value},`, '};');
913
914
  }
914
915
  await compiler.compileNodes(body);
915
916
  compiler.out();
@@ -1639,11 +1640,11 @@ const plugin$2 = {
1639
1640
  parsers: parsers$2,
1640
1641
  };
1641
1642
 
1642
- async function compileUnexpected$1({ name, val, loc }, compiler) {
1643
- compiler.pushRaw(loc, `<!-- unexpected "${name}" with value "${val}" -->`);
1643
+ async function compileUnexpected({ name, loc }, compiler) {
1644
+ compiler.pushRaw(loc, `<!--Unexpected "${name}"-->`);
1644
1645
  }
1645
1646
  const compilers$1 = {
1646
- UNEXPECTED: compileUnexpected$1,
1647
+ UNEXPECTED: compileUnexpected,
1647
1648
  };
1648
1649
 
1649
1650
  class UnexpectedNode extends Traversal {
@@ -1684,7 +1685,7 @@ class UnexpectedNode extends Traversal {
1684
1685
 
1685
1686
  async function* parseUnexpected(token, parser) {
1686
1687
  const name = token.name ?? token.type;
1687
- parser.options.debug?.(new CompileError(`Unexpected "${name}" node`, parser.template, token.loc));
1688
+ parser.options.debug?.(new CompileError(`Unexpected "${name}"`, parser.template, token.loc));
1688
1689
  yield 'NEXT';
1689
1690
  yield new UnexpectedNode(name, token.val, token.loc, token.strip);
1690
1691
  }
@@ -1697,11 +1698,11 @@ const plugin$1 = {
1697
1698
  parsers: parsers$1,
1698
1699
  };
1699
1700
 
1700
- async function compileUnexpected({ name, val, loc }, compiler) {
1701
- compiler.pushRaw(loc, `<!-- unexpected "${name}" with value "${val}" -->`);
1701
+ async function compileUnknown({ name, loc }, compiler) {
1702
+ compiler.pushRaw(loc, `<!--Unknown "${name}"-->`);
1702
1703
  }
1703
1704
  const compilers = {
1704
- UNEXPECTED: compileUnexpected,
1705
+ UNKNOWN: compileUnknown,
1705
1706
  };
1706
1707
 
1707
1708
  class UnknownNode extends Traversal {
@@ -1742,7 +1743,7 @@ class UnknownNode extends Traversal {
1742
1743
 
1743
1744
  async function* parseUnknown(token, parser) {
1744
1745
  const name = token.name ?? token.type;
1745
- parser.options.debug?.(new CompileError(`Unknown "${name}" node`, parser.template, token.loc));
1746
+ parser.options.debug?.(new CompileError(`Unknown "${name}"`, parser.template, token.loc));
1746
1747
  yield 'NEXT';
1747
1748
  yield new UnknownNode(name, token.val, token.loc, token.strip);
1748
1749
  }
@@ -1781,7 +1782,7 @@ const baseOptions = {
1781
1782
  const parserOptions = {
1782
1783
  ...baseOptions,
1783
1784
  commentOpen: '{{#',
1784
- commentClose: '}}',
1785
+ commentClose: '#}}',
1785
1786
  directiveOpen: '{{',
1786
1787
  directiveClose: '}}',
1787
1788
  outputOpen: '{{=',
package/dist/index.esm.js CHANGED
@@ -882,6 +882,7 @@ class CommentNode extends Traversal {
882
882
  }
883
883
 
884
884
  async function* parseComment({ val, loc, strip }) {
885
+ console.log(val);
885
886
  yield 'NEXT';
886
887
  yield new CommentNode(val, loc, strip);
887
888
  }
@@ -894,20 +895,20 @@ const plugin$9 = {
894
895
  parsers: parsers$9,
895
896
  };
896
897
 
897
- async function compileFor({ loop, body }, compiler) {
898
+ async function compileFor({ loop: { left, right, loc }, body }, compiler) {
898
899
  const { context } = compiler;
899
900
  const expCompiler = new ExpCompiler();
900
- if (loop.left.type === 'SEQ') {
901
- compiler.pushRaw(loop.loc, '{', `const a_=${expCompiler.compile(loop.right, context)},n_=a_.length;`, 'let i_=0;', `for(const {${loop.left.elements
901
+ if (left.type === 'SEQ') {
902
+ compiler.pushRaw(loc, '{', `const a_=${expCompiler.compile(right, context)},n_=a_.length;`, 'let i_=0;', `for(const {${left.elements
902
903
  .map((el) => el.type === 'ASSIGN'
903
904
  ? `${el.left.value}=${expCompiler.compile(el.right, context)}`
904
905
  : el.value)
905
- .join(',')}} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${loop.left.elements
906
+ .join(',')}} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${left.elements
906
907
  .map((el) => (el.type === 'ASSIGN' ? el.left.value : el.value))
907
908
  .join(',')},`, '};');
908
909
  }
909
910
  else {
910
- compiler.pushRaw(loop.loc, '{', `const a_=${expCompiler.compile(loop.right, context)},n_=a_.length;`, 'let i_=0;', `for(const ${loop.left.value} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${loop.left.value},`, '};');
911
+ compiler.pushRaw(loc, '{', `const a_=${expCompiler.compile(right, context)},n_=a_.length;`, 'let i_=0;', `for(const ${left.value} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${left.value},`, '};');
911
912
  }
912
913
  await compiler.compileNodes(body);
913
914
  compiler.out();
@@ -1637,11 +1638,11 @@ const plugin$2 = {
1637
1638
  parsers: parsers$2,
1638
1639
  };
1639
1640
 
1640
- async function compileUnexpected$1({ name, val, loc }, compiler) {
1641
- compiler.pushRaw(loc, `<!-- unexpected "${name}" with value "${val}" -->`);
1641
+ async function compileUnexpected({ name, loc }, compiler) {
1642
+ compiler.pushRaw(loc, `<!--Unexpected "${name}"-->`);
1642
1643
  }
1643
1644
  const compilers$1 = {
1644
- UNEXPECTED: compileUnexpected$1,
1645
+ UNEXPECTED: compileUnexpected,
1645
1646
  };
1646
1647
 
1647
1648
  class UnexpectedNode extends Traversal {
@@ -1682,7 +1683,7 @@ class UnexpectedNode extends Traversal {
1682
1683
 
1683
1684
  async function* parseUnexpected(token, parser) {
1684
1685
  const name = token.name ?? token.type;
1685
- parser.options.debug?.(new CompileError(`Unexpected "${name}" node`, parser.template, token.loc));
1686
+ parser.options.debug?.(new CompileError(`Unexpected "${name}"`, parser.template, token.loc));
1686
1687
  yield 'NEXT';
1687
1688
  yield new UnexpectedNode(name, token.val, token.loc, token.strip);
1688
1689
  }
@@ -1695,11 +1696,11 @@ const plugin$1 = {
1695
1696
  parsers: parsers$1,
1696
1697
  };
1697
1698
 
1698
- async function compileUnexpected({ name, val, loc }, compiler) {
1699
- compiler.pushRaw(loc, `<!-- unexpected "${name}" with value "${val}" -->`);
1699
+ async function compileUnknown({ name, loc }, compiler) {
1700
+ compiler.pushRaw(loc, `<!--Unknown "${name}"-->`);
1700
1701
  }
1701
1702
  const compilers = {
1702
- UNEXPECTED: compileUnexpected,
1703
+ UNKNOWN: compileUnknown,
1703
1704
  };
1704
1705
 
1705
1706
  class UnknownNode extends Traversal {
@@ -1740,7 +1741,7 @@ class UnknownNode extends Traversal {
1740
1741
 
1741
1742
  async function* parseUnknown(token, parser) {
1742
1743
  const name = token.name ?? token.type;
1743
- parser.options.debug?.(new CompileError(`Unknown "${name}" node`, parser.template, token.loc));
1744
+ parser.options.debug?.(new CompileError(`Unknown "${name}"`, parser.template, token.loc));
1744
1745
  yield 'NEXT';
1745
1746
  yield new UnknownNode(name, token.val, token.loc, token.strip);
1746
1747
  }
@@ -1779,7 +1780,7 @@ const baseOptions = {
1779
1780
  const parserOptions = {
1780
1781
  ...baseOptions,
1781
1782
  commentOpen: '{{#',
1782
- commentClose: '}}',
1783
+ commentClose: '#}}',
1783
1784
  directiveOpen: '{{',
1784
1785
  directiveClose: '}}',
1785
1786
  outputOpen: '{{=',
package/dist/index.js CHANGED
@@ -885,6 +885,7 @@ ${output
885
885
  }
886
886
 
887
887
  async function* parseComment({ val, loc, strip }) {
888
+ console.log(val);
888
889
  yield 'NEXT';
889
890
  yield new CommentNode(val, loc, strip);
890
891
  }
@@ -897,20 +898,20 @@ ${output
897
898
  parsers: parsers$9,
898
899
  };
899
900
 
900
- async function compileFor({ loop, body }, compiler) {
901
+ async function compileFor({ loop: { left, right, loc }, body }, compiler) {
901
902
  const { context } = compiler;
902
903
  const expCompiler = new ExpCompiler();
903
- if (loop.left.type === 'SEQ') {
904
- compiler.pushRaw(loop.loc, '{', `const a_=${expCompiler.compile(loop.right, context)},n_=a_.length;`, 'let i_=0;', `for(const {${loop.left.elements
904
+ if (left.type === 'SEQ') {
905
+ compiler.pushRaw(loc, '{', `const a_=${expCompiler.compile(right, context)},n_=a_.length;`, 'let i_=0;', `for(const {${left.elements
905
906
  .map((el) => el.type === 'ASSIGN'
906
907
  ? `${el.left.value}=${expCompiler.compile(el.right, context)}`
907
908
  : el.value)
908
- .join(',')}} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${loop.left.elements
909
+ .join(',')}} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${left.elements
909
910
  .map((el) => (el.type === 'ASSIGN' ? el.left.value : el.value))
910
911
  .join(',')},`, '};');
911
912
  }
912
913
  else {
913
- compiler.pushRaw(loop.loc, '{', `const a_=${expCompiler.compile(loop.right, context)},n_=a_.length;`, 'let i_=0;', `for(const ${loop.left.value} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${loop.left.value},`, '};');
914
+ compiler.pushRaw(loc, '{', `const a_=${expCompiler.compile(right, context)},n_=a_.length;`, 'let i_=0;', `for(const ${left.value} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${left.value},`, '};');
914
915
  }
915
916
  await compiler.compileNodes(body);
916
917
  compiler.out();
@@ -1640,11 +1641,11 @@ ${output
1640
1641
  parsers: parsers$2,
1641
1642
  };
1642
1643
 
1643
- async function compileUnexpected$1({ name, val, loc }, compiler) {
1644
- compiler.pushRaw(loc, `<!-- unexpected "${name}" with value "${val}" -->`);
1644
+ async function compileUnexpected({ name, loc }, compiler) {
1645
+ compiler.pushRaw(loc, `<!--Unexpected "${name}"-->`);
1645
1646
  }
1646
1647
  const compilers$1 = {
1647
- UNEXPECTED: compileUnexpected$1,
1648
+ UNEXPECTED: compileUnexpected,
1648
1649
  };
1649
1650
 
1650
1651
  class UnexpectedNode extends Traversal {
@@ -1685,7 +1686,7 @@ ${output
1685
1686
 
1686
1687
  async function* parseUnexpected(token, parser) {
1687
1688
  const name = token.name ?? token.type;
1688
- parser.options.debug?.(new CompileError(`Unexpected "${name}" node`, parser.template, token.loc));
1689
+ parser.options.debug?.(new CompileError(`Unexpected "${name}"`, parser.template, token.loc));
1689
1690
  yield 'NEXT';
1690
1691
  yield new UnexpectedNode(name, token.val, token.loc, token.strip);
1691
1692
  }
@@ -1698,11 +1699,11 @@ ${output
1698
1699
  parsers: parsers$1,
1699
1700
  };
1700
1701
 
1701
- async function compileUnexpected({ name, val, loc }, compiler) {
1702
- compiler.pushRaw(loc, `<!-- unexpected "${name}" with value "${val}" -->`);
1702
+ async function compileUnknown({ name, loc }, compiler) {
1703
+ compiler.pushRaw(loc, `<!--Unknown "${name}"-->`);
1703
1704
  }
1704
1705
  const compilers = {
1705
- UNEXPECTED: compileUnexpected,
1706
+ UNKNOWN: compileUnknown,
1706
1707
  };
1707
1708
 
1708
1709
  class UnknownNode extends Traversal {
@@ -1743,7 +1744,7 @@ ${output
1743
1744
 
1744
1745
  async function* parseUnknown(token, parser) {
1745
1746
  const name = token.name ?? token.type;
1746
- parser.options.debug?.(new CompileError(`Unknown "${name}" node`, parser.template, token.loc));
1747
+ parser.options.debug?.(new CompileError(`Unknown "${name}"`, parser.template, token.loc));
1747
1748
  yield 'NEXT';
1748
1749
  yield new UnknownNode(name, token.val, token.loc, token.strip);
1749
1750
  }
@@ -1782,7 +1783,7 @@ ${output
1782
1783
  const parserOptions = {
1783
1784
  ...baseOptions,
1784
1785
  commentOpen: '{{#',
1785
- commentClose: '}}',
1786
+ commentClose: '#}}',
1786
1787
  directiveOpen: '{{',
1787
1788
  directiveClose: '}}',
1788
1789
  outputOpen: '{{=',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "janja",
3
3
  "type": "module",
4
- "version": "2.3.0",
4
+ "version": "2.4.0",
5
5
  "packageManager": "yarn@4.9.2",
6
6
  "description": "A simple, fast, lightweight, and extensible template engine for Node.js and browsers.",
7
7
  "license": "MIT",