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