janja 2.2.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 +33 -1
- package/dist/index.cjs.js +26 -27
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +26 -27
- package/dist/index.js +26 -27
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+

|
|
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**:
|
|
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
|
@@ -191,7 +191,7 @@ class Context extends OutScript {
|
|
|
191
191
|
writable: true,
|
|
192
192
|
value: CONTEXT
|
|
193
193
|
});
|
|
194
|
-
Object.defineProperty(this, "
|
|
194
|
+
Object.defineProperty(this, "stack", {
|
|
195
195
|
enumerable: true,
|
|
196
196
|
configurable: true,
|
|
197
197
|
writable: true,
|
|
@@ -206,15 +206,15 @@ class Context extends OutScript {
|
|
|
206
206
|
}
|
|
207
207
|
in() {
|
|
208
208
|
this.context = `${this.context}_${this.index++}`;
|
|
209
|
-
this.
|
|
209
|
+
this.stack.push(this.context);
|
|
210
210
|
return this.context;
|
|
211
211
|
}
|
|
212
212
|
out() {
|
|
213
213
|
if (this.context === CONTEXT) {
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
|
-
this.
|
|
217
|
-
this.context = this.
|
|
216
|
+
this.stack.pop();
|
|
217
|
+
this.context = this.stack.at(-1);
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -634,8 +634,6 @@ class ExpCompiler {
|
|
|
634
634
|
return this.compileLit(expression);
|
|
635
635
|
case 'PIPE':
|
|
636
636
|
return this.compilePipe(expression);
|
|
637
|
-
case 'OF':
|
|
638
|
-
return this.compileOf(expression);
|
|
639
637
|
case 'ASSIGN':
|
|
640
638
|
return this.compileAssign(expression);
|
|
641
639
|
case 'IS':
|
|
@@ -687,13 +685,6 @@ class ExpCompiler {
|
|
|
687
685
|
const { value: name, args = [] } = right;
|
|
688
686
|
return `(await ${this.filters}.${name}.call(${[this.context, this.compileExp(left), ...args.map((arg) => (arg.type === 'ASSIGN' ? `${this.context}.${arg.left.value}=${this.compileExp(arg.right)}` : this.compileExp(arg)))].join(',')}))`;
|
|
689
687
|
}
|
|
690
|
-
compileOf({ left, right }) {
|
|
691
|
-
// destructuring
|
|
692
|
-
if (left.type === 'SEQ') {
|
|
693
|
-
return `const {${left.elements.map(({ value }) => value).join(',')}} of ${this.compileExp(right)}`;
|
|
694
|
-
}
|
|
695
|
-
return `const ${left.value} of ${this.compileExp(right)}`;
|
|
696
|
-
}
|
|
697
688
|
compileAssign({ left, right }) {
|
|
698
689
|
if (left.type === 'ID') {
|
|
699
690
|
return `Object.assign(${this.context},{${left.value}:${this.compileExp(right)}});`;
|
|
@@ -893,6 +884,7 @@ class CommentNode extends Traversal {
|
|
|
893
884
|
}
|
|
894
885
|
|
|
895
886
|
async function* parseComment({ val, loc, strip }) {
|
|
887
|
+
console.log(val);
|
|
896
888
|
yield 'NEXT';
|
|
897
889
|
yield new CommentNode(val, loc, strip);
|
|
898
890
|
}
|
|
@@ -905,17 +897,24 @@ const plugin$9 = {
|
|
|
905
897
|
parsers: parsers$9,
|
|
906
898
|
};
|
|
907
899
|
|
|
908
|
-
async function compileFor({ loop, body }, compiler) {
|
|
900
|
+
async function compileFor({ loop: { left, right, loc }, body }, compiler) {
|
|
909
901
|
const { context } = compiler;
|
|
910
|
-
|
|
911
|
-
|
|
902
|
+
const expCompiler = new ExpCompiler();
|
|
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
|
|
905
|
+
.map((el) => el.type === 'ASSIGN'
|
|
906
|
+
? `${el.left.value}=${expCompiler.compile(el.right, context)}`
|
|
907
|
+
: el.value)
|
|
908
|
+
.join(',')}} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${left.elements
|
|
909
|
+
.map((el) => (el.type === 'ASSIGN' ? el.left.value : el.value))
|
|
910
|
+
.join(',')},`, '};');
|
|
912
911
|
}
|
|
913
912
|
else {
|
|
914
|
-
compiler.pushRaw(
|
|
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},`, '};');
|
|
915
914
|
}
|
|
916
915
|
await compiler.compileNodes(body);
|
|
917
916
|
compiler.out();
|
|
918
|
-
compiler.pushRaw(null, '}');
|
|
917
|
+
compiler.pushRaw(null, '}', '};');
|
|
919
918
|
}
|
|
920
919
|
function compileBreak({ loc }, compiler) {
|
|
921
920
|
compiler.pushRaw(loc, 'break;');
|
|
@@ -1641,11 +1640,11 @@ const plugin$2 = {
|
|
|
1641
1640
|
parsers: parsers$2,
|
|
1642
1641
|
};
|
|
1643
1642
|
|
|
1644
|
-
async function compileUnexpected
|
|
1645
|
-
compiler.pushRaw(loc, `<!--
|
|
1643
|
+
async function compileUnexpected({ name, loc }, compiler) {
|
|
1644
|
+
compiler.pushRaw(loc, `<!--Unexpected "${name}"-->`);
|
|
1646
1645
|
}
|
|
1647
1646
|
const compilers$1 = {
|
|
1648
|
-
UNEXPECTED: compileUnexpected
|
|
1647
|
+
UNEXPECTED: compileUnexpected,
|
|
1649
1648
|
};
|
|
1650
1649
|
|
|
1651
1650
|
class UnexpectedNode extends Traversal {
|
|
@@ -1686,7 +1685,7 @@ class UnexpectedNode extends Traversal {
|
|
|
1686
1685
|
|
|
1687
1686
|
async function* parseUnexpected(token, parser) {
|
|
1688
1687
|
const name = token.name ?? token.type;
|
|
1689
|
-
parser.options.debug?.(new CompileError(`Unexpected "${name}"
|
|
1688
|
+
parser.options.debug?.(new CompileError(`Unexpected "${name}"`, parser.template, token.loc));
|
|
1690
1689
|
yield 'NEXT';
|
|
1691
1690
|
yield new UnexpectedNode(name, token.val, token.loc, token.strip);
|
|
1692
1691
|
}
|
|
@@ -1699,11 +1698,11 @@ const plugin$1 = {
|
|
|
1699
1698
|
parsers: parsers$1,
|
|
1700
1699
|
};
|
|
1701
1700
|
|
|
1702
|
-
async function
|
|
1703
|
-
compiler.pushRaw(loc, `<!--
|
|
1701
|
+
async function compileUnknown({ name, loc }, compiler) {
|
|
1702
|
+
compiler.pushRaw(loc, `<!--Unknown "${name}"-->`);
|
|
1704
1703
|
}
|
|
1705
1704
|
const compilers = {
|
|
1706
|
-
|
|
1705
|
+
UNKNOWN: compileUnknown,
|
|
1707
1706
|
};
|
|
1708
1707
|
|
|
1709
1708
|
class UnknownNode extends Traversal {
|
|
@@ -1744,7 +1743,7 @@ class UnknownNode extends Traversal {
|
|
|
1744
1743
|
|
|
1745
1744
|
async function* parseUnknown(token, parser) {
|
|
1746
1745
|
const name = token.name ?? token.type;
|
|
1747
|
-
parser.options.debug?.(new CompileError(`Unknown "${name}"
|
|
1746
|
+
parser.options.debug?.(new CompileError(`Unknown "${name}"`, parser.template, token.loc));
|
|
1748
1747
|
yield 'NEXT';
|
|
1749
1748
|
yield new UnknownNode(name, token.val, token.loc, token.strip);
|
|
1750
1749
|
}
|
|
@@ -1783,7 +1782,7 @@ const baseOptions = {
|
|
|
1783
1782
|
const parserOptions = {
|
|
1784
1783
|
...baseOptions,
|
|
1785
1784
|
commentOpen: '{{#',
|
|
1786
|
-
commentClose: '}}',
|
|
1785
|
+
commentClose: '#}}',
|
|
1787
1786
|
directiveOpen: '{{',
|
|
1788
1787
|
directiveClose: '}}',
|
|
1789
1788
|
outputOpen: '{{=',
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -189,7 +189,7 @@ class Context extends OutScript {
|
|
|
189
189
|
writable: true,
|
|
190
190
|
value: CONTEXT
|
|
191
191
|
});
|
|
192
|
-
Object.defineProperty(this, "
|
|
192
|
+
Object.defineProperty(this, "stack", {
|
|
193
193
|
enumerable: true,
|
|
194
194
|
configurable: true,
|
|
195
195
|
writable: true,
|
|
@@ -204,15 +204,15 @@ class Context extends OutScript {
|
|
|
204
204
|
}
|
|
205
205
|
in() {
|
|
206
206
|
this.context = `${this.context}_${this.index++}`;
|
|
207
|
-
this.
|
|
207
|
+
this.stack.push(this.context);
|
|
208
208
|
return this.context;
|
|
209
209
|
}
|
|
210
210
|
out() {
|
|
211
211
|
if (this.context === CONTEXT) {
|
|
212
212
|
return;
|
|
213
213
|
}
|
|
214
|
-
this.
|
|
215
|
-
this.context = this.
|
|
214
|
+
this.stack.pop();
|
|
215
|
+
this.context = this.stack.at(-1);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
@@ -632,8 +632,6 @@ class ExpCompiler {
|
|
|
632
632
|
return this.compileLit(expression);
|
|
633
633
|
case 'PIPE':
|
|
634
634
|
return this.compilePipe(expression);
|
|
635
|
-
case 'OF':
|
|
636
|
-
return this.compileOf(expression);
|
|
637
635
|
case 'ASSIGN':
|
|
638
636
|
return this.compileAssign(expression);
|
|
639
637
|
case 'IS':
|
|
@@ -685,13 +683,6 @@ class ExpCompiler {
|
|
|
685
683
|
const { value: name, args = [] } = right;
|
|
686
684
|
return `(await ${this.filters}.${name}.call(${[this.context, this.compileExp(left), ...args.map((arg) => (arg.type === 'ASSIGN' ? `${this.context}.${arg.left.value}=${this.compileExp(arg.right)}` : this.compileExp(arg)))].join(',')}))`;
|
|
687
685
|
}
|
|
688
|
-
compileOf({ left, right }) {
|
|
689
|
-
// destructuring
|
|
690
|
-
if (left.type === 'SEQ') {
|
|
691
|
-
return `const {${left.elements.map(({ value }) => value).join(',')}} of ${this.compileExp(right)}`;
|
|
692
|
-
}
|
|
693
|
-
return `const ${left.value} of ${this.compileExp(right)}`;
|
|
694
|
-
}
|
|
695
686
|
compileAssign({ left, right }) {
|
|
696
687
|
if (left.type === 'ID') {
|
|
697
688
|
return `Object.assign(${this.context},{${left.value}:${this.compileExp(right)}});`;
|
|
@@ -891,6 +882,7 @@ class CommentNode extends Traversal {
|
|
|
891
882
|
}
|
|
892
883
|
|
|
893
884
|
async function* parseComment({ val, loc, strip }) {
|
|
885
|
+
console.log(val);
|
|
894
886
|
yield 'NEXT';
|
|
895
887
|
yield new CommentNode(val, loc, strip);
|
|
896
888
|
}
|
|
@@ -903,17 +895,24 @@ const plugin$9 = {
|
|
|
903
895
|
parsers: parsers$9,
|
|
904
896
|
};
|
|
905
897
|
|
|
906
|
-
async function compileFor({ loop, body }, compiler) {
|
|
898
|
+
async function compileFor({ loop: { left, right, loc }, body }, compiler) {
|
|
907
899
|
const { context } = compiler;
|
|
908
|
-
|
|
909
|
-
|
|
900
|
+
const expCompiler = new ExpCompiler();
|
|
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
|
|
903
|
+
.map((el) => el.type === 'ASSIGN'
|
|
904
|
+
? `${el.left.value}=${expCompiler.compile(el.right, context)}`
|
|
905
|
+
: el.value)
|
|
906
|
+
.join(',')}} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${left.elements
|
|
907
|
+
.map((el) => (el.type === 'ASSIGN' ? el.left.value : el.value))
|
|
908
|
+
.join(',')},`, '};');
|
|
910
909
|
}
|
|
911
910
|
else {
|
|
912
|
-
compiler.pushRaw(
|
|
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},`, '};');
|
|
913
912
|
}
|
|
914
913
|
await compiler.compileNodes(body);
|
|
915
914
|
compiler.out();
|
|
916
|
-
compiler.pushRaw(null, '}');
|
|
915
|
+
compiler.pushRaw(null, '}', '};');
|
|
917
916
|
}
|
|
918
917
|
function compileBreak({ loc }, compiler) {
|
|
919
918
|
compiler.pushRaw(loc, 'break;');
|
|
@@ -1639,11 +1638,11 @@ const plugin$2 = {
|
|
|
1639
1638
|
parsers: parsers$2,
|
|
1640
1639
|
};
|
|
1641
1640
|
|
|
1642
|
-
async function compileUnexpected
|
|
1643
|
-
compiler.pushRaw(loc, `<!--
|
|
1641
|
+
async function compileUnexpected({ name, loc }, compiler) {
|
|
1642
|
+
compiler.pushRaw(loc, `<!--Unexpected "${name}"-->`);
|
|
1644
1643
|
}
|
|
1645
1644
|
const compilers$1 = {
|
|
1646
|
-
UNEXPECTED: compileUnexpected
|
|
1645
|
+
UNEXPECTED: compileUnexpected,
|
|
1647
1646
|
};
|
|
1648
1647
|
|
|
1649
1648
|
class UnexpectedNode extends Traversal {
|
|
@@ -1684,7 +1683,7 @@ class UnexpectedNode extends Traversal {
|
|
|
1684
1683
|
|
|
1685
1684
|
async function* parseUnexpected(token, parser) {
|
|
1686
1685
|
const name = token.name ?? token.type;
|
|
1687
|
-
parser.options.debug?.(new CompileError(`Unexpected "${name}"
|
|
1686
|
+
parser.options.debug?.(new CompileError(`Unexpected "${name}"`, parser.template, token.loc));
|
|
1688
1687
|
yield 'NEXT';
|
|
1689
1688
|
yield new UnexpectedNode(name, token.val, token.loc, token.strip);
|
|
1690
1689
|
}
|
|
@@ -1697,11 +1696,11 @@ const plugin$1 = {
|
|
|
1697
1696
|
parsers: parsers$1,
|
|
1698
1697
|
};
|
|
1699
1698
|
|
|
1700
|
-
async function
|
|
1701
|
-
compiler.pushRaw(loc, `<!--
|
|
1699
|
+
async function compileUnknown({ name, loc }, compiler) {
|
|
1700
|
+
compiler.pushRaw(loc, `<!--Unknown "${name}"-->`);
|
|
1702
1701
|
}
|
|
1703
1702
|
const compilers = {
|
|
1704
|
-
|
|
1703
|
+
UNKNOWN: compileUnknown,
|
|
1705
1704
|
};
|
|
1706
1705
|
|
|
1707
1706
|
class UnknownNode extends Traversal {
|
|
@@ -1742,7 +1741,7 @@ class UnknownNode extends Traversal {
|
|
|
1742
1741
|
|
|
1743
1742
|
async function* parseUnknown(token, parser) {
|
|
1744
1743
|
const name = token.name ?? token.type;
|
|
1745
|
-
parser.options.debug?.(new CompileError(`Unknown "${name}"
|
|
1744
|
+
parser.options.debug?.(new CompileError(`Unknown "${name}"`, parser.template, token.loc));
|
|
1746
1745
|
yield 'NEXT';
|
|
1747
1746
|
yield new UnknownNode(name, token.val, token.loc, token.strip);
|
|
1748
1747
|
}
|
|
@@ -1781,7 +1780,7 @@ const baseOptions = {
|
|
|
1781
1780
|
const parserOptions = {
|
|
1782
1781
|
...baseOptions,
|
|
1783
1782
|
commentOpen: '{{#',
|
|
1784
|
-
commentClose: '}}',
|
|
1783
|
+
commentClose: '#}}',
|
|
1785
1784
|
directiveOpen: '{{',
|
|
1786
1785
|
directiveClose: '}}',
|
|
1787
1786
|
outputOpen: '{{=',
|
package/dist/index.js
CHANGED
|
@@ -192,7 +192,7 @@ ${output
|
|
|
192
192
|
writable: true,
|
|
193
193
|
value: CONTEXT
|
|
194
194
|
});
|
|
195
|
-
Object.defineProperty(this, "
|
|
195
|
+
Object.defineProperty(this, "stack", {
|
|
196
196
|
enumerable: true,
|
|
197
197
|
configurable: true,
|
|
198
198
|
writable: true,
|
|
@@ -207,15 +207,15 @@ ${output
|
|
|
207
207
|
}
|
|
208
208
|
in() {
|
|
209
209
|
this.context = `${this.context}_${this.index++}`;
|
|
210
|
-
this.
|
|
210
|
+
this.stack.push(this.context);
|
|
211
211
|
return this.context;
|
|
212
212
|
}
|
|
213
213
|
out() {
|
|
214
214
|
if (this.context === CONTEXT) {
|
|
215
215
|
return;
|
|
216
216
|
}
|
|
217
|
-
this.
|
|
218
|
-
this.context = this.
|
|
217
|
+
this.stack.pop();
|
|
218
|
+
this.context = this.stack.at(-1);
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
@@ -635,8 +635,6 @@ ${output
|
|
|
635
635
|
return this.compileLit(expression);
|
|
636
636
|
case 'PIPE':
|
|
637
637
|
return this.compilePipe(expression);
|
|
638
|
-
case 'OF':
|
|
639
|
-
return this.compileOf(expression);
|
|
640
638
|
case 'ASSIGN':
|
|
641
639
|
return this.compileAssign(expression);
|
|
642
640
|
case 'IS':
|
|
@@ -688,13 +686,6 @@ ${output
|
|
|
688
686
|
const { value: name, args = [] } = right;
|
|
689
687
|
return `(await ${this.filters}.${name}.call(${[this.context, this.compileExp(left), ...args.map((arg) => (arg.type === 'ASSIGN' ? `${this.context}.${arg.left.value}=${this.compileExp(arg.right)}` : this.compileExp(arg)))].join(',')}))`;
|
|
690
688
|
}
|
|
691
|
-
compileOf({ left, right }) {
|
|
692
|
-
// destructuring
|
|
693
|
-
if (left.type === 'SEQ') {
|
|
694
|
-
return `const {${left.elements.map(({ value }) => value).join(',')}} of ${this.compileExp(right)}`;
|
|
695
|
-
}
|
|
696
|
-
return `const ${left.value} of ${this.compileExp(right)}`;
|
|
697
|
-
}
|
|
698
689
|
compileAssign({ left, right }) {
|
|
699
690
|
if (left.type === 'ID') {
|
|
700
691
|
return `Object.assign(${this.context},{${left.value}:${this.compileExp(right)}});`;
|
|
@@ -894,6 +885,7 @@ ${output
|
|
|
894
885
|
}
|
|
895
886
|
|
|
896
887
|
async function* parseComment({ val, loc, strip }) {
|
|
888
|
+
console.log(val);
|
|
897
889
|
yield 'NEXT';
|
|
898
890
|
yield new CommentNode(val, loc, strip);
|
|
899
891
|
}
|
|
@@ -906,17 +898,24 @@ ${output
|
|
|
906
898
|
parsers: parsers$9,
|
|
907
899
|
};
|
|
908
900
|
|
|
909
|
-
async function compileFor({ loop, body }, compiler) {
|
|
901
|
+
async function compileFor({ loop: { left, right, loc }, body }, compiler) {
|
|
910
902
|
const { context } = compiler;
|
|
911
|
-
|
|
912
|
-
|
|
903
|
+
const expCompiler = new ExpCompiler();
|
|
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
|
|
906
|
+
.map((el) => el.type === 'ASSIGN'
|
|
907
|
+
? `${el.left.value}=${expCompiler.compile(el.right, context)}`
|
|
908
|
+
: el.value)
|
|
909
|
+
.join(',')}} of a_){`, `const ${compiler.in()}={`, `...${context},`, 'loop:{', 'first:i_===0,', 'index:i_++,', 'last:i_===n_,', '},', `${left.elements
|
|
910
|
+
.map((el) => (el.type === 'ASSIGN' ? el.left.value : el.value))
|
|
911
|
+
.join(',')},`, '};');
|
|
913
912
|
}
|
|
914
913
|
else {
|
|
915
|
-
compiler.pushRaw(
|
|
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},`, '};');
|
|
916
915
|
}
|
|
917
916
|
await compiler.compileNodes(body);
|
|
918
917
|
compiler.out();
|
|
919
|
-
compiler.pushRaw(null, '}');
|
|
918
|
+
compiler.pushRaw(null, '}', '};');
|
|
920
919
|
}
|
|
921
920
|
function compileBreak({ loc }, compiler) {
|
|
922
921
|
compiler.pushRaw(loc, 'break;');
|
|
@@ -1642,11 +1641,11 @@ ${output
|
|
|
1642
1641
|
parsers: parsers$2,
|
|
1643
1642
|
};
|
|
1644
1643
|
|
|
1645
|
-
async function compileUnexpected
|
|
1646
|
-
compiler.pushRaw(loc, `<!--
|
|
1644
|
+
async function compileUnexpected({ name, loc }, compiler) {
|
|
1645
|
+
compiler.pushRaw(loc, `<!--Unexpected "${name}"-->`);
|
|
1647
1646
|
}
|
|
1648
1647
|
const compilers$1 = {
|
|
1649
|
-
UNEXPECTED: compileUnexpected
|
|
1648
|
+
UNEXPECTED: compileUnexpected,
|
|
1650
1649
|
};
|
|
1651
1650
|
|
|
1652
1651
|
class UnexpectedNode extends Traversal {
|
|
@@ -1687,7 +1686,7 @@ ${output
|
|
|
1687
1686
|
|
|
1688
1687
|
async function* parseUnexpected(token, parser) {
|
|
1689
1688
|
const name = token.name ?? token.type;
|
|
1690
|
-
parser.options.debug?.(new CompileError(`Unexpected "${name}"
|
|
1689
|
+
parser.options.debug?.(new CompileError(`Unexpected "${name}"`, parser.template, token.loc));
|
|
1691
1690
|
yield 'NEXT';
|
|
1692
1691
|
yield new UnexpectedNode(name, token.val, token.loc, token.strip);
|
|
1693
1692
|
}
|
|
@@ -1700,11 +1699,11 @@ ${output
|
|
|
1700
1699
|
parsers: parsers$1,
|
|
1701
1700
|
};
|
|
1702
1701
|
|
|
1703
|
-
async function
|
|
1704
|
-
compiler.pushRaw(loc, `<!--
|
|
1702
|
+
async function compileUnknown({ name, loc }, compiler) {
|
|
1703
|
+
compiler.pushRaw(loc, `<!--Unknown "${name}"-->`);
|
|
1705
1704
|
}
|
|
1706
1705
|
const compilers = {
|
|
1707
|
-
|
|
1706
|
+
UNKNOWN: compileUnknown,
|
|
1708
1707
|
};
|
|
1709
1708
|
|
|
1710
1709
|
class UnknownNode extends Traversal {
|
|
@@ -1745,7 +1744,7 @@ ${output
|
|
|
1745
1744
|
|
|
1746
1745
|
async function* parseUnknown(token, parser) {
|
|
1747
1746
|
const name = token.name ?? token.type;
|
|
1748
|
-
parser.options.debug?.(new CompileError(`Unknown "${name}"
|
|
1747
|
+
parser.options.debug?.(new CompileError(`Unknown "${name}"`, parser.template, token.loc));
|
|
1749
1748
|
yield 'NEXT';
|
|
1750
1749
|
yield new UnknownNode(name, token.val, token.loc, token.strip);
|
|
1751
1750
|
}
|
|
@@ -1784,7 +1783,7 @@ ${output
|
|
|
1784
1783
|
const parserOptions = {
|
|
1785
1784
|
...baseOptions,
|
|
1786
1785
|
commentOpen: '{{#',
|
|
1787
|
-
commentClose: '}}',
|
|
1786
|
+
commentClose: '#}}',
|
|
1788
1787
|
directiveOpen: '{{',
|
|
1789
1788
|
directiveClose: '}}',
|
|
1790
1789
|
outputOpen: '{{=',
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "janja",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
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",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"globals": "^16.5.0",
|
|
41
41
|
"husky": "^9.1.7",
|
|
42
42
|
"jiti": "^2.6.1",
|
|
43
|
-
"prettier": "^3.7.
|
|
43
|
+
"prettier": "^3.7.3",
|
|
44
44
|
"rollup": "^4.53.3",
|
|
45
45
|
"rollup-plugin-dts": "^6.3.0",
|
|
46
46
|
"tslib": "^2.8.1",
|