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