janja 2.1.1 → 2.1.2
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 +308 -226
- package/dist/index.d.ts +12 -21
- package/dist/index.esm.js +308 -226
- package/dist/index.js +308 -226
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -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 = {
|
|
@@ -790,7 +718,7 @@ ${output
|
|
|
790
718
|
await compiler.compileNodes(body);
|
|
791
719
|
compiler.pushRaw(null, '});');
|
|
792
720
|
}
|
|
793
|
-
const compilers$
|
|
721
|
+
const compilers$b = {
|
|
794
722
|
CALL: compileCall,
|
|
795
723
|
};
|
|
796
724
|
|
|
@@ -830,29 +758,29 @@ ${output
|
|
|
830
758
|
}
|
|
831
759
|
}
|
|
832
760
|
|
|
833
|
-
function parseCall(token, parser) {
|
|
761
|
+
async function* parseCall(token, parser) {
|
|
834
762
|
if (!token.expression) {
|
|
835
763
|
parser.emitExpErr(token);
|
|
836
764
|
return;
|
|
837
765
|
}
|
|
838
|
-
|
|
839
|
-
const body = parser.parseUntil(['endcall']);
|
|
766
|
+
yield 'NEXT';
|
|
767
|
+
const body = await parser.parseUntil(['endcall']);
|
|
840
768
|
if (parser.match(['endcall'])) {
|
|
841
|
-
|
|
769
|
+
yield 'NEXT';
|
|
842
770
|
}
|
|
843
771
|
else {
|
|
844
772
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
845
773
|
}
|
|
846
|
-
|
|
774
|
+
yield new CallNode(parser.parseExp(token.expression), body, token.loc, token.strip);
|
|
847
775
|
}
|
|
848
|
-
const parsers$
|
|
776
|
+
const parsers$b = {
|
|
849
777
|
call: parseCall,
|
|
850
|
-
endcall:
|
|
778
|
+
endcall: 'unexpected',
|
|
851
779
|
};
|
|
852
780
|
|
|
853
|
-
const plugin$
|
|
854
|
-
compilers: compilers$
|
|
855
|
-
parsers: parsers$
|
|
781
|
+
const plugin$b = {
|
|
782
|
+
compilers: compilers$b,
|
|
783
|
+
parsers: parsers$b,
|
|
856
784
|
};
|
|
857
785
|
|
|
858
786
|
async function compileCapture({ val, body, loc }, compiler) {
|
|
@@ -860,7 +788,7 @@ ${output
|
|
|
860
788
|
await compiler.compileNodes(body);
|
|
861
789
|
compiler.pushRaw(null, 'return s;})("");');
|
|
862
790
|
}
|
|
863
|
-
const compilers$
|
|
791
|
+
const compilers$a = {
|
|
864
792
|
CAPTURE: compileCapture,
|
|
865
793
|
};
|
|
866
794
|
|
|
@@ -900,29 +828,29 @@ ${output
|
|
|
900
828
|
}
|
|
901
829
|
}
|
|
902
830
|
|
|
903
|
-
function parseCapture(token, parser) {
|
|
831
|
+
async function* parseCapture(token, parser) {
|
|
904
832
|
if (!token.expression) {
|
|
905
833
|
parser.emitExpErr(token);
|
|
906
834
|
return;
|
|
907
835
|
}
|
|
908
|
-
|
|
909
|
-
const body = parser.parseUntil(['endcapture']);
|
|
836
|
+
yield 'NEXT';
|
|
837
|
+
const body = await parser.parseUntil(['endcapture']);
|
|
910
838
|
if (parser.match(['endcapture'])) {
|
|
911
|
-
|
|
839
|
+
yield 'NEXT';
|
|
912
840
|
}
|
|
913
841
|
else {
|
|
914
842
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
915
843
|
}
|
|
916
|
-
|
|
844
|
+
yield new CaptureNode(parser.parseExp(token.expression), body, token.loc, token.strip);
|
|
917
845
|
}
|
|
918
|
-
const parsers$
|
|
846
|
+
const parsers$a = {
|
|
919
847
|
capture: parseCapture,
|
|
920
|
-
endcapture:
|
|
848
|
+
endcapture: 'unexpected',
|
|
921
849
|
};
|
|
922
850
|
|
|
923
|
-
const plugin$
|
|
924
|
-
compilers: compilers$
|
|
925
|
-
parsers: parsers$
|
|
851
|
+
const plugin$a = {
|
|
852
|
+
compilers: compilers$a,
|
|
853
|
+
parsers: parsers$a,
|
|
926
854
|
};
|
|
927
855
|
|
|
928
856
|
async function compileComment({ val, loc }, compiler) {
|
|
@@ -930,7 +858,7 @@ ${output
|
|
|
930
858
|
compiler.pushStr(loc, `<!--${val}-->`);
|
|
931
859
|
}
|
|
932
860
|
}
|
|
933
|
-
const compilers$
|
|
861
|
+
const compilers$9 = {
|
|
934
862
|
COMMENT: compileComment,
|
|
935
863
|
};
|
|
936
864
|
|
|
@@ -964,17 +892,17 @@ ${output
|
|
|
964
892
|
}
|
|
965
893
|
}
|
|
966
894
|
|
|
967
|
-
function parseComment({ val, loc, strip }
|
|
968
|
-
|
|
969
|
-
|
|
895
|
+
async function* parseComment({ val, loc, strip }) {
|
|
896
|
+
yield 'NEXT';
|
|
897
|
+
yield new CommentNode(val, loc, strip);
|
|
970
898
|
}
|
|
971
|
-
const parsers$
|
|
899
|
+
const parsers$9 = {
|
|
972
900
|
comment: parseComment,
|
|
973
901
|
};
|
|
974
902
|
|
|
975
|
-
const plugin$
|
|
976
|
-
compilers: compilers$
|
|
977
|
-
parsers: parsers$
|
|
903
|
+
const plugin$9 = {
|
|
904
|
+
compilers: compilers$9,
|
|
905
|
+
parsers: parsers$9,
|
|
978
906
|
};
|
|
979
907
|
|
|
980
908
|
async function compileFor({ loop, body }, compiler) {
|
|
@@ -995,7 +923,7 @@ ${output
|
|
|
995
923
|
function compileContinue({ loc }, compiler) {
|
|
996
924
|
compiler.pushRaw(loc, 'continue;');
|
|
997
925
|
}
|
|
998
|
-
const compilers$
|
|
926
|
+
const compilers$8 = {
|
|
999
927
|
FOR: compileFor,
|
|
1000
928
|
BREAK: compileBreak,
|
|
1001
929
|
CONTINUE: compileContinue,
|
|
@@ -1096,24 +1024,24 @@ ${output
|
|
|
1096
1024
|
}
|
|
1097
1025
|
|
|
1098
1026
|
const wm$1 = new WeakMap();
|
|
1099
|
-
function parseFor(token, parser) {
|
|
1027
|
+
async function* parseFor(token, parser) {
|
|
1100
1028
|
if (!token.expression) {
|
|
1101
1029
|
parser.emitExpErr(token);
|
|
1102
1030
|
return;
|
|
1103
1031
|
}
|
|
1104
1032
|
wm$1.set(parser, true);
|
|
1105
|
-
|
|
1106
|
-
const body = parser.parseUntil(['endfor']);
|
|
1033
|
+
yield 'NEXT';
|
|
1034
|
+
const body = await parser.parseUntil(['endfor']);
|
|
1107
1035
|
wm$1.set(parser, false);
|
|
1108
1036
|
if (parser.match(['endfor'])) {
|
|
1109
|
-
|
|
1037
|
+
yield 'NEXT';
|
|
1110
1038
|
}
|
|
1111
1039
|
else {
|
|
1112
1040
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
1113
1041
|
}
|
|
1114
|
-
|
|
1042
|
+
yield new ForNode(parser.parseExp(token.expression), body, token.loc, token.strip);
|
|
1115
1043
|
}
|
|
1116
|
-
function parseBreak(token, parser) {
|
|
1044
|
+
async function* parseBreak(token, parser) {
|
|
1117
1045
|
if (token.expression) {
|
|
1118
1046
|
parser.emitExpErr(token, false);
|
|
1119
1047
|
return;
|
|
@@ -1122,10 +1050,10 @@ ${output
|
|
|
1122
1050
|
parser.options.debug?.(new CompileError('"break" directive used outside of a loop', parser.template, token.loc));
|
|
1123
1051
|
return;
|
|
1124
1052
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1053
|
+
yield 'NEXT';
|
|
1054
|
+
yield new BreakNode(token.val, token.loc, token.strip);
|
|
1127
1055
|
}
|
|
1128
|
-
function parseContinue(token, parser) {
|
|
1056
|
+
async function* parseContinue(token, parser) {
|
|
1129
1057
|
if (token.expression) {
|
|
1130
1058
|
parser.emitExpErr(token, false);
|
|
1131
1059
|
return;
|
|
@@ -1134,19 +1062,19 @@ ${output
|
|
|
1134
1062
|
parser.options.debug?.(new CompileError('"continue" directive used outside of a loop', parser.template, token.loc));
|
|
1135
1063
|
return;
|
|
1136
1064
|
}
|
|
1137
|
-
|
|
1138
|
-
|
|
1065
|
+
yield 'NEXT';
|
|
1066
|
+
yield new ContinueNode(token.val, token.loc, token.strip);
|
|
1139
1067
|
}
|
|
1140
|
-
const parsers$
|
|
1068
|
+
const parsers$8 = {
|
|
1141
1069
|
for: parseFor,
|
|
1142
1070
|
break: parseBreak,
|
|
1143
1071
|
continue: parseContinue,
|
|
1144
|
-
endfor:
|
|
1072
|
+
endfor: 'unexpected',
|
|
1145
1073
|
};
|
|
1146
1074
|
|
|
1147
|
-
const plugin$
|
|
1148
|
-
compilers: compilers$
|
|
1149
|
-
parsers: parsers$
|
|
1075
|
+
const plugin$8 = {
|
|
1076
|
+
compilers: compilers$8,
|
|
1077
|
+
parsers: parsers$8,
|
|
1150
1078
|
};
|
|
1151
1079
|
|
|
1152
1080
|
async function compileIf({ test, body, alternatives }, compiler) {
|
|
@@ -1164,7 +1092,7 @@ ${output
|
|
|
1164
1092
|
compiler.pushRaw(null, '}');
|
|
1165
1093
|
}
|
|
1166
1094
|
}
|
|
1167
|
-
const compilers$
|
|
1095
|
+
const compilers$7 = {
|
|
1168
1096
|
IF: compileIf,
|
|
1169
1097
|
};
|
|
1170
1098
|
|
|
@@ -1278,70 +1206,96 @@ ${output
|
|
|
1278
1206
|
}
|
|
1279
1207
|
}
|
|
1280
1208
|
|
|
1281
|
-
function parseIf(token, parser) {
|
|
1209
|
+
async function* parseIf(token, parser) {
|
|
1282
1210
|
if (!token.expression) {
|
|
1283
1211
|
parser.emitExpErr(token);
|
|
1284
1212
|
return;
|
|
1285
1213
|
}
|
|
1286
|
-
|
|
1287
|
-
const body = parser.parseUntil([
|
|
1214
|
+
yield 'NEXT';
|
|
1215
|
+
const body = await parser.parseUntil([
|
|
1216
|
+
'else',
|
|
1217
|
+
'elseif',
|
|
1218
|
+
'elsif',
|
|
1219
|
+
'elif',
|
|
1220
|
+
'endif',
|
|
1221
|
+
]);
|
|
1288
1222
|
const alternatives = [];
|
|
1289
1223
|
while (parser.match(['else', 'elseif', 'elsif', 'elif'])) {
|
|
1290
1224
|
const branchToken = parser.peek();
|
|
1291
1225
|
if (branchToken.name.toLowerCase() === 'else') {
|
|
1292
|
-
const
|
|
1293
|
-
|
|
1294
|
-
|
|
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
|
+
}
|
|
1295
1239
|
}
|
|
1296
1240
|
}
|
|
1297
1241
|
else {
|
|
1298
|
-
const
|
|
1299
|
-
|
|
1300
|
-
|
|
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
|
+
}
|
|
1301
1255
|
}
|
|
1302
1256
|
}
|
|
1303
1257
|
}
|
|
1304
1258
|
if (parser.match(['endif'])) {
|
|
1305
|
-
|
|
1259
|
+
yield 'NEXT';
|
|
1306
1260
|
}
|
|
1307
1261
|
else {
|
|
1308
1262
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
1309
1263
|
}
|
|
1310
|
-
|
|
1264
|
+
yield new IfNode(parser.parseExp(token.expression), body, alternatives, token.loc, token.strip);
|
|
1311
1265
|
}
|
|
1312
|
-
function parseElseIf(token, parser) {
|
|
1266
|
+
async function* parseElseIf(token, parser) {
|
|
1313
1267
|
if (!token.expression) {
|
|
1314
1268
|
parser.emitExpErr(token);
|
|
1315
1269
|
return;
|
|
1316
1270
|
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1271
|
+
yield 'NEXT';
|
|
1272
|
+
yield new ElseIfNode(parser.parseExp(token.expression), await parser.parseUntil(['else', 'elseif', 'elsif', 'elif', 'endif']), token.loc, token.strip);
|
|
1319
1273
|
}
|
|
1320
|
-
function parseElse(token, parser) {
|
|
1274
|
+
async function* parseElse(token, parser) {
|
|
1321
1275
|
if (token.expression) {
|
|
1322
1276
|
parser.emitExpErr(token, false);
|
|
1323
1277
|
return;
|
|
1324
1278
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1279
|
+
yield 'NEXT';
|
|
1280
|
+
yield new ElseNode(await parser.parseUntil(['endif']), token.loc, token.strip);
|
|
1327
1281
|
}
|
|
1328
|
-
const parsers$
|
|
1282
|
+
const parsers$7 = {
|
|
1329
1283
|
if: parseIf,
|
|
1330
|
-
elseif:
|
|
1331
|
-
elsif:
|
|
1332
|
-
elif:
|
|
1333
|
-
endif:
|
|
1284
|
+
elseif: 'unexpected',
|
|
1285
|
+
elsif: 'unexpected',
|
|
1286
|
+
elif: 'unexpected',
|
|
1287
|
+
endif: 'unexpected',
|
|
1334
1288
|
};
|
|
1335
1289
|
|
|
1336
|
-
const plugin$
|
|
1337
|
-
compilers: compilers$
|
|
1338
|
-
parsers: parsers$
|
|
1290
|
+
const plugin$7 = {
|
|
1291
|
+
compilers: compilers$7,
|
|
1292
|
+
parsers: parsers$7,
|
|
1339
1293
|
};
|
|
1340
1294
|
|
|
1341
1295
|
async function compileInclude({ val: { value }, loc }, compiler) {
|
|
1342
1296
|
compiler.pushRaw(loc, `s+=await p["${value}"]?.()??"";`);
|
|
1343
1297
|
}
|
|
1344
|
-
const compilers$
|
|
1298
|
+
const compilers$6 = {
|
|
1345
1299
|
INCLUDE: compileInclude,
|
|
1346
1300
|
};
|
|
1347
1301
|
|
|
@@ -1375,21 +1329,21 @@ ${output
|
|
|
1375
1329
|
}
|
|
1376
1330
|
}
|
|
1377
1331
|
|
|
1378
|
-
function parseInclude(token, parser) {
|
|
1332
|
+
async function* parseInclude(token, parser) {
|
|
1379
1333
|
if (!token.expression) {
|
|
1380
1334
|
parser.emitExpErr(token);
|
|
1381
1335
|
return;
|
|
1382
1336
|
}
|
|
1383
|
-
|
|
1384
|
-
|
|
1337
|
+
yield 'NEXT';
|
|
1338
|
+
yield new IncludeNode(parser.parseExp(token.expression), token.loc, token.strip);
|
|
1385
1339
|
}
|
|
1386
|
-
const parsers$
|
|
1340
|
+
const parsers$6 = {
|
|
1387
1341
|
include: parseInclude,
|
|
1388
1342
|
};
|
|
1389
1343
|
|
|
1390
|
-
const plugin$
|
|
1391
|
-
compilers: compilers$
|
|
1392
|
-
parsers: parsers$
|
|
1344
|
+
const plugin$6 = {
|
|
1345
|
+
compilers: compilers$6,
|
|
1346
|
+
parsers: parsers$6,
|
|
1393
1347
|
};
|
|
1394
1348
|
|
|
1395
1349
|
async function compileMacro({ val: { left, right }, loc, body }, compiler) {
|
|
@@ -1410,7 +1364,7 @@ ${output
|
|
|
1410
1364
|
function compileCaller({ loc }, compiler) {
|
|
1411
1365
|
compiler.pushRaw(loc, 'await _c?.();');
|
|
1412
1366
|
}
|
|
1413
|
-
const compilers$
|
|
1367
|
+
const compilers$5 = {
|
|
1414
1368
|
MACRO: compileMacro,
|
|
1415
1369
|
CALLER: compileCaller,
|
|
1416
1370
|
};
|
|
@@ -1481,24 +1435,24 @@ ${output
|
|
|
1481
1435
|
}
|
|
1482
1436
|
|
|
1483
1437
|
const wm = new WeakMap();
|
|
1484
|
-
function parseMacro(token, parser) {
|
|
1438
|
+
async function* parseMacro(token, parser) {
|
|
1485
1439
|
if (!token.expression) {
|
|
1486
1440
|
parser.emitExpErr(token);
|
|
1487
1441
|
return;
|
|
1488
1442
|
}
|
|
1489
1443
|
wm.set(parser, true);
|
|
1490
|
-
|
|
1491
|
-
const body = parser.parseUntil(['endmacro']);
|
|
1444
|
+
yield 'NEXT';
|
|
1445
|
+
const body = await parser.parseUntil(['endmacro']);
|
|
1492
1446
|
wm.set(parser, false);
|
|
1493
1447
|
if (parser.match(['endmacro'])) {
|
|
1494
|
-
|
|
1448
|
+
yield 'NEXT';
|
|
1495
1449
|
}
|
|
1496
1450
|
else {
|
|
1497
1451
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
1498
1452
|
}
|
|
1499
|
-
|
|
1453
|
+
yield new MacroNode(parser.parseExp(token.expression), body, token.loc, token.strip);
|
|
1500
1454
|
}
|
|
1501
|
-
function parseCaller(token, parser) {
|
|
1455
|
+
async function* parseCaller(token, parser) {
|
|
1502
1456
|
if (token.expression) {
|
|
1503
1457
|
parser.emitExpErr(token, false);
|
|
1504
1458
|
return;
|
|
@@ -1507,24 +1461,24 @@ ${output
|
|
|
1507
1461
|
parser.options.debug?.(new CompileError('"caller" directive used outside of a macro', parser.template, token.loc));
|
|
1508
1462
|
return;
|
|
1509
1463
|
}
|
|
1510
|
-
|
|
1511
|
-
|
|
1464
|
+
yield 'NEXT';
|
|
1465
|
+
yield new CallerNode(token.val, token.loc, token.strip);
|
|
1512
1466
|
}
|
|
1513
|
-
const parsers$
|
|
1467
|
+
const parsers$5 = {
|
|
1514
1468
|
macro: parseMacro,
|
|
1515
1469
|
caller: parseCaller,
|
|
1516
|
-
endmacro:
|
|
1470
|
+
endmacro: 'unexpected',
|
|
1517
1471
|
};
|
|
1518
1472
|
|
|
1519
|
-
const plugin$
|
|
1520
|
-
compilers: compilers$
|
|
1521
|
-
parsers: parsers$
|
|
1473
|
+
const plugin$5 = {
|
|
1474
|
+
compilers: compilers$5,
|
|
1475
|
+
parsers: parsers$5,
|
|
1522
1476
|
};
|
|
1523
1477
|
|
|
1524
1478
|
async function compileOutput({ exp }, compiler) {
|
|
1525
1479
|
compiler.pushVar(exp.loc, new ExpCompiler().compile(exp, compiler.context));
|
|
1526
1480
|
}
|
|
1527
|
-
const compilers$
|
|
1481
|
+
const compilers$4 = {
|
|
1528
1482
|
OUTPUT: compileOutput,
|
|
1529
1483
|
};
|
|
1530
1484
|
|
|
@@ -1564,23 +1518,23 @@ ${output
|
|
|
1564
1518
|
}
|
|
1565
1519
|
}
|
|
1566
1520
|
|
|
1567
|
-
function parseOutput(token, parser) {
|
|
1568
|
-
|
|
1569
|
-
|
|
1521
|
+
async function* parseOutput(token, parser) {
|
|
1522
|
+
yield 'NEXT';
|
|
1523
|
+
yield new OutputNode(token.val, token.loc, token.strip, parser.parseExp(token));
|
|
1570
1524
|
}
|
|
1571
|
-
const parsers$
|
|
1525
|
+
const parsers$4 = {
|
|
1572
1526
|
output: parseOutput,
|
|
1573
1527
|
};
|
|
1574
1528
|
|
|
1575
|
-
const plugin$
|
|
1576
|
-
compilers: compilers$
|
|
1577
|
-
parsers: parsers$
|
|
1529
|
+
const plugin$4 = {
|
|
1530
|
+
compilers: compilers$4,
|
|
1531
|
+
parsers: parsers$4,
|
|
1578
1532
|
};
|
|
1579
1533
|
|
|
1580
1534
|
async function compileSet({ val, loc }, compiler) {
|
|
1581
1535
|
compiler.pushRaw(loc, new ExpCompiler().compile(val, compiler.context));
|
|
1582
1536
|
}
|
|
1583
|
-
const compilers$
|
|
1537
|
+
const compilers$3 = {
|
|
1584
1538
|
SET: compileSet,
|
|
1585
1539
|
};
|
|
1586
1540
|
|
|
@@ -1614,21 +1568,21 @@ ${output
|
|
|
1614
1568
|
}
|
|
1615
1569
|
}
|
|
1616
1570
|
|
|
1617
|
-
function parseSet(token, parser) {
|
|
1571
|
+
async function* parseSet(token, parser) {
|
|
1618
1572
|
if (!token.expression) {
|
|
1619
1573
|
parser.emitExpErr(token);
|
|
1620
1574
|
return;
|
|
1621
1575
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1576
|
+
yield 'NEXT';
|
|
1577
|
+
yield new SetNode(parser.parseExp(token.expression), token.loc, token.strip);
|
|
1624
1578
|
}
|
|
1625
|
-
const parsers$
|
|
1579
|
+
const parsers$3 = {
|
|
1626
1580
|
set: parseSet,
|
|
1627
1581
|
};
|
|
1628
1582
|
|
|
1629
|
-
const plugin$
|
|
1630
|
-
compilers: compilers$
|
|
1631
|
-
parsers: parsers$
|
|
1583
|
+
const plugin$3 = {
|
|
1584
|
+
compilers: compilers$3,
|
|
1585
|
+
parsers: parsers$3,
|
|
1632
1586
|
};
|
|
1633
1587
|
|
|
1634
1588
|
async function compileText({ val, loc, strip: { start, end } }, compiler) {
|
|
@@ -1640,7 +1594,7 @@ ${output
|
|
|
1640
1594
|
}
|
|
1641
1595
|
compiler.pushStr(loc, val);
|
|
1642
1596
|
}
|
|
1643
|
-
const compilers = {
|
|
1597
|
+
const compilers$2 = {
|
|
1644
1598
|
TEXT: compileText,
|
|
1645
1599
|
};
|
|
1646
1600
|
|
|
@@ -1674,31 +1628,149 @@ ${output
|
|
|
1674
1628
|
}
|
|
1675
1629
|
}
|
|
1676
1630
|
|
|
1677
|
-
function parseText(token
|
|
1678
|
-
|
|
1679
|
-
|
|
1631
|
+
async function* parseText(token) {
|
|
1632
|
+
yield 'NEXT';
|
|
1633
|
+
yield new TextNode(token.val, token.loc, token.strip);
|
|
1680
1634
|
}
|
|
1681
|
-
const parsers = {
|
|
1635
|
+
const parsers$2 = {
|
|
1682
1636
|
text: parseText,
|
|
1683
1637
|
};
|
|
1684
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
|
+
|
|
1685
1755
|
const plugin = {
|
|
1686
1756
|
compilers,
|
|
1687
1757
|
parsers,
|
|
1688
1758
|
};
|
|
1689
1759
|
|
|
1690
1760
|
const plugins = [
|
|
1691
|
-
plugin$
|
|
1761
|
+
plugin$c,
|
|
1762
|
+
plugin$b,
|
|
1692
1763
|
plugin$9,
|
|
1693
|
-
plugin$
|
|
1764
|
+
plugin$a,
|
|
1694
1765
|
plugin$8,
|
|
1766
|
+
plugin$7,
|
|
1695
1767
|
plugin$6,
|
|
1696
1768
|
plugin$5,
|
|
1697
|
-
plugin$4,
|
|
1698
1769
|
plugin$3,
|
|
1770
|
+
plugin$2,
|
|
1771
|
+
plugin$4,
|
|
1699
1772
|
plugin$1,
|
|
1700
1773
|
plugin,
|
|
1701
|
-
plugin$2,
|
|
1702
1774
|
];
|
|
1703
1775
|
|
|
1704
1776
|
const baseOptions = {
|
|
@@ -2503,15 +2575,15 @@ ${output
|
|
|
2503
2575
|
value: void 0
|
|
2504
2576
|
});
|
|
2505
2577
|
}
|
|
2506
|
-
parse(template) {
|
|
2578
|
+
async parse(template) {
|
|
2507
2579
|
this.tokenize(template);
|
|
2508
2580
|
const start = this.tokens[0]?.loc.start ?? { line: 1, column: 1 };
|
|
2509
2581
|
const end = this.tokens.at(-1)?.loc.end ?? { line: 1, column: 1 };
|
|
2510
2582
|
this.expParser = new ExpParser(template);
|
|
2511
2583
|
this.cursor = 0;
|
|
2512
|
-
return new RootNode(this.parseUntil(), { start, end });
|
|
2584
|
+
return new RootNode(await this.parseUntil(), { start, end });
|
|
2513
2585
|
}
|
|
2514
|
-
parseUntil(names) {
|
|
2586
|
+
async parseUntil(names) {
|
|
2515
2587
|
const nodes = [];
|
|
2516
2588
|
let prevToken = null;
|
|
2517
2589
|
while (true) {
|
|
@@ -2528,24 +2600,33 @@ ${output
|
|
|
2528
2600
|
if (token.strip?.before && prevToken?.type === TokenType.TEXT) {
|
|
2529
2601
|
prevToken.strip.end = true;
|
|
2530
2602
|
}
|
|
2531
|
-
|
|
2532
|
-
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
|
+
}
|
|
2533
2626
|
prevToken = token;
|
|
2534
2627
|
}
|
|
2535
2628
|
return nodes;
|
|
2536
2629
|
}
|
|
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
2630
|
parseExp({ val, loc }) {
|
|
2550
2631
|
return this.expParser.parse(val, loc);
|
|
2551
2632
|
}
|
|
@@ -2617,7 +2698,7 @@ ${output
|
|
|
2617
2698
|
this.isRoot = root;
|
|
2618
2699
|
this.partials = partials;
|
|
2619
2700
|
this.blocks = blocks;
|
|
2620
|
-
this.rootNode = new Parser(this.options).parse(template);
|
|
2701
|
+
this.rootNode = await new Parser(this.options).parse(template);
|
|
2621
2702
|
this.state = {};
|
|
2622
2703
|
this.start();
|
|
2623
2704
|
await this.parseTemplates();
|
|
@@ -2699,8 +2780,9 @@ ${output
|
|
|
2699
2780
|
await this.compileNodes(node.body);
|
|
2700
2781
|
return;
|
|
2701
2782
|
}
|
|
2702
|
-
|
|
2703
|
-
|
|
2783
|
+
const compiler = this.options.compilers[node.type];
|
|
2784
|
+
if (compiler) {
|
|
2785
|
+
await compiler(node, this);
|
|
2704
2786
|
return;
|
|
2705
2787
|
}
|
|
2706
2788
|
this.options.debug?.(new CompileError(`Unknown "${node.name}" node`, this.template, node.loc));
|