htmljs-parser 3.1.0 → 3.2.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.mjs CHANGED
@@ -5,13 +5,42 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/util/constants.ts
8
- var OpenTagEnding = /* @__PURE__ */ ((OpenTagEnding2) => {
9
- OpenTagEnding2[OpenTagEnding2["tag"] = 0] = "tag";
10
- OpenTagEnding2[OpenTagEnding2["self"] = 1] = "self";
11
- OpenTagEnding2[OpenTagEnding2["void"] = 2] = "void";
12
- OpenTagEnding2[OpenTagEnding2["code"] = 4] = "code";
13
- return OpenTagEnding2;
14
- })(OpenTagEnding || {});
8
+ var ErrorCode = /* @__PURE__ */ ((ErrorCode3) => {
9
+ ErrorCode3[ErrorCode3["EXTRA_CLOSING_TAG"] = 0] = "EXTRA_CLOSING_TAG";
10
+ ErrorCode3[ErrorCode3["INVALID_ATTRIBUTE_ARGUMENT"] = 1] = "INVALID_ATTRIBUTE_ARGUMENT";
11
+ ErrorCode3[ErrorCode3["INVALID_ATTRIBUTE_NAME"] = 2] = "INVALID_ATTRIBUTE_NAME";
12
+ ErrorCode3[ErrorCode3["INVALID_ATTRIBUTE_VALUE"] = 3] = "INVALID_ATTRIBUTE_VALUE";
13
+ ErrorCode3[ErrorCode3["INVALID_CHARACTER"] = 4] = "INVALID_CHARACTER";
14
+ ErrorCode3[ErrorCode3["INVALID_CODE_AFTER_SEMICOLON"] = 5] = "INVALID_CODE_AFTER_SEMICOLON";
15
+ ErrorCode3[ErrorCode3["INVALID_EXPRESSION"] = 6] = "INVALID_EXPRESSION";
16
+ ErrorCode3[ErrorCode3["INVALID_INDENTATION"] = 7] = "INVALID_INDENTATION";
17
+ ErrorCode3[ErrorCode3["INVALID_LINE_START"] = 8] = "INVALID_LINE_START";
18
+ ErrorCode3[ErrorCode3["INVALID_REGULAR_EXPRESSION"] = 9] = "INVALID_REGULAR_EXPRESSION";
19
+ ErrorCode3[ErrorCode3["INVALID_STRING"] = 10] = "INVALID_STRING";
20
+ ErrorCode3[ErrorCode3["INVALID_TAG_ARGUMENT"] = 11] = "INVALID_TAG_ARGUMENT";
21
+ ErrorCode3[ErrorCode3["INVALID_TAG_SHORTHAND"] = 12] = "INVALID_TAG_SHORTHAND";
22
+ ErrorCode3[ErrorCode3["INVALID_TEMPLATE_STRING"] = 13] = "INVALID_TEMPLATE_STRING";
23
+ ErrorCode3[ErrorCode3["MALFORMED_CDATA"] = 14] = "MALFORMED_CDATA";
24
+ ErrorCode3[ErrorCode3["MALFORMED_CLOSE_TAG"] = 15] = "MALFORMED_CLOSE_TAG";
25
+ ErrorCode3[ErrorCode3["MALFORMED_COMMENT"] = 16] = "MALFORMED_COMMENT";
26
+ ErrorCode3[ErrorCode3["MALFORMED_DECLARATION"] = 17] = "MALFORMED_DECLARATION";
27
+ ErrorCode3[ErrorCode3["MALFORMED_DOCUMENT_TYPE"] = 18] = "MALFORMED_DOCUMENT_TYPE";
28
+ ErrorCode3[ErrorCode3["MALFORMED_OPEN_TAG"] = 19] = "MALFORMED_OPEN_TAG";
29
+ ErrorCode3[ErrorCode3["MALFORMED_PLACEHOLDER"] = 20] = "MALFORMED_PLACEHOLDER";
30
+ ErrorCode3[ErrorCode3["MISMATCHED_CLOSING_TAG"] = 21] = "MISMATCHED_CLOSING_TAG";
31
+ ErrorCode3[ErrorCode3["MISSING_END_TAG"] = 22] = "MISSING_END_TAG";
32
+ ErrorCode3[ErrorCode3["MISSING_TAG_VARIABLE"] = 23] = "MISSING_TAG_VARIABLE";
33
+ ErrorCode3[ErrorCode3["RESERVED_TAG_NAME"] = 24] = "RESERVED_TAG_NAME";
34
+ ErrorCode3[ErrorCode3["ROOT_TAG_ONLY"] = 25] = "ROOT_TAG_ONLY";
35
+ return ErrorCode3;
36
+ })(ErrorCode || {});
37
+ var TagType = /* @__PURE__ */ ((TagType2) => {
38
+ TagType2[TagType2["html"] = 0] = "html";
39
+ TagType2[TagType2["text"] = 1] = "text";
40
+ TagType2[TagType2["void"] = 2] = "void";
41
+ TagType2[TagType2["statement"] = 3] = "statement";
42
+ return TagType2;
43
+ })(TagType || {});
15
44
 
16
45
  // src/util/util.ts
17
46
  function isWhitespaceCode(code) {
@@ -53,16 +82,16 @@ function htmlEOF() {
53
82
  if (this.activeTag.concise) {
54
83
  this.closeTag(this.pos, this.pos, void 0);
55
84
  } else {
56
- return this.emitError(this.activeTag, "MISSING_END_TAG", 'Missing ending "' + this.read(this.activeTag.tagName) + '" tag');
85
+ return this.emitError(this.activeTag, 22 /* MISSING_END_TAG */, 'Missing ending "' + this.read(this.activeTag.tagName) + '" tag');
57
86
  }
58
87
  }
59
88
  }
60
89
 
61
90
  // src/core/Parser.ts
62
91
  var Parser = class {
63
- constructor(handlers) {
64
- this.handlers = handlers;
65
- this.handlers = handlers;
92
+ constructor(options) {
93
+ this.options = options;
94
+ this.options = options;
66
95
  }
67
96
  pos;
68
97
  maxPos;
@@ -153,13 +182,13 @@ var Parser = class {
153
182
  var _a, _b;
154
183
  const start = this.textPos;
155
184
  if (start !== -1) {
156
- (_b = (_a = this.handlers).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
185
+ (_b = (_a = this.options).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
157
186
  this.textPos = -1;
158
187
  }
159
188
  }
160
189
  beginHtmlBlock(delimiter, singleLine) {
161
190
  var _a;
162
- const content = this.enterState(((_a = this.activeTag) == null ? void 0 : _a.bodyMode) === 1 /* PARSED_TEXT */ ? states_exports.PARSED_TEXT_CONTENT : states_exports.HTML_CONTENT);
191
+ const content = this.enterState(((_a = this.activeTag) == null ? void 0 : _a.type) === 1 /* text */ ? states_exports.PARSED_TEXT_CONTENT : states_exports.HTML_CONTENT);
163
192
  content.singleLine = singleLine;
164
193
  content.delimiter = delimiter;
165
194
  content.indent = this.indent;
@@ -173,7 +202,7 @@ var Parser = class {
173
202
  start = range.start;
174
203
  end = range.end;
175
204
  }
176
- (_b = (_a = this.handlers).onError) == null ? void 0 : _b.call(_a, {
205
+ (_b = (_a = this.options).onError) == null ? void 0 : _b.call(_a, {
177
206
  start,
178
207
  end,
179
208
  code,
@@ -187,7 +216,7 @@ var Parser = class {
187
216
  if (beginMixedMode)
188
217
  this.endingMixedModeAtEOL = true;
189
218
  this.activeTag = parentTag;
190
- (_b = (_a = this.handlers).onCloseTag) == null ? void 0 : _b.call(_a, {
219
+ (_b = (_a = this.options).onCloseTag) == null ? void 0 : _b.call(_a, {
191
220
  start,
192
221
  end,
193
222
  value
@@ -423,7 +452,7 @@ var ATTRIBUTE = {
423
452
  if (this.isConcise) {
424
453
  this.exitState();
425
454
  } else {
426
- this.emitError(attr, "MALFORMED_OPEN_TAG", 'EOF reached while parsing attribute "' + (attr.name ? this.read(attr.name) : "default") + '" for the "' + this.read(this.activeTag.tagName) + '" tag');
455
+ this.emitError(attr, 19 /* MALFORMED_OPEN_TAG */, 'EOF reached while parsing attribute "' + (attr.name ? this.read(attr.name) : "default") + '" for the "' + this.read(this.activeTag.tagName) + '" tag');
427
456
  }
428
457
  },
429
458
  return(child, attr) {
@@ -434,12 +463,12 @@ var ATTRIBUTE = {
434
463
  start: child.start,
435
464
  end: child.end
436
465
  };
437
- (_b = (_a = this.handlers).onAttrName) == null ? void 0 : _b.call(_a, attr.name);
466
+ (_b = (_a = this.options).onAttrName) == null ? void 0 : _b.call(_a, attr.name);
438
467
  break;
439
468
  }
440
469
  case 3 /* ARGUMENT */: {
441
470
  if (attr.args) {
442
- this.emitError(child, "ILLEGAL_ATTRIBUTE_ARGUMENT", "An attribute can only have one set of arguments");
471
+ this.emitError(child, 1 /* INVALID_ATTRIBUTE_ARGUMENT */, "An attribute can only have one set of arguments");
443
472
  return;
444
473
  }
445
474
  const start = child.start - 1;
@@ -456,7 +485,7 @@ var ATTRIBUTE = {
456
485
  };
457
486
  } else {
458
487
  attr.args = true;
459
- (_d = (_c = this.handlers).onAttrArgs) == null ? void 0 : _d.call(_c, {
488
+ (_d = (_c = this.options).onAttrArgs) == null ? void 0 : _d.call(_c, {
460
489
  start,
461
490
  end,
462
491
  value
@@ -468,7 +497,7 @@ var ATTRIBUTE = {
468
497
  const params = attr.args;
469
498
  const start = params.start;
470
499
  const end = ++this.pos;
471
- (_f = (_e = this.handlers).onAttrMethod) == null ? void 0 : _f.call(_e, {
500
+ (_f = (_e = this.options).onAttrMethod) == null ? void 0 : _f.call(_e, {
472
501
  start,
473
502
  end,
474
503
  params,
@@ -486,10 +515,10 @@ var ATTRIBUTE = {
486
515
  }
487
516
  case 2 /* VALUE */: {
488
517
  if (child.start === child.end) {
489
- return this.emitError(child, "ILLEGAL_ATTRIBUTE_VALUE", "Missing value for attribute");
518
+ return this.emitError(child, 3 /* INVALID_ATTRIBUTE_VALUE */, "Missing value for attribute");
490
519
  }
491
520
  if (attr.spread) {
492
- (_h = (_g = this.handlers).onAttrSpread) == null ? void 0 : _h.call(_g, {
521
+ (_h = (_g = this.options).onAttrSpread) == null ? void 0 : _h.call(_g, {
493
522
  start: attr.valueStart,
494
523
  end: child.end,
495
524
  value: {
@@ -498,7 +527,7 @@ var ATTRIBUTE = {
498
527
  }
499
528
  });
500
529
  } else {
501
- (_j = (_i = this.handlers).onAttrValue) == null ? void 0 : _j.call(_i, {
530
+ (_j = (_i = this.options).onAttrValue) == null ? void 0 : _j.call(_i, {
502
531
  start: attr.valueStart,
503
532
  end: child.end,
504
533
  bound: attr.bound,
@@ -517,7 +546,7 @@ var ATTRIBUTE = {
517
546
  function ensureAttrName(parser, attr) {
518
547
  var _a, _b;
519
548
  if (!attr.name) {
520
- (_b = (_a = parser.handlers).onAttrName) == null ? void 0 : _b.call(_a, {
549
+ (_b = (_a = parser.options).onAttrName) == null ? void 0 : _b.call(_a, {
521
550
  start: attr.start,
522
551
  end: attr.start
523
552
  });
@@ -587,7 +616,7 @@ function handleDelimitedBlockEOL(parser, newLineLength, {
587
616
  parser.exitState();
588
617
  parser.exitState();
589
618
  } else {
590
- parser.emitError(parser.pos, "INVALID_CHARACTER", "A concise mode closing block delimiter can only be followed by whitespace.");
619
+ parser.emitError(parser.pos, 4 /* INVALID_CHARACTER */, "A concise mode closing block delimiter can only be followed by whitespace.");
591
620
  }
592
621
  } else if (parser.lookAheadFor(indent, parser.pos + newLineLength)) {
593
622
  parser.startText();
@@ -614,7 +643,7 @@ var CDATA = {
614
643
  },
615
644
  exit(cdata) {
616
645
  var _a, _b;
617
- (_b = (_a = this.handlers).onCDATA) == null ? void 0 : _b.call(_a, {
646
+ (_b = (_a = this.options).onCDATA) == null ? void 0 : _b.call(_a, {
618
647
  start: cdata.start,
619
648
  end: cdata.end,
620
649
  value: {
@@ -633,7 +662,7 @@ var CDATA = {
633
662
  eol() {
634
663
  },
635
664
  eof(cdata) {
636
- this.emitError(cdata, "MALFORMED_CDATA", "EOF reached while parsing CDATA");
665
+ this.emitError(cdata, 14 /* MALFORMED_CDATA */, "EOF reached while parsing CDATA");
637
666
  },
638
667
  return() {
639
668
  }
@@ -672,7 +701,7 @@ var CLOSE_TAG = {
672
701
  eol() {
673
702
  },
674
703
  eof(closeTag) {
675
- this.emitError(closeTag, "MALFORMED_CLOSE_TAG", "EOF reached while parsing closing tag");
704
+ this.emitError(closeTag, 15 /* MALFORMED_CLOSE_TAG */, "EOF reached while parsing closing tag");
676
705
  },
677
706
  return() {
678
707
  }
@@ -709,7 +738,7 @@ function ensureExpectedCloseTag(parser, closeTag) {
709
738
  const closeTagNameStart = closeTag.start + 2;
710
739
  const closeTagNameEnd = closeTag.end - 1;
711
740
  if (!activeTag) {
712
- parser.emitError(closeTag, "EXTRA_CLOSING_TAG", 'The closing "' + parser.read({ start: closeTagNameStart, end: closeTagNameEnd }) + '" tag was not expected');
741
+ parser.emitError(closeTag, 0 /* EXTRA_CLOSING_TAG */, 'The closing "' + parser.read({ start: closeTagNameStart, end: closeTagNameEnd }) + '" tag was not expected');
713
742
  return false;
714
743
  }
715
744
  const closeTagNamePos = {
@@ -722,7 +751,7 @@ function ensureExpectedCloseTag(parser, closeTag) {
722
751
  start: activeTag.tagName.start,
723
752
  end: activeTag.shorthandEnd
724
753
  })) {
725
- parser.emitError(closeTag, "MISMATCHED_CLOSING_TAG", 'The closing "' + parser.read(closeTagNamePos) + '" tag does not match the corresponding opening "' + (parser.read(activeTag.tagName) || "div") + '" tag');
754
+ parser.emitError(closeTag, 21 /* MISMATCHED_CLOSING_TAG */, 'The closing "' + parser.read(closeTagNamePos) + '" tag does not match the corresponding opening "' + (parser.read(activeTag.tagName) || "div") + '" tag');
726
755
  return false;
727
756
  }
728
757
  }
@@ -758,22 +787,18 @@ var CONCISE_HTML_CONTENT = {
758
787
  parentTag = this.activeTag;
759
788
  }
760
789
  if (!parentTag && curIndent) {
761
- this.emitError(this.pos, "BAD_INDENTATION", "Line has extra indentation at the beginning");
790
+ this.emitError(this.pos, 7 /* INVALID_INDENTATION */, "Line has extra indentation at the beginning");
762
791
  return;
763
792
  }
764
793
  if (parentTag) {
765
- if (parentTag.ending !== 0 /* tag */) {
766
- this.emitError(this.pos, "INVALID_BODY", `The "${this.read(parentTag.tagName)}" tag does not allow nested body content`);
767
- return;
768
- }
769
- if (parentTag.bodyMode === 1 /* PARSED_TEXT */ && code !== 45 /* HTML_BLOCK_DELIMITER */) {
770
- this.emitError(this.pos, "ILLEGAL_LINE_START", 'A line within a tag that only allows text content must begin with a "-" character');
794
+ if (parentTag.type === 1 /* text */ && code !== 45 /* HTML_BLOCK_DELIMITER */) {
795
+ this.emitError(this.pos, 8 /* INVALID_LINE_START */, 'A line within a tag that only allows text content must begin with a "-" character');
771
796
  return;
772
797
  }
773
798
  if (parentTag.nestedIndent === void 0) {
774
799
  parentTag.nestedIndent = this.indent;
775
800
  } else if (parentTag.nestedIndent !== this.indent) {
776
- this.emitError(this.pos, "BAD_INDENTATION", "Line indentation does match indentation of previous line");
801
+ this.emitError(this.pos, 7 /* INVALID_INDENTATION */, "Line indentation does match indentation of previous line");
777
802
  return;
778
803
  }
779
804
  }
@@ -795,7 +820,7 @@ var CONCISE_HTML_CONTENT = {
795
820
  this.enterState(states_exports.BEGIN_DELIMITED_HTML_BLOCK);
796
821
  this.pos--;
797
822
  } else {
798
- this.emitError(this.pos, "ILLEGAL_LINE_START", 'A line in concise mode cannot start with a single hyphen. Use "--" instead. See: https://github.com/marko-js/htmljs-parser/issues/43');
823
+ this.emitError(this.pos, 8 /* INVALID_LINE_START */, 'A line in concise mode cannot start with a single hyphen. Use "--" instead. See: https://github.com/marko-js/htmljs-parser/issues/43');
799
824
  }
800
825
  return;
801
826
  case 47 /* FORWARD_SLASH */:
@@ -809,7 +834,7 @@ var CONCISE_HTML_CONTENT = {
809
834
  this.pos++;
810
835
  return;
811
836
  default:
812
- this.emitError(this.pos, "ILLEGAL_LINE_START", 'A line in concise mode cannot start with "/" unless it starts a "//" or "/*" comment');
837
+ this.emitError(this.pos, 8 /* INVALID_LINE_START */, 'A line in concise mode cannot start with "/" unless it starts a "//" or "/*" comment');
813
838
  return;
814
839
  }
815
840
  }
@@ -827,7 +852,7 @@ var CONCISE_HTML_CONTENT = {
827
852
  this.isConcise = true;
828
853
  switch (child.state) {
829
854
  case states_exports.JS_COMMENT_LINE:
830
- (_b = (_a = this.handlers).onComment) == null ? void 0 : _b.call(_a, {
855
+ (_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
831
856
  start: child.start,
832
857
  end: child.end,
833
858
  value: {
@@ -837,7 +862,7 @@ var CONCISE_HTML_CONTENT = {
837
862
  });
838
863
  break;
839
864
  case states_exports.JS_COMMENT_BLOCK: {
840
- (_d = (_c = this.handlers).onComment) == null ? void 0 : _d.call(_c, {
865
+ (_d = (_c = this.options).onComment) == null ? void 0 : _d.call(_c, {
841
866
  start: child.start,
842
867
  end: child.end,
843
868
  value: {
@@ -846,7 +871,7 @@ var CONCISE_HTML_CONTENT = {
846
871
  }
847
872
  });
848
873
  if (!this.consumeWhitespaceOnLine(0)) {
849
- this.emitError(this.pos, "INVALID_CHARACTER", "In concise mode a javascript comment block can only be followed by whitespace characters and a newline.");
874
+ this.emitError(this.pos, 4 /* INVALID_CHARACTER */, "In concise mode a javascript comment block can only be followed by whitespace characters and a newline.");
850
875
  }
851
876
  break;
852
877
  }
@@ -880,7 +905,7 @@ var DECLARATION = {
880
905
  eol() {
881
906
  },
882
907
  eof(declaration) {
883
- this.emitError(declaration, "MALFORMED_DECLARATION", "EOF reached while parsing declaration");
908
+ this.emitError(declaration, 17 /* MALFORMED_DECLARATION */, "EOF reached while parsing declaration");
884
909
  },
885
910
  return() {
886
911
  }
@@ -889,7 +914,7 @@ function exitDeclaration(parser, declaration, closeOffset) {
889
914
  var _a, _b;
890
915
  parser.pos += closeOffset;
891
916
  parser.exitState();
892
- (_b = (_a = parser.handlers).onDeclaration) == null ? void 0 : _b.call(_a, {
917
+ (_b = (_a = parser.options).onDeclaration) == null ? void 0 : _b.call(_a, {
893
918
  start: declaration.start,
894
919
  end: declaration.end,
895
920
  value: {
@@ -913,7 +938,7 @@ var DTD = {
913
938
  },
914
939
  exit(documentType) {
915
940
  var _a, _b;
916
- (_b = (_a = this.handlers).onDoctype) == null ? void 0 : _b.call(_a, {
941
+ (_b = (_a = this.options).onDoctype) == null ? void 0 : _b.call(_a, {
917
942
  start: documentType.start,
918
943
  end: documentType.end,
919
944
  value: {
@@ -931,7 +956,7 @@ var DTD = {
931
956
  eol() {
932
957
  },
933
958
  eof(documentType) {
934
- this.emitError(documentType, "MALFORMED_DOCUMENT_TYPE", "EOF reached while parsing document type");
959
+ this.emitError(documentType, 18 /* MALFORMED_DOCUMENT_TYPE */, "EOF reached while parsing document type");
935
960
  },
936
961
  return() {
937
962
  }
@@ -1011,11 +1036,11 @@ var EXPRESSION = {
1011
1036
  case 93 /* CLOSE_SQUARE_BRACKET */:
1012
1037
  case 125 /* CLOSE_CURLY_BRACE */: {
1013
1038
  if (!expression.groupStack.length) {
1014
- return this.emitError(expression, "INVALID_EXPRESSION", 'Mismatched group. A closing "' + String.fromCharCode(code) + '" character was found but it is not matched with a corresponding opening character.');
1039
+ return this.emitError(expression, 6 /* INVALID_EXPRESSION */, 'Mismatched group. A closing "' + String.fromCharCode(code) + '" character was found but it is not matched with a corresponding opening character.');
1015
1040
  }
1016
1041
  const expectedCode = expression.groupStack.pop();
1017
1042
  if (expectedCode !== code) {
1018
- return this.emitError(expression, "INVALID_EXPRESSION", 'Mismatched group. A "' + String.fromCharCode(code) + '" character was found when "' + String.fromCharCode(expectedCode) + '" was expected.');
1043
+ return this.emitError(expression, 6 /* INVALID_EXPRESSION */, 'Mismatched group. A "' + String.fromCharCode(code) + '" character was found when "' + String.fromCharCode(expectedCode) + '" was expected.');
1019
1044
  }
1020
1045
  break;
1021
1046
  }
@@ -1023,11 +1048,7 @@ var EXPRESSION = {
1023
1048
  },
1024
1049
  eol(_, expression) {
1025
1050
  if (!expression.groupStack.length && (expression.terminatedByWhitespace || expression.terminatedByEOL)) {
1026
- if (checkForOperators(this, expression)) {
1027
- this.forward = 1;
1028
- } else {
1029
- this.exitState();
1030
- }
1051
+ this.exitState();
1031
1052
  }
1032
1053
  },
1033
1054
  eof(expression) {
@@ -1039,16 +1060,16 @@ var EXPRESSION = {
1039
1060
  case states_exports.ATTRIBUTE: {
1040
1061
  const attr = parent;
1041
1062
  if (!attr.spread && !attr.name) {
1042
- return this.emitError(expression, "MALFORMED_OPEN_TAG", 'EOF reached while parsing attribute name for the "' + this.read(this.activeTag.tagName) + '" tag');
1063
+ return this.emitError(expression, 19 /* MALFORMED_OPEN_TAG */, 'EOF reached while parsing attribute name for the "' + this.read(this.activeTag.tagName) + '" tag');
1043
1064
  }
1044
- return this.emitError(expression, "MALFORMED_OPEN_TAG", `EOF reached while parsing attribute value for the ${attr.spread ? "..." : attr.name ? `"${this.read(attr.name)}"` : `"default"`} attribute`);
1065
+ return this.emitError(expression, 19 /* MALFORMED_OPEN_TAG */, `EOF reached while parsing attribute value for the ${attr.spread ? "..." : attr.name ? `"${this.read(attr.name)}"` : `"default"`} attribute`);
1045
1066
  }
1046
1067
  case states_exports.TAG_NAME:
1047
- return this.emitError(expression, "MALFORMED_OPEN_TAG", "EOF reached while parsing tag name");
1068
+ return this.emitError(expression, 19 /* MALFORMED_OPEN_TAG */, "EOF reached while parsing tag name");
1048
1069
  case states_exports.PLACEHOLDER:
1049
- return this.emitError(expression, "MALFORMED_PLACEHOLDER", "EOF reached while parsing placeholder");
1070
+ return this.emitError(expression, 20 /* MALFORMED_PLACEHOLDER */, "EOF reached while parsing placeholder");
1050
1071
  }
1051
- return this.emitError(expression, "INVALID_EXPRESSION", "EOF reached while parsing expression");
1072
+ return this.emitError(expression, 6 /* INVALID_EXPRESSION */, "EOF reached while parsing expression");
1052
1073
  }
1053
1074
  },
1054
1075
  return() {
@@ -1116,7 +1137,7 @@ var HTML_COMMENT = {
1116
1137
  },
1117
1138
  exit(comment) {
1118
1139
  var _a, _b;
1119
- (_b = (_a = this.handlers).onComment) == null ? void 0 : _b.call(_a, {
1140
+ (_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
1120
1141
  start: comment.start,
1121
1142
  end: comment.end,
1122
1143
  value: {
@@ -1140,7 +1161,7 @@ var HTML_COMMENT = {
1140
1161
  eol() {
1141
1162
  },
1142
1163
  eof(comment) {
1143
- this.emitError(comment, "MALFORMED_COMMENT", "EOF reached while parsing comment");
1164
+ this.emitError(comment, 16 /* MALFORMED_COMMENT */, "EOF reached while parsing comment");
1144
1165
  },
1145
1166
  return() {
1146
1167
  }
@@ -1246,7 +1267,7 @@ var INLINE_SCRIPT = {
1246
1267
  },
1247
1268
  exit(inlineScript) {
1248
1269
  var _a, _b;
1249
- (_b = (_a = this.handlers).onScriptlet) == null ? void 0 : _b.call(_a, {
1270
+ (_b = (_a = this.options).onScriptlet) == null ? void 0 : _b.call(_a, {
1250
1271
  start: inlineScript.start,
1251
1272
  end: inlineScript.end,
1252
1273
  block: inlineScript.block,
@@ -1305,7 +1326,7 @@ var JS_COMMENT_BLOCK = {
1305
1326
  eol() {
1306
1327
  },
1307
1328
  eof(comment) {
1308
- this.emitError(comment, "MALFORMED_COMMENT", "EOF reached while parsing multi-line JavaScript comment");
1329
+ this.emitError(comment, 16 /* MALFORMED_COMMENT */, "EOF reached while parsing multi-line JavaScript comment");
1309
1330
  },
1310
1331
  return() {
1311
1332
  }
@@ -1326,7 +1347,7 @@ var JS_COMMENT_LINE = {
1326
1347
  },
1327
1348
  char(code) {
1328
1349
  var _a;
1329
- if (!this.isConcise && code === 60 /* OPEN_ANGLE_BRACKET */ && ((_a = this.activeTag) == null ? void 0 : _a.bodyMode) === 1 /* PARSED_TEXT */) {
1350
+ if (!this.isConcise && code === 60 /* OPEN_ANGLE_BRACKET */ && ((_a = this.activeTag) == null ? void 0 : _a.type) === 1 /* text */) {
1330
1351
  states_exports.checkForClosingTag(this);
1331
1352
  }
1332
1353
  },
@@ -1410,7 +1431,7 @@ var PLACEHOLDER = {
1410
1431
  },
1411
1432
  exit(placeholder) {
1412
1433
  var _a, _b;
1413
- (_b = (_a = this.handlers).onPlaceholder) == null ? void 0 : _b.call(_a, {
1434
+ (_b = (_a = this.options).onPlaceholder) == null ? void 0 : _b.call(_a, {
1414
1435
  start: placeholder.start,
1415
1436
  end: placeholder.end,
1416
1437
  escape: placeholder.escape,
@@ -1428,7 +1449,7 @@ var PLACEHOLDER = {
1428
1449
  },
1429
1450
  return(child) {
1430
1451
  if (child.start === child.end) {
1431
- this.emitError(child, "PLACEHOLDER_EXPRESSION_REQUIRED", "Invalid placeholder, the expression cannot be missing");
1452
+ this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
1432
1453
  }
1433
1454
  this.pos++;
1434
1455
  this.exitState();
@@ -1502,10 +1523,10 @@ var REGULAR_EXPRESSION = {
1502
1523
  }
1503
1524
  },
1504
1525
  eol(_, regExp) {
1505
- this.emitError(regExp, "INVALID_REGULAR_EXPRESSION", "EOL reached while parsing regular expression");
1526
+ this.emitError(regExp, 9 /* INVALID_REGULAR_EXPRESSION */, "EOL reached while parsing regular expression");
1506
1527
  },
1507
1528
  eof(regExp) {
1508
- this.emitError(regExp, "INVALID_REGULAR_EXPRESSION", "EOF reached while parsing regular expression");
1529
+ this.emitError(regExp, 9 /* INVALID_REGULAR_EXPRESSION */, "EOF reached while parsing regular expression");
1509
1530
  },
1510
1531
  return() {
1511
1532
  }
@@ -1539,30 +1560,13 @@ var STRING = {
1539
1560
  eol() {
1540
1561
  },
1541
1562
  eof(string) {
1542
- this.emitError(string, "INVALID_STRING", "EOF reached while parsing string expression");
1563
+ this.emitError(string, 10 /* INVALID_STRING */, "EOF reached while parsing string expression");
1543
1564
  },
1544
1565
  return() {
1545
1566
  }
1546
1567
  };
1547
1568
 
1548
1569
  // src/states/TAG_NAME.ts
1549
- var VOID_TAGS = [
1550
- "area",
1551
- "base",
1552
- "br",
1553
- "col",
1554
- "hr",
1555
- "embed",
1556
- "img",
1557
- "input",
1558
- "link",
1559
- "meta",
1560
- "param",
1561
- "source",
1562
- "track",
1563
- "wbr"
1564
- ];
1565
- var CODE_TAGS = ["import", "export", "static", "class"];
1566
1570
  var TAG_NAME = {
1567
1571
  name: "TAG_NAME",
1568
1572
  enter(parent, start) {
@@ -1584,10 +1588,10 @@ var TAG_NAME = {
1584
1588
  switch (tagName.shorthandCode) {
1585
1589
  case 35 /* NUMBER_SIGN */:
1586
1590
  if (this.activeTag.hasShorthandId) {
1587
- return this.emitError(tagName, "INVALID_TAG_SHORTHAND", "Multiple shorthand ID parts are not allowed on the same tag");
1591
+ return this.emitError(tagName, 12 /* INVALID_TAG_SHORTHAND */, "Multiple shorthand ID parts are not allowed on the same tag");
1588
1592
  }
1589
1593
  this.activeTag.hasShorthandId = true;
1590
- (_b = (_a = this.handlers).onTagShorthandId) == null ? void 0 : _b.call(_a, {
1594
+ (_b = (_a = this.options).onTagShorthandId) == null ? void 0 : _b.call(_a, {
1591
1595
  start,
1592
1596
  end,
1593
1597
  quasis,
@@ -1595,7 +1599,7 @@ var TAG_NAME = {
1595
1599
  });
1596
1600
  break;
1597
1601
  case 46 /* PERIOD */:
1598
- (_d = (_c = this.handlers).onTagShorthandClass) == null ? void 0 : _d.call(_c, {
1602
+ (_d = (_c = this.options).onTagShorthandClass) == null ? void 0 : _d.call(_c, {
1599
1603
  start,
1600
1604
  end,
1601
1605
  quasis,
@@ -1604,28 +1608,26 @@ var TAG_NAME = {
1604
1608
  break;
1605
1609
  default: {
1606
1610
  const tag = this.activeTag;
1611
+ const tagType = (_f = (_e = this.options).onTagName) == null ? void 0 : _f.call(_e, {
1612
+ start,
1613
+ end,
1614
+ quasis,
1615
+ expressions,
1616
+ concise: this.isConcise
1617
+ });
1607
1618
  tag.tagName = tagName;
1608
- if (tagName.expressions.length === 0) {
1609
- if (this.matchAnyAtPos(tagName, VOID_TAGS)) {
1610
- tag.ending |= 2 /* void */;
1611
- } else if (this.matchAnyAtPos(tagName, CODE_TAGS)) {
1619
+ if (tagType) {
1620
+ tag.type = tagType;
1621
+ if (tagType === 3 /* statement */) {
1612
1622
  if (!tag.concise) {
1613
- return this.emitError(tagName, "RESERVED_TAG_NAME", `The "${this.read(tagName)}" tag is reserved and cannot be used as an HTML tag.`);
1623
+ return this.emitError(tagName, 24 /* RESERVED_TAG_NAME */, `The "${this.read(tagName)}" tag is reserved and cannot be used as an HTML tag.`);
1614
1624
  }
1615
1625
  if (tag.parentTag) {
1616
- return this.emitError(tagName, "ROOT_TAG_ONLY", `"${this.read(tagName)}" can only be used at the root of the template.`);
1626
+ return this.emitError(tagName, 25 /* ROOT_TAG_ONLY */, `"${this.read(tagName)}" can only be used at the root of the template.`);
1617
1627
  }
1618
- tag.ending |= 4 /* code */;
1619
1628
  this.enterState(states_exports.EXPRESSION).terminatedByEOL = true;
1620
1629
  }
1621
1630
  }
1622
- (_f = (_e = this.handlers).onTagName) == null ? void 0 : _f.call(_e, {
1623
- start,
1624
- end,
1625
- quasis,
1626
- expressions,
1627
- concise: this.isConcise
1628
- });
1629
1631
  break;
1630
1632
  }
1631
1633
  }
@@ -1656,12 +1658,12 @@ var TAG_NAME = {
1656
1658
  if (child.terminatedByEOL)
1657
1659
  return;
1658
1660
  if (child.start === child.end) {
1659
- this.emitError(child, "PLACEHOLDER_EXPRESSION_REQUIRED", "Invalid placeholder, the expression cannot be missing");
1661
+ this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
1660
1662
  }
1661
1663
  const { quasis, expressions } = tagName;
1662
1664
  const start = child.start - 2;
1663
1665
  const end = ++this.pos;
1664
- const nextStart = end + 1;
1666
+ const nextStart = end;
1665
1667
  expressions.push({
1666
1668
  start,
1667
1669
  end,
@@ -1704,20 +1706,19 @@ var TEMPLATE_STRING = {
1704
1706
  }
1705
1707
  },
1706
1708
  eof(templateString) {
1707
- this.emitError(templateString, "INVALID_TEMPLATE_STRING", "EOF reached while parsing template string expression");
1709
+ this.emitError(templateString, 13 /* INVALID_TEMPLATE_STRING */, "EOF reached while parsing template string expression");
1708
1710
  },
1709
1711
  eol() {
1710
1712
  },
1711
1713
  return(child) {
1712
1714
  if (child.start === child.end) {
1713
- this.emitError(child, "PLACEHOLDER_EXPRESSION_REQUIRED", "Invalid placeholder, the expression cannot be missing");
1715
+ this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
1714
1716
  }
1715
1717
  this.pos++;
1716
1718
  }
1717
1719
  };
1718
1720
 
1719
1721
  // src/states/OPEN_TAG.ts
1720
- var PARSED_TEXT_TAGS = ["script", "style", "textarea", "html-comment"];
1721
1722
  var CONCISE_TAG_VAR_TERMINATORS = [
1722
1723
  59 /* SEMICOLON */,
1723
1724
  40 /* OPEN_PAREN */,
@@ -1738,6 +1739,7 @@ var OPEN_TAG = {
1738
1739
  enter(parent, start) {
1739
1740
  const tag = this.activeTag = {
1740
1741
  state: OPEN_TAG,
1742
+ type: 0 /* html */,
1741
1743
  parent,
1742
1744
  start,
1743
1745
  end: start,
@@ -1748,11 +1750,10 @@ var OPEN_TAG = {
1748
1750
  hasShorthandId: false,
1749
1751
  hasArgs: false,
1750
1752
  hasAttrs: false,
1753
+ selfClosed: false,
1751
1754
  shorthandEnd: -1,
1752
1755
  tagName: void 0,
1753
- ending: 0 /* tag */,
1754
1756
  concise: this.isConcise,
1755
- bodyMode: 0 /* HTML */,
1756
1757
  beginMixedMode: this.beginMixedMode || this.endingMixedModeAtEOL
1757
1758
  };
1758
1759
  this.beginMixedMode = false;
@@ -1762,21 +1763,27 @@ var OPEN_TAG = {
1762
1763
  },
1763
1764
  exit(tag) {
1764
1765
  var _a, _b;
1765
- const { tagName, ending } = tag;
1766
- (_b = (_a = this.handlers).onOpenTagEnd) == null ? void 0 : _b.call(_a, {
1767
- start: this.pos - (this.isConcise ? 0 : ending & 1 /* self */ ? 2 : 1),
1766
+ const { selfClosed } = tag;
1767
+ (_b = (_a = this.options).onOpenTagEnd) == null ? void 0 : _b.call(_a, {
1768
+ start: this.pos - (this.isConcise ? 0 : selfClosed ? 2 : 1),
1768
1769
  end: this.pos,
1769
- ending
1770
+ selfClosed
1770
1771
  });
1771
- if (!this.isConcise && ending !== 0 /* tag */) {
1772
- this.closeTag(this.pos, this.pos, void 0);
1773
- } else if (tagName.expressions.length === 0 && this.matchAnyAtPos(tagName, PARSED_TEXT_TAGS)) {
1774
- tag.bodyMode = 1 /* PARSED_TEXT */;
1775
- if (this.isConcise) {
1776
- this.enterState(states_exports.CONCISE_HTML_CONTENT);
1777
- } else {
1778
- this.enterState(states_exports.PARSED_TEXT_CONTENT);
1772
+ switch (selfClosed ? 2 /* void */ : tag.type) {
1773
+ case 2 /* void */:
1774
+ case 3 /* statement */: {
1775
+ if (tag.beginMixedMode)
1776
+ this.endingMixedModeAtEOL = true;
1777
+ this.activeTag = tag.parentTag;
1778
+ break;
1779
1779
  }
1780
+ case 1 /* text */:
1781
+ if (this.isConcise) {
1782
+ this.enterState(states_exports.CONCISE_HTML_CONTENT);
1783
+ } else {
1784
+ this.enterState(states_exports.PARSED_TEXT_CONTENT);
1785
+ }
1786
+ break;
1780
1787
  }
1781
1788
  },
1782
1789
  eol(_, tag) {
@@ -1787,12 +1794,12 @@ var OPEN_TAG = {
1787
1794
  eof(tag) {
1788
1795
  if (this.isConcise) {
1789
1796
  if (tag.stage === 4 /* ATTR_GROUP */) {
1790
- this.emitError(tag, "MALFORMED_OPEN_TAG", 'EOF reached while within an attribute group (e.g. "[ ... ]").');
1797
+ this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, 'EOF reached while within an attribute group (e.g. "[ ... ]").');
1791
1798
  return;
1792
1799
  }
1793
1800
  this.exitState();
1794
1801
  } else {
1795
- this.emitError(tag, "MALFORMED_OPEN_TAG", "EOF reached while parsing open tag");
1802
+ this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, "EOF reached while parsing open tag");
1796
1803
  }
1797
1804
  },
1798
1805
  char(code, tag) {
@@ -1822,17 +1829,17 @@ var OPEN_TAG = {
1822
1829
  }
1823
1830
  break;
1824
1831
  }
1825
- this.emitError(this.pos, "INVALID_CODE_AFTER_SEMICOLON", "A semicolon indicates the end of a line. Only comments may follow it.");
1832
+ this.emitError(this.pos, 5 /* INVALID_CODE_AFTER_SEMICOLON */, "A semicolon indicates the end of a line. Only comments may follow it.");
1826
1833
  }
1827
1834
  return;
1828
1835
  }
1829
1836
  if (code === 45 /* HTML_BLOCK_DELIMITER */) {
1830
1837
  if (this.lookAtCharCodeAhead(1) !== 45 /* HTML_BLOCK_DELIMITER */) {
1831
- this.emitError(tag, "MALFORMED_OPEN_TAG", '"-" not allowed as first character of attribute name');
1838
+ this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, '"-" not allowed as first character of attribute name');
1832
1839
  return;
1833
1840
  }
1834
1841
  if (tag.stage === 4 /* ATTR_GROUP */) {
1835
- this.emitError(this.pos, "MALFORMED_OPEN_TAG", "Attribute group was not properly ended");
1842
+ this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, "Attribute group was not properly ended");
1836
1843
  return;
1837
1844
  }
1838
1845
  this.exitState();
@@ -1857,14 +1864,14 @@ var OPEN_TAG = {
1857
1864
  return;
1858
1865
  } else if (code === 91 /* OPEN_SQUARE_BRACKET */) {
1859
1866
  if (tag.stage === 4 /* ATTR_GROUP */) {
1860
- this.emitError(this.pos, "MALFORMED_OPEN_TAG", 'Unexpected "[" character within open tag.');
1867
+ this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, 'Unexpected "[" character within open tag.');
1861
1868
  return;
1862
1869
  }
1863
1870
  tag.stage = 4 /* ATTR_GROUP */;
1864
1871
  return;
1865
1872
  } else if (code === 93 /* CLOSE_SQUARE_BRACKET */) {
1866
1873
  if (tag.stage !== 4 /* ATTR_GROUP */) {
1867
- this.emitError(this.pos, "MALFORMED_OPEN_TAG", 'Unexpected "]" character within open tag.');
1874
+ this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, 'Unexpected "]" character within open tag.');
1868
1875
  return;
1869
1876
  }
1870
1877
  tag.stage = 0 /* UNKNOWN */;
@@ -1875,13 +1882,13 @@ var OPEN_TAG = {
1875
1882
  this.exitState();
1876
1883
  return;
1877
1884
  } else if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 62 /* CLOSE_ANGLE_BRACKET */) {
1878
- tag.ending |= 1 /* self */;
1885
+ tag.selfClosed = true;
1879
1886
  this.pos += 2;
1880
1887
  this.exitState();
1881
1888
  return;
1882
1889
  }
1883
1890
  if (code === 60 /* OPEN_ANGLE_BRACKET */) {
1884
- return this.emitError(this.pos, "ILLEGAL_ATTRIBUTE_NAME", 'Invalid attribute name. Attribute name cannot begin with the "<" character.');
1891
+ return this.emitError(this.pos, 2 /* INVALID_ATTRIBUTE_NAME */, 'Invalid attribute name. Attribute name cannot begin with the "<" character.');
1885
1892
  }
1886
1893
  if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 42 /* ASTERISK */) {
1887
1894
  this.enterState(states_exports.JS_COMMENT_BLOCK);
@@ -1903,7 +1910,7 @@ var OPEN_TAG = {
1903
1910
  this.pos--;
1904
1911
  } else if (code === 40 /* OPEN_PAREN */ && !tag.hasAttrs) {
1905
1912
  if (tag.hasArgs) {
1906
- this.emitError(this.pos, "ILLEGAL_TAG_ARGUMENT", "A tag can only have one argument");
1913
+ this.emitError(this.pos, 11 /* INVALID_TAG_ARGUMENT */, "A tag can only have one argument");
1907
1914
  return;
1908
1915
  }
1909
1916
  tag.stage = 2 /* ARGUMENT */;
@@ -1939,9 +1946,9 @@ var OPEN_TAG = {
1939
1946
  switch (tag.stage) {
1940
1947
  case 1 /* VAR */: {
1941
1948
  if (child.start === child.end) {
1942
- return this.emitError(child, "MISSING_TAG_VARIABLE", "A slash was found that was not followed by a variable name or lhs expression");
1949
+ return this.emitError(child, 23 /* MISSING_TAG_VARIABLE */, "A slash was found that was not followed by a variable name or lhs expression");
1943
1950
  }
1944
- (_b = (_a = this.handlers).onTagVar) == null ? void 0 : _b.call(_a, {
1951
+ (_b = (_a = this.options).onTagVar) == null ? void 0 : _b.call(_a, {
1945
1952
  start: child.start - 1,
1946
1953
  end: child.end,
1947
1954
  value: {
@@ -1966,7 +1973,7 @@ var OPEN_TAG = {
1966
1973
  this.pos--;
1967
1974
  } else {
1968
1975
  tag.hasArgs = true;
1969
- (_d = (_c = this.handlers).onTagArgs) == null ? void 0 : _d.call(_c, {
1976
+ (_d = (_c = this.options).onTagArgs) == null ? void 0 : _d.call(_c, {
1970
1977
  start,
1971
1978
  end,
1972
1979
  value
@@ -1976,7 +1983,7 @@ var OPEN_TAG = {
1976
1983
  }
1977
1984
  case 3 /* PARAMS */: {
1978
1985
  const end = ++this.pos;
1979
- (_f = (_e = this.handlers).onTagParams) == null ? void 0 : _f.call(_e, {
1986
+ (_f = (_e = this.options).onTagParams) == null ? void 0 : _f.call(_e, {
1980
1987
  start: child.start - 1,
1981
1988
  end,
1982
1989
  value: {
@@ -2003,8 +2010,8 @@ function createParser(handlers) {
2003
2010
  read(range) {
2004
2011
  return parser.read(range);
2005
2012
  },
2006
- positionAt(index) {
2007
- return parser.positionAt(index);
2013
+ positionAt(offset) {
2014
+ return parser.positionAt(offset);
2008
2015
  },
2009
2016
  locationAt(range) {
2010
2017
  return parser.locationAt(range);
@@ -2012,6 +2019,7 @@ function createParser(handlers) {
2012
2019
  };
2013
2020
  }
2014
2021
  export {
2015
- OpenTagEnding,
2022
+ ErrorCode,
2023
+ TagType,
2016
2024
  createParser
2017
2025
  };