janja 2.1.1 → 2.1.3
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 +314 -235
- package/dist/index.d.ts +53 -89
- package/dist/index.esm.js +314 -235
- package/dist/index.js +314 -235
- package/package.json +6 -6
package/dist/index.cjs.js
CHANGED
|
@@ -365,7 +365,7 @@ function values(value = {}) {
|
|
|
365
365
|
return Object.values(value);
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
-
var
|
|
368
|
+
var filters = /*#__PURE__*/Object.freeze({
|
|
369
369
|
__proto__: null,
|
|
370
370
|
abs: abs,
|
|
371
371
|
add: add,
|
|
@@ -421,13 +421,11 @@ async function compileSuper({ loc }, compiler) {
|
|
|
421
421
|
}
|
|
422
422
|
compiler.pushRaw(loc, `s+=await b["${compiler.state.block}"]?.s?.pop()?.()??"";`);
|
|
423
423
|
}
|
|
424
|
-
const compilers$
|
|
424
|
+
const compilers$c = {
|
|
425
425
|
BLOCK: compileBlock,
|
|
426
426
|
SUPER: compileSuper,
|
|
427
427
|
};
|
|
428
428
|
|
|
429
|
-
const createUnexpected = (token, parser) => parser.createUnexpectedNode(token);
|
|
430
|
-
|
|
431
429
|
class Traversal {
|
|
432
430
|
constructor() {
|
|
433
431
|
Object.defineProperty(this, "type", {
|
|
@@ -476,76 +474,6 @@ class RootNode extends Traversal {
|
|
|
476
474
|
});
|
|
477
475
|
}
|
|
478
476
|
}
|
|
479
|
-
class UnknownNode extends Traversal {
|
|
480
|
-
constructor(name, val, loc, strip) {
|
|
481
|
-
super();
|
|
482
|
-
Object.defineProperty(this, "name", {
|
|
483
|
-
enumerable: true,
|
|
484
|
-
configurable: true,
|
|
485
|
-
writable: true,
|
|
486
|
-
value: name
|
|
487
|
-
});
|
|
488
|
-
Object.defineProperty(this, "val", {
|
|
489
|
-
enumerable: true,
|
|
490
|
-
configurable: true,
|
|
491
|
-
writable: true,
|
|
492
|
-
value: val
|
|
493
|
-
});
|
|
494
|
-
Object.defineProperty(this, "loc", {
|
|
495
|
-
enumerable: true,
|
|
496
|
-
configurable: true,
|
|
497
|
-
writable: true,
|
|
498
|
-
value: loc
|
|
499
|
-
});
|
|
500
|
-
Object.defineProperty(this, "strip", {
|
|
501
|
-
enumerable: true,
|
|
502
|
-
configurable: true,
|
|
503
|
-
writable: true,
|
|
504
|
-
value: strip
|
|
505
|
-
});
|
|
506
|
-
Object.defineProperty(this, "type", {
|
|
507
|
-
enumerable: true,
|
|
508
|
-
configurable: true,
|
|
509
|
-
writable: true,
|
|
510
|
-
value: 'UNKNOWN'
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
class UnexpectedNode extends Traversal {
|
|
515
|
-
constructor(name, val, loc, strip) {
|
|
516
|
-
super();
|
|
517
|
-
Object.defineProperty(this, "name", {
|
|
518
|
-
enumerable: true,
|
|
519
|
-
configurable: true,
|
|
520
|
-
writable: true,
|
|
521
|
-
value: name
|
|
522
|
-
});
|
|
523
|
-
Object.defineProperty(this, "val", {
|
|
524
|
-
enumerable: true,
|
|
525
|
-
configurable: true,
|
|
526
|
-
writable: true,
|
|
527
|
-
value: val
|
|
528
|
-
});
|
|
529
|
-
Object.defineProperty(this, "loc", {
|
|
530
|
-
enumerable: true,
|
|
531
|
-
configurable: true,
|
|
532
|
-
writable: true,
|
|
533
|
-
value: loc
|
|
534
|
-
});
|
|
535
|
-
Object.defineProperty(this, "strip", {
|
|
536
|
-
enumerable: true,
|
|
537
|
-
configurable: true,
|
|
538
|
-
writable: true,
|
|
539
|
-
value: strip
|
|
540
|
-
});
|
|
541
|
-
Object.defineProperty(this, "type", {
|
|
542
|
-
enumerable: true,
|
|
543
|
-
configurable: true,
|
|
544
|
-
writable: true,
|
|
545
|
-
value: 'UNEXPECTED'
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
477
|
|
|
550
478
|
class BlockNode extends Traversal {
|
|
551
479
|
constructor(val, body, loc, strip) {
|
|
@@ -612,38 +540,38 @@ class SuperNode extends Traversal {
|
|
|
612
540
|
}
|
|
613
541
|
}
|
|
614
542
|
|
|
615
|
-
function parseBlock(token, parser) {
|
|
543
|
+
async function* parseBlock(token, parser) {
|
|
616
544
|
if (!token.expression) {
|
|
617
545
|
parser.emitExpErr(token);
|
|
618
546
|
return;
|
|
619
547
|
}
|
|
620
|
-
|
|
621
|
-
const body = parser.parseUntil(['endblock']);
|
|
548
|
+
yield 'NEXT';
|
|
549
|
+
const body = await parser.parseUntil(['endblock']);
|
|
622
550
|
if (parser.match(['endblock'])) {
|
|
623
|
-
|
|
551
|
+
yield 'NEXT';
|
|
624
552
|
}
|
|
625
553
|
else {
|
|
626
554
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
627
555
|
}
|
|
628
|
-
|
|
556
|
+
yield new BlockNode(parser.parseExp(token.expression), body, token.loc, token.strip);
|
|
629
557
|
}
|
|
630
|
-
function parseSuper(token, parser) {
|
|
558
|
+
async function* parseSuper(token, parser) {
|
|
631
559
|
if (token.expression) {
|
|
632
560
|
parser.emitExpErr(token, false);
|
|
633
561
|
return;
|
|
634
562
|
}
|
|
635
|
-
|
|
636
|
-
|
|
563
|
+
yield 'NEXT';
|
|
564
|
+
yield new SuperNode(token.val, token.loc, token.strip);
|
|
637
565
|
}
|
|
638
|
-
const parsers$
|
|
566
|
+
const parsers$c = {
|
|
639
567
|
block: parseBlock,
|
|
640
568
|
super: parseSuper,
|
|
641
|
-
endblock:
|
|
569
|
+
endblock: 'unexpected',
|
|
642
570
|
};
|
|
643
571
|
|
|
644
|
-
const plugin$
|
|
645
|
-
compilers: compilers$
|
|
646
|
-
parsers: parsers$
|
|
572
|
+
const plugin$c = {
|
|
573
|
+
compilers: compilers$c,
|
|
574
|
+
parsers: parsers$c,
|
|
647
575
|
};
|
|
648
576
|
|
|
649
577
|
const expTokenOperators = {
|
|
@@ -732,7 +660,8 @@ class ExpCompiler {
|
|
|
732
660
|
return this.compileTernary(expression);
|
|
733
661
|
case 'SEQ':
|
|
734
662
|
return this.compileSeq(expression);
|
|
735
|
-
|
|
663
|
+
default:
|
|
664
|
+
return '';
|
|
736
665
|
}
|
|
737
666
|
}
|
|
738
667
|
compileNot({ argument }) {
|
|
@@ -789,7 +718,7 @@ async function compileCall({ val, body, loc }, compiler) {
|
|
|
789
718
|
await compiler.compileNodes(body);
|
|
790
719
|
compiler.pushRaw(null, '});');
|
|
791
720
|
}
|
|
792
|
-
const compilers$
|
|
721
|
+
const compilers$b = {
|
|
793
722
|
CALL: compileCall,
|
|
794
723
|
};
|
|
795
724
|
|
|
@@ -829,29 +758,29 @@ class CallNode extends Traversal {
|
|
|
829
758
|
}
|
|
830
759
|
}
|
|
831
760
|
|
|
832
|
-
function parseCall(token, parser) {
|
|
761
|
+
async function* parseCall(token, parser) {
|
|
833
762
|
if (!token.expression) {
|
|
834
763
|
parser.emitExpErr(token);
|
|
835
764
|
return;
|
|
836
765
|
}
|
|
837
|
-
|
|
838
|
-
const body = parser.parseUntil(['endcall']);
|
|
766
|
+
yield 'NEXT';
|
|
767
|
+
const body = await parser.parseUntil(['endcall']);
|
|
839
768
|
if (parser.match(['endcall'])) {
|
|
840
|
-
|
|
769
|
+
yield 'NEXT';
|
|
841
770
|
}
|
|
842
771
|
else {
|
|
843
772
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
844
773
|
}
|
|
845
|
-
|
|
774
|
+
yield new CallNode(parser.parseExp(token.expression), body, token.loc, token.strip);
|
|
846
775
|
}
|
|
847
|
-
const parsers$
|
|
776
|
+
const parsers$b = {
|
|
848
777
|
call: parseCall,
|
|
849
|
-
endcall:
|
|
778
|
+
endcall: 'unexpected',
|
|
850
779
|
};
|
|
851
780
|
|
|
852
|
-
const plugin$
|
|
853
|
-
compilers: compilers$
|
|
854
|
-
parsers: parsers$
|
|
781
|
+
const plugin$b = {
|
|
782
|
+
compilers: compilers$b,
|
|
783
|
+
parsers: parsers$b,
|
|
855
784
|
};
|
|
856
785
|
|
|
857
786
|
async function compileCapture({ val, body, loc }, compiler) {
|
|
@@ -859,7 +788,7 @@ async function compileCapture({ val, body, loc }, compiler) {
|
|
|
859
788
|
await compiler.compileNodes(body);
|
|
860
789
|
compiler.pushRaw(null, 'return s;})("");');
|
|
861
790
|
}
|
|
862
|
-
const compilers$
|
|
791
|
+
const compilers$a = {
|
|
863
792
|
CAPTURE: compileCapture,
|
|
864
793
|
};
|
|
865
794
|
|
|
@@ -899,29 +828,29 @@ class CaptureNode extends Traversal {
|
|
|
899
828
|
}
|
|
900
829
|
}
|
|
901
830
|
|
|
902
|
-
function parseCapture(token, parser) {
|
|
831
|
+
async function* parseCapture(token, parser) {
|
|
903
832
|
if (!token.expression) {
|
|
904
833
|
parser.emitExpErr(token);
|
|
905
834
|
return;
|
|
906
835
|
}
|
|
907
|
-
|
|
908
|
-
const body = parser.parseUntil(['endcapture']);
|
|
836
|
+
yield 'NEXT';
|
|
837
|
+
const body = await parser.parseUntil(['endcapture']);
|
|
909
838
|
if (parser.match(['endcapture'])) {
|
|
910
|
-
|
|
839
|
+
yield 'NEXT';
|
|
911
840
|
}
|
|
912
841
|
else {
|
|
913
842
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
914
843
|
}
|
|
915
|
-
|
|
844
|
+
yield new CaptureNode(parser.parseExp(token.expression), body, token.loc, token.strip);
|
|
916
845
|
}
|
|
917
|
-
const parsers$
|
|
846
|
+
const parsers$a = {
|
|
918
847
|
capture: parseCapture,
|
|
919
|
-
endcapture:
|
|
848
|
+
endcapture: 'unexpected',
|
|
920
849
|
};
|
|
921
850
|
|
|
922
|
-
const plugin$
|
|
923
|
-
compilers: compilers$
|
|
924
|
-
parsers: parsers$
|
|
851
|
+
const plugin$a = {
|
|
852
|
+
compilers: compilers$a,
|
|
853
|
+
parsers: parsers$a,
|
|
925
854
|
};
|
|
926
855
|
|
|
927
856
|
async function compileComment({ val, loc }, compiler) {
|
|
@@ -929,7 +858,7 @@ async function compileComment({ val, loc }, compiler) {
|
|
|
929
858
|
compiler.pushStr(loc, `<!--${val}-->`);
|
|
930
859
|
}
|
|
931
860
|
}
|
|
932
|
-
const compilers$
|
|
861
|
+
const compilers$9 = {
|
|
933
862
|
COMMENT: compileComment,
|
|
934
863
|
};
|
|
935
864
|
|
|
@@ -963,17 +892,17 @@ class CommentNode extends Traversal {
|
|
|
963
892
|
}
|
|
964
893
|
}
|
|
965
894
|
|
|
966
|
-
function parseComment({ val, loc, strip }
|
|
967
|
-
|
|
968
|
-
|
|
895
|
+
async function* parseComment({ val, loc, strip }) {
|
|
896
|
+
yield 'NEXT';
|
|
897
|
+
yield new CommentNode(val, loc, strip);
|
|
969
898
|
}
|
|
970
|
-
const parsers$
|
|
899
|
+
const parsers$9 = {
|
|
971
900
|
comment: parseComment,
|
|
972
901
|
};
|
|
973
902
|
|
|
974
|
-
const plugin$
|
|
975
|
-
compilers: compilers$
|
|
976
|
-
parsers: parsers$
|
|
903
|
+
const plugin$9 = {
|
|
904
|
+
compilers: compilers$9,
|
|
905
|
+
parsers: parsers$9,
|
|
977
906
|
};
|
|
978
907
|
|
|
979
908
|
async function compileFor({ loop, body }, compiler) {
|
|
@@ -994,7 +923,7 @@ function compileBreak({ loc }, compiler) {
|
|
|
994
923
|
function compileContinue({ loc }, compiler) {
|
|
995
924
|
compiler.pushRaw(loc, 'continue;');
|
|
996
925
|
}
|
|
997
|
-
const compilers$
|
|
926
|
+
const compilers$8 = {
|
|
998
927
|
FOR: compileFor,
|
|
999
928
|
BREAK: compileBreak,
|
|
1000
929
|
CONTINUE: compileContinue,
|
|
@@ -1095,24 +1024,24 @@ class ContinueNode extends Traversal {
|
|
|
1095
1024
|
}
|
|
1096
1025
|
|
|
1097
1026
|
const wm$1 = new WeakMap();
|
|
1098
|
-
function parseFor(token, parser) {
|
|
1027
|
+
async function* parseFor(token, parser) {
|
|
1099
1028
|
if (!token.expression) {
|
|
1100
1029
|
parser.emitExpErr(token);
|
|
1101
1030
|
return;
|
|
1102
1031
|
}
|
|
1103
1032
|
wm$1.set(parser, true);
|
|
1104
|
-
|
|
1105
|
-
const body = parser.parseUntil(['endfor']);
|
|
1033
|
+
yield 'NEXT';
|
|
1034
|
+
const body = await parser.parseUntil(['endfor']);
|
|
1106
1035
|
wm$1.set(parser, false);
|
|
1107
1036
|
if (parser.match(['endfor'])) {
|
|
1108
|
-
|
|
1037
|
+
yield 'NEXT';
|
|
1109
1038
|
}
|
|
1110
1039
|
else {
|
|
1111
1040
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
1112
1041
|
}
|
|
1113
|
-
|
|
1042
|
+
yield new ForNode(parser.parseExp(token.expression), body, token.loc, token.strip);
|
|
1114
1043
|
}
|
|
1115
|
-
function parseBreak(token, parser) {
|
|
1044
|
+
async function* parseBreak(token, parser) {
|
|
1116
1045
|
if (token.expression) {
|
|
1117
1046
|
parser.emitExpErr(token, false);
|
|
1118
1047
|
return;
|
|
@@ -1121,10 +1050,10 @@ function parseBreak(token, parser) {
|
|
|
1121
1050
|
parser.options.debug?.(new CompileError('"break" directive used outside of a loop', parser.template, token.loc));
|
|
1122
1051
|
return;
|
|
1123
1052
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1053
|
+
yield 'NEXT';
|
|
1054
|
+
yield new BreakNode(token.val, token.loc, token.strip);
|
|
1126
1055
|
}
|
|
1127
|
-
function parseContinue(token, parser) {
|
|
1056
|
+
async function* parseContinue(token, parser) {
|
|
1128
1057
|
if (token.expression) {
|
|
1129
1058
|
parser.emitExpErr(token, false);
|
|
1130
1059
|
return;
|
|
@@ -1133,19 +1062,19 @@ function parseContinue(token, parser) {
|
|
|
1133
1062
|
parser.options.debug?.(new CompileError('"continue" directive used outside of a loop', parser.template, token.loc));
|
|
1134
1063
|
return;
|
|
1135
1064
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1065
|
+
yield 'NEXT';
|
|
1066
|
+
yield new ContinueNode(token.val, token.loc, token.strip);
|
|
1138
1067
|
}
|
|
1139
|
-
const parsers$
|
|
1068
|
+
const parsers$8 = {
|
|
1140
1069
|
for: parseFor,
|
|
1141
1070
|
break: parseBreak,
|
|
1142
1071
|
continue: parseContinue,
|
|
1143
|
-
endfor:
|
|
1072
|
+
endfor: 'unexpected',
|
|
1144
1073
|
};
|
|
1145
1074
|
|
|
1146
|
-
const plugin$
|
|
1147
|
-
compilers: compilers$
|
|
1148
|
-
parsers: parsers$
|
|
1075
|
+
const plugin$8 = {
|
|
1076
|
+
compilers: compilers$8,
|
|
1077
|
+
parsers: parsers$8,
|
|
1149
1078
|
};
|
|
1150
1079
|
|
|
1151
1080
|
async function compileIf({ test, body, alternatives }, compiler) {
|
|
@@ -1163,7 +1092,7 @@ async function compileIf({ test, body, alternatives }, compiler) {
|
|
|
1163
1092
|
compiler.pushRaw(null, '}');
|
|
1164
1093
|
}
|
|
1165
1094
|
}
|
|
1166
|
-
const compilers$
|
|
1095
|
+
const compilers$7 = {
|
|
1167
1096
|
IF: compileIf,
|
|
1168
1097
|
};
|
|
1169
1098
|
|
|
@@ -1277,70 +1206,96 @@ class ElseNode extends Traversal {
|
|
|
1277
1206
|
}
|
|
1278
1207
|
}
|
|
1279
1208
|
|
|
1280
|
-
function parseIf(token, parser) {
|
|
1209
|
+
async function* parseIf(token, parser) {
|
|
1281
1210
|
if (!token.expression) {
|
|
1282
1211
|
parser.emitExpErr(token);
|
|
1283
1212
|
return;
|
|
1284
1213
|
}
|
|
1285
|
-
|
|
1286
|
-
const body = parser.parseUntil([
|
|
1214
|
+
yield 'NEXT';
|
|
1215
|
+
const body = await parser.parseUntil([
|
|
1216
|
+
'else',
|
|
1217
|
+
'elseif',
|
|
1218
|
+
'elsif',
|
|
1219
|
+
'elif',
|
|
1220
|
+
'endif',
|
|
1221
|
+
]);
|
|
1287
1222
|
const alternatives = [];
|
|
1288
1223
|
while (parser.match(['else', 'elseif', 'elsif', 'elif'])) {
|
|
1289
1224
|
const branchToken = parser.peek();
|
|
1290
1225
|
if (branchToken.name.toLowerCase() === 'else') {
|
|
1291
|
-
const
|
|
1292
|
-
|
|
1293
|
-
|
|
1226
|
+
const g = parseElse(branchToken, parser);
|
|
1227
|
+
while (true) {
|
|
1228
|
+
const { value, done } = await g.next();
|
|
1229
|
+
if (done) {
|
|
1230
|
+
break;
|
|
1231
|
+
}
|
|
1232
|
+
if (value) {
|
|
1233
|
+
if (value === 'NEXT') {
|
|
1234
|
+
yield 'NEXT';
|
|
1235
|
+
continue;
|
|
1236
|
+
}
|
|
1237
|
+
alternatives.push(value);
|
|
1238
|
+
}
|
|
1294
1239
|
}
|
|
1295
1240
|
}
|
|
1296
1241
|
else {
|
|
1297
|
-
const
|
|
1298
|
-
|
|
1299
|
-
|
|
1242
|
+
const g = parseElseIf(branchToken, parser);
|
|
1243
|
+
while (true) {
|
|
1244
|
+
const { value, done } = await g.next();
|
|
1245
|
+
if (done) {
|
|
1246
|
+
break;
|
|
1247
|
+
}
|
|
1248
|
+
if (value) {
|
|
1249
|
+
if (value === 'NEXT') {
|
|
1250
|
+
yield 'NEXT';
|
|
1251
|
+
continue;
|
|
1252
|
+
}
|
|
1253
|
+
alternatives.push(value);
|
|
1254
|
+
}
|
|
1300
1255
|
}
|
|
1301
1256
|
}
|
|
1302
1257
|
}
|
|
1303
1258
|
if (parser.match(['endif'])) {
|
|
1304
|
-
|
|
1259
|
+
yield 'NEXT';
|
|
1305
1260
|
}
|
|
1306
1261
|
else {
|
|
1307
1262
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
1308
1263
|
}
|
|
1309
|
-
|
|
1264
|
+
yield new IfNode(parser.parseExp(token.expression), body, alternatives, token.loc, token.strip);
|
|
1310
1265
|
}
|
|
1311
|
-
function parseElseIf(token, parser) {
|
|
1266
|
+
async function* parseElseIf(token, parser) {
|
|
1312
1267
|
if (!token.expression) {
|
|
1313
1268
|
parser.emitExpErr(token);
|
|
1314
1269
|
return;
|
|
1315
1270
|
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1271
|
+
yield 'NEXT';
|
|
1272
|
+
yield new ElseIfNode(parser.parseExp(token.expression), await parser.parseUntil(['else', 'elseif', 'elsif', 'elif', 'endif']), token.loc, token.strip);
|
|
1318
1273
|
}
|
|
1319
|
-
function parseElse(token, parser) {
|
|
1274
|
+
async function* parseElse(token, parser) {
|
|
1320
1275
|
if (token.expression) {
|
|
1321
1276
|
parser.emitExpErr(token, false);
|
|
1322
1277
|
return;
|
|
1323
1278
|
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1279
|
+
yield 'NEXT';
|
|
1280
|
+
yield new ElseNode(await parser.parseUntil(['endif']), token.loc, token.strip);
|
|
1326
1281
|
}
|
|
1327
|
-
const parsers$
|
|
1282
|
+
const parsers$7 = {
|
|
1328
1283
|
if: parseIf,
|
|
1329
|
-
elseif:
|
|
1330
|
-
elsif:
|
|
1331
|
-
elif:
|
|
1332
|
-
endif:
|
|
1284
|
+
elseif: 'unexpected',
|
|
1285
|
+
elsif: 'unexpected',
|
|
1286
|
+
elif: 'unexpected',
|
|
1287
|
+
endif: 'unexpected',
|
|
1333
1288
|
};
|
|
1334
1289
|
|
|
1335
|
-
const plugin$
|
|
1336
|
-
compilers: compilers$
|
|
1337
|
-
parsers: parsers$
|
|
1290
|
+
const plugin$7 = {
|
|
1291
|
+
compilers: compilers$7,
|
|
1292
|
+
parsers: parsers$7,
|
|
1338
1293
|
};
|
|
1339
1294
|
|
|
1340
1295
|
async function compileInclude({ val: { value }, loc }, compiler) {
|
|
1341
1296
|
compiler.pushRaw(loc, `s+=await p["${value}"]?.()??"";`);
|
|
1342
1297
|
}
|
|
1343
|
-
const compilers$
|
|
1298
|
+
const compilers$6 = {
|
|
1344
1299
|
INCLUDE: compileInclude,
|
|
1345
1300
|
};
|
|
1346
1301
|
|
|
@@ -1374,21 +1329,21 @@ class IncludeNode extends Traversal {
|
|
|
1374
1329
|
}
|
|
1375
1330
|
}
|
|
1376
1331
|
|
|
1377
|
-
function parseInclude(token, parser) {
|
|
1332
|
+
async function* parseInclude(token, parser) {
|
|
1378
1333
|
if (!token.expression) {
|
|
1379
1334
|
parser.emitExpErr(token);
|
|
1380
1335
|
return;
|
|
1381
1336
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1337
|
+
yield 'NEXT';
|
|
1338
|
+
yield new IncludeNode(parser.parseExp(token.expression), token.loc, token.strip);
|
|
1384
1339
|
}
|
|
1385
|
-
const parsers$
|
|
1340
|
+
const parsers$6 = {
|
|
1386
1341
|
include: parseInclude,
|
|
1387
1342
|
};
|
|
1388
1343
|
|
|
1389
|
-
const plugin$
|
|
1390
|
-
compilers: compilers$
|
|
1391
|
-
parsers: parsers$
|
|
1344
|
+
const plugin$6 = {
|
|
1345
|
+
compilers: compilers$6,
|
|
1346
|
+
parsers: parsers$6,
|
|
1392
1347
|
};
|
|
1393
1348
|
|
|
1394
1349
|
async function compileMacro({ val: { left, right }, loc, body }, compiler) {
|
|
@@ -1400,7 +1355,7 @@ async function compileMacro({ val: { left, right }, loc, body }, compiler) {
|
|
|
1400
1355
|
? `${el.left.value}=${expCompiler.compile(el.right)}`
|
|
1401
1356
|
: el.value)
|
|
1402
1357
|
.join(',')})=>async(_c)=>{`, `const ${compiler.in()}={`, `...${context},`, elements
|
|
1403
|
-
.map((el) => el.type === 'ASSIGN' ? el.left.value : el.value)
|
|
1358
|
+
.map((el) => (el.type === 'ASSIGN' ? el.left.value : el.value))
|
|
1404
1359
|
.join(','), '};');
|
|
1405
1360
|
await compiler.compileNodes(body);
|
|
1406
1361
|
compiler.out();
|
|
@@ -1409,7 +1364,7 @@ async function compileMacro({ val: { left, right }, loc, body }, compiler) {
|
|
|
1409
1364
|
function compileCaller({ loc }, compiler) {
|
|
1410
1365
|
compiler.pushRaw(loc, 'await _c?.();');
|
|
1411
1366
|
}
|
|
1412
|
-
const compilers$
|
|
1367
|
+
const compilers$5 = {
|
|
1413
1368
|
MACRO: compileMacro,
|
|
1414
1369
|
CALLER: compileCaller,
|
|
1415
1370
|
};
|
|
@@ -1480,24 +1435,24 @@ class CallerNode extends Traversal {
|
|
|
1480
1435
|
}
|
|
1481
1436
|
|
|
1482
1437
|
const wm = new WeakMap();
|
|
1483
|
-
function parseMacro(token, parser) {
|
|
1438
|
+
async function* parseMacro(token, parser) {
|
|
1484
1439
|
if (!token.expression) {
|
|
1485
1440
|
parser.emitExpErr(token);
|
|
1486
1441
|
return;
|
|
1487
1442
|
}
|
|
1488
1443
|
wm.set(parser, true);
|
|
1489
|
-
|
|
1490
|
-
const body = parser.parseUntil(['endmacro']);
|
|
1444
|
+
yield 'NEXT';
|
|
1445
|
+
const body = await parser.parseUntil(['endmacro']);
|
|
1491
1446
|
wm.set(parser, false);
|
|
1492
1447
|
if (parser.match(['endmacro'])) {
|
|
1493
|
-
|
|
1448
|
+
yield 'NEXT';
|
|
1494
1449
|
}
|
|
1495
1450
|
else {
|
|
1496
1451
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
1497
1452
|
}
|
|
1498
|
-
|
|
1453
|
+
yield new MacroNode(parser.parseExp(token.expression), body, token.loc, token.strip);
|
|
1499
1454
|
}
|
|
1500
|
-
function parseCaller(token, parser) {
|
|
1455
|
+
async function* parseCaller(token, parser) {
|
|
1501
1456
|
if (token.expression) {
|
|
1502
1457
|
parser.emitExpErr(token, false);
|
|
1503
1458
|
return;
|
|
@@ -1506,24 +1461,24 @@ function parseCaller(token, parser) {
|
|
|
1506
1461
|
parser.options.debug?.(new CompileError('"caller" directive used outside of a macro', parser.template, token.loc));
|
|
1507
1462
|
return;
|
|
1508
1463
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1464
|
+
yield 'NEXT';
|
|
1465
|
+
yield new CallerNode(token.val, token.loc, token.strip);
|
|
1511
1466
|
}
|
|
1512
|
-
const parsers$
|
|
1467
|
+
const parsers$5 = {
|
|
1513
1468
|
macro: parseMacro,
|
|
1514
1469
|
caller: parseCaller,
|
|
1515
|
-
endmacro:
|
|
1470
|
+
endmacro: 'unexpected',
|
|
1516
1471
|
};
|
|
1517
1472
|
|
|
1518
|
-
const plugin$
|
|
1519
|
-
compilers: compilers$
|
|
1520
|
-
parsers: parsers$
|
|
1473
|
+
const plugin$5 = {
|
|
1474
|
+
compilers: compilers$5,
|
|
1475
|
+
parsers: parsers$5,
|
|
1521
1476
|
};
|
|
1522
1477
|
|
|
1523
1478
|
async function compileOutput({ exp }, compiler) {
|
|
1524
1479
|
compiler.pushVar(exp.loc, new ExpCompiler().compile(exp, compiler.context));
|
|
1525
1480
|
}
|
|
1526
|
-
const compilers$
|
|
1481
|
+
const compilers$4 = {
|
|
1527
1482
|
OUTPUT: compileOutput,
|
|
1528
1483
|
};
|
|
1529
1484
|
|
|
@@ -1563,23 +1518,23 @@ class OutputNode extends Traversal {
|
|
|
1563
1518
|
}
|
|
1564
1519
|
}
|
|
1565
1520
|
|
|
1566
|
-
function parseOutput(token, parser) {
|
|
1567
|
-
|
|
1568
|
-
|
|
1521
|
+
async function* parseOutput(token, parser) {
|
|
1522
|
+
yield 'NEXT';
|
|
1523
|
+
yield new OutputNode(token.val, token.loc, token.strip, parser.parseExp(token));
|
|
1569
1524
|
}
|
|
1570
|
-
const parsers$
|
|
1525
|
+
const parsers$4 = {
|
|
1571
1526
|
output: parseOutput,
|
|
1572
1527
|
};
|
|
1573
1528
|
|
|
1574
|
-
const plugin$
|
|
1575
|
-
compilers: compilers$
|
|
1576
|
-
parsers: parsers$
|
|
1529
|
+
const plugin$4 = {
|
|
1530
|
+
compilers: compilers$4,
|
|
1531
|
+
parsers: parsers$4,
|
|
1577
1532
|
};
|
|
1578
1533
|
|
|
1579
1534
|
async function compileSet({ val, loc }, compiler) {
|
|
1580
1535
|
compiler.pushRaw(loc, new ExpCompiler().compile(val, compiler.context));
|
|
1581
1536
|
}
|
|
1582
|
-
const compilers$
|
|
1537
|
+
const compilers$3 = {
|
|
1583
1538
|
SET: compileSet,
|
|
1584
1539
|
};
|
|
1585
1540
|
|
|
@@ -1613,21 +1568,21 @@ class SetNode extends Traversal {
|
|
|
1613
1568
|
}
|
|
1614
1569
|
}
|
|
1615
1570
|
|
|
1616
|
-
function parseSet(token, parser) {
|
|
1571
|
+
async function* parseSet(token, parser) {
|
|
1617
1572
|
if (!token.expression) {
|
|
1618
1573
|
parser.emitExpErr(token);
|
|
1619
1574
|
return;
|
|
1620
1575
|
}
|
|
1621
|
-
|
|
1622
|
-
|
|
1576
|
+
yield 'NEXT';
|
|
1577
|
+
yield new SetNode(parser.parseExp(token.expression), token.loc, token.strip);
|
|
1623
1578
|
}
|
|
1624
|
-
const parsers$
|
|
1579
|
+
const parsers$3 = {
|
|
1625
1580
|
set: parseSet,
|
|
1626
1581
|
};
|
|
1627
1582
|
|
|
1628
|
-
const plugin$
|
|
1629
|
-
compilers: compilers$
|
|
1630
|
-
parsers: parsers$
|
|
1583
|
+
const plugin$3 = {
|
|
1584
|
+
compilers: compilers$3,
|
|
1585
|
+
parsers: parsers$3,
|
|
1631
1586
|
};
|
|
1632
1587
|
|
|
1633
1588
|
async function compileText({ val, loc, strip: { start, end } }, compiler) {
|
|
@@ -1639,7 +1594,7 @@ async function compileText({ val, loc, strip: { start, end } }, compiler) {
|
|
|
1639
1594
|
}
|
|
1640
1595
|
compiler.pushStr(loc, val);
|
|
1641
1596
|
}
|
|
1642
|
-
const compilers = {
|
|
1597
|
+
const compilers$2 = {
|
|
1643
1598
|
TEXT: compileText,
|
|
1644
1599
|
};
|
|
1645
1600
|
|
|
@@ -1673,35 +1628,153 @@ class TextNode extends Traversal {
|
|
|
1673
1628
|
}
|
|
1674
1629
|
}
|
|
1675
1630
|
|
|
1676
|
-
function parseText(token
|
|
1677
|
-
|
|
1678
|
-
|
|
1631
|
+
async function* parseText(token) {
|
|
1632
|
+
yield 'NEXT';
|
|
1633
|
+
yield new TextNode(token.val, token.loc, token.strip);
|
|
1679
1634
|
}
|
|
1680
|
-
const parsers = {
|
|
1635
|
+
const parsers$2 = {
|
|
1681
1636
|
text: parseText,
|
|
1682
1637
|
};
|
|
1683
1638
|
|
|
1639
|
+
const plugin$2 = {
|
|
1640
|
+
compilers: compilers$2,
|
|
1641
|
+
parsers: parsers$2,
|
|
1642
|
+
};
|
|
1643
|
+
|
|
1644
|
+
async function compileUnexpected$1({ name, val, loc }, compiler) {
|
|
1645
|
+
compiler.pushRaw(loc, `<!-- unexpected "${name}" with value "${val}" -->`);
|
|
1646
|
+
}
|
|
1647
|
+
const compilers$1 = {
|
|
1648
|
+
UNEXPECTED: compileUnexpected$1,
|
|
1649
|
+
};
|
|
1650
|
+
|
|
1651
|
+
class UnexpectedNode extends Traversal {
|
|
1652
|
+
constructor(name, val, loc, strip) {
|
|
1653
|
+
super();
|
|
1654
|
+
Object.defineProperty(this, "name", {
|
|
1655
|
+
enumerable: true,
|
|
1656
|
+
configurable: true,
|
|
1657
|
+
writable: true,
|
|
1658
|
+
value: name
|
|
1659
|
+
});
|
|
1660
|
+
Object.defineProperty(this, "val", {
|
|
1661
|
+
enumerable: true,
|
|
1662
|
+
configurable: true,
|
|
1663
|
+
writable: true,
|
|
1664
|
+
value: val
|
|
1665
|
+
});
|
|
1666
|
+
Object.defineProperty(this, "loc", {
|
|
1667
|
+
enumerable: true,
|
|
1668
|
+
configurable: true,
|
|
1669
|
+
writable: true,
|
|
1670
|
+
value: loc
|
|
1671
|
+
});
|
|
1672
|
+
Object.defineProperty(this, "strip", {
|
|
1673
|
+
enumerable: true,
|
|
1674
|
+
configurable: true,
|
|
1675
|
+
writable: true,
|
|
1676
|
+
value: strip
|
|
1677
|
+
});
|
|
1678
|
+
Object.defineProperty(this, "type", {
|
|
1679
|
+
enumerable: true,
|
|
1680
|
+
configurable: true,
|
|
1681
|
+
writable: true,
|
|
1682
|
+
value: 'unexpected'
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
async function* parseUnexpected(token, parser) {
|
|
1688
|
+
const name = token.name ?? token.type;
|
|
1689
|
+
parser.options.debug?.(new CompileError(`Unexpected "${name}" node`, parser.template, token.loc));
|
|
1690
|
+
yield 'NEXT';
|
|
1691
|
+
yield new UnexpectedNode(name, token.val, token.loc, token.strip);
|
|
1692
|
+
}
|
|
1693
|
+
const parsers$1 = {
|
|
1694
|
+
unexpected: parseUnexpected,
|
|
1695
|
+
};
|
|
1696
|
+
|
|
1697
|
+
const plugin$1 = {
|
|
1698
|
+
compilers: compilers$1,
|
|
1699
|
+
parsers: parsers$1,
|
|
1700
|
+
};
|
|
1701
|
+
|
|
1702
|
+
async function compileUnexpected({ name, val, loc }, compiler) {
|
|
1703
|
+
compiler.pushRaw(loc, `<!-- unexpected "${name}" with value "${val}" -->`);
|
|
1704
|
+
}
|
|
1705
|
+
const compilers = {
|
|
1706
|
+
UNEXPECTED: compileUnexpected,
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1709
|
+
class UnknownNode extends Traversal {
|
|
1710
|
+
constructor(name, val, loc, strip) {
|
|
1711
|
+
super();
|
|
1712
|
+
Object.defineProperty(this, "name", {
|
|
1713
|
+
enumerable: true,
|
|
1714
|
+
configurable: true,
|
|
1715
|
+
writable: true,
|
|
1716
|
+
value: name
|
|
1717
|
+
});
|
|
1718
|
+
Object.defineProperty(this, "val", {
|
|
1719
|
+
enumerable: true,
|
|
1720
|
+
configurable: true,
|
|
1721
|
+
writable: true,
|
|
1722
|
+
value: val
|
|
1723
|
+
});
|
|
1724
|
+
Object.defineProperty(this, "loc", {
|
|
1725
|
+
enumerable: true,
|
|
1726
|
+
configurable: true,
|
|
1727
|
+
writable: true,
|
|
1728
|
+
value: loc
|
|
1729
|
+
});
|
|
1730
|
+
Object.defineProperty(this, "strip", {
|
|
1731
|
+
enumerable: true,
|
|
1732
|
+
configurable: true,
|
|
1733
|
+
writable: true,
|
|
1734
|
+
value: strip
|
|
1735
|
+
});
|
|
1736
|
+
Object.defineProperty(this, "type", {
|
|
1737
|
+
enumerable: true,
|
|
1738
|
+
configurable: true,
|
|
1739
|
+
writable: true,
|
|
1740
|
+
value: 'UNKNOWN'
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
async function* parseUnknown(token, parser) {
|
|
1746
|
+
const name = token.name ?? token.type;
|
|
1747
|
+
parser.options.debug?.(new CompileError(`Unknown "${name}" node`, parser.template, token.loc));
|
|
1748
|
+
yield 'NEXT';
|
|
1749
|
+
yield new UnknownNode(name, token.val, token.loc, token.strip);
|
|
1750
|
+
}
|
|
1751
|
+
const parsers = {
|
|
1752
|
+
unknown: parseUnknown,
|
|
1753
|
+
};
|
|
1754
|
+
|
|
1684
1755
|
const plugin = {
|
|
1685
1756
|
compilers,
|
|
1686
1757
|
parsers,
|
|
1687
1758
|
};
|
|
1688
1759
|
|
|
1689
1760
|
const plugins = [
|
|
1690
|
-
plugin$
|
|
1761
|
+
plugin$c,
|
|
1762
|
+
plugin$b,
|
|
1691
1763
|
plugin$9,
|
|
1692
|
-
plugin$
|
|
1764
|
+
plugin$a,
|
|
1693
1765
|
plugin$8,
|
|
1766
|
+
plugin$7,
|
|
1694
1767
|
plugin$6,
|
|
1695
1768
|
plugin$5,
|
|
1696
|
-
plugin$4,
|
|
1697
1769
|
plugin$3,
|
|
1770
|
+
plugin$2,
|
|
1771
|
+
plugin$4,
|
|
1698
1772
|
plugin$1,
|
|
1699
1773
|
plugin,
|
|
1700
|
-
plugin$2,
|
|
1701
1774
|
];
|
|
1702
1775
|
|
|
1703
1776
|
const baseOptions = {
|
|
1704
|
-
filters
|
|
1777
|
+
filters,
|
|
1705
1778
|
parsers: {},
|
|
1706
1779
|
compilers: {},
|
|
1707
1780
|
plugins,
|
|
@@ -2502,15 +2575,15 @@ class Parser extends Tokenizer {
|
|
|
2502
2575
|
value: void 0
|
|
2503
2576
|
});
|
|
2504
2577
|
}
|
|
2505
|
-
parse(template) {
|
|
2578
|
+
async parse(template) {
|
|
2506
2579
|
this.tokenize(template);
|
|
2507
2580
|
const start = this.tokens[0]?.loc.start ?? { line: 1, column: 1 };
|
|
2508
2581
|
const end = this.tokens.at(-1)?.loc.end ?? { line: 1, column: 1 };
|
|
2509
2582
|
this.expParser = new ExpParser(template);
|
|
2510
2583
|
this.cursor = 0;
|
|
2511
|
-
return new RootNode(this.parseUntil(), { start, end });
|
|
2584
|
+
return new RootNode(await this.parseUntil(), { start, end });
|
|
2512
2585
|
}
|
|
2513
|
-
parseUntil(names) {
|
|
2586
|
+
async parseUntil(names) {
|
|
2514
2587
|
const nodes = [];
|
|
2515
2588
|
let prevToken = null;
|
|
2516
2589
|
while (true) {
|
|
@@ -2527,24 +2600,33 @@ class Parser extends Tokenizer {
|
|
|
2527
2600
|
if (token.strip?.before && prevToken?.type === TokenType.TEXT) {
|
|
2528
2601
|
prevToken.strip.end = true;
|
|
2529
2602
|
}
|
|
2530
|
-
|
|
2531
|
-
token.type?.toLowerCase()]
|
|
2603
|
+
let parser = this.options.parsers[token.name?.toLowerCase() ??
|
|
2604
|
+
token.type?.toLowerCase()];
|
|
2605
|
+
if (parser === 'unexpected') {
|
|
2606
|
+
parser = this.options.parsers['unexpected'];
|
|
2607
|
+
}
|
|
2608
|
+
if (!parser) {
|
|
2609
|
+
parser = this.options.parsers['unknown'];
|
|
2610
|
+
}
|
|
2611
|
+
const ag = parser?.(token, this);
|
|
2612
|
+
if (ag) {
|
|
2613
|
+
while (true) {
|
|
2614
|
+
const { value, done } = await ag.next();
|
|
2615
|
+
if (done) {
|
|
2616
|
+
break;
|
|
2617
|
+
}
|
|
2618
|
+
if (value === 'NEXT') {
|
|
2619
|
+
this.advance();
|
|
2620
|
+
}
|
|
2621
|
+
else if (value) {
|
|
2622
|
+
nodes.push(value);
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2532
2626
|
prevToken = token;
|
|
2533
2627
|
}
|
|
2534
2628
|
return nodes;
|
|
2535
2629
|
}
|
|
2536
|
-
createUnexpectedNode(token) {
|
|
2537
|
-
const name = token.name ?? token.type;
|
|
2538
|
-
this.options.debug?.(new CompileError(`Unexpected "${name}" directive`, this.template, token.loc));
|
|
2539
|
-
this.advance();
|
|
2540
|
-
return new UnexpectedNode(name, token.val, token.loc, token.strip);
|
|
2541
|
-
}
|
|
2542
|
-
createUnknownNode(token) {
|
|
2543
|
-
const name = token.name ?? token.type;
|
|
2544
|
-
this.options.debug?.(new CompileError(`Unknown "${name}" node`, this.template, token.loc));
|
|
2545
|
-
this.advance();
|
|
2546
|
-
return new UnknownNode(name, token.val, token.loc, token.strip);
|
|
2547
|
-
}
|
|
2548
2630
|
parseExp({ val, loc }) {
|
|
2549
2631
|
return this.expParser.parse(val, loc);
|
|
2550
2632
|
}
|
|
@@ -2616,7 +2698,7 @@ class Compiler extends Context {
|
|
|
2616
2698
|
this.isRoot = root;
|
|
2617
2699
|
this.partials = partials;
|
|
2618
2700
|
this.blocks = blocks;
|
|
2619
|
-
this.rootNode = new Parser(this.options).parse(template);
|
|
2701
|
+
this.rootNode = await new Parser(this.options).parse(template);
|
|
2620
2702
|
this.state = {};
|
|
2621
2703
|
this.start();
|
|
2622
2704
|
await this.parseTemplates();
|
|
@@ -2698,11 +2780,8 @@ class Compiler extends Context {
|
|
|
2698
2780
|
await this.compileNodes(node.body);
|
|
2699
2781
|
return;
|
|
2700
2782
|
}
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
return;
|
|
2704
|
-
}
|
|
2705
|
-
this.options.debug?.(new CompileError(`Unknown "${node.name}" node`, this.template, node.loc));
|
|
2783
|
+
const compiler = this.options.compilers[node.type] || this.options.compilers['UNKNOWN'];
|
|
2784
|
+
await compiler?.(node, this);
|
|
2706
2785
|
}
|
|
2707
2786
|
async compileNodes(nodes) {
|
|
2708
2787
|
for (const child of nodes) {
|
|
@@ -2758,12 +2837,12 @@ class Renderer {
|
|
|
2758
2837
|
const compiler = new Compiler(this.options);
|
|
2759
2838
|
try {
|
|
2760
2839
|
await compiler.compile(template);
|
|
2761
|
-
return await compiler.script({ ...this.options.globals
|
|
2840
|
+
return await compiler.script({ ...globals, ...this.options.globals }, (v) => {
|
|
2762
2841
|
if (v instanceof Safe) {
|
|
2763
2842
|
return `${v}`;
|
|
2764
2843
|
}
|
|
2765
2844
|
return this.options.autoEscape ? escape(v) : v;
|
|
2766
|
-
}, { ...this.options.filters
|
|
2845
|
+
}, { ...filters, ...this.options.filters });
|
|
2767
2846
|
}
|
|
2768
2847
|
catch (error) {
|
|
2769
2848
|
this.options.debug((() => {
|