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