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