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.js CHANGED
@@ -19,19 +19,49 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/index.ts
20
20
  var src_exports = {};
21
21
  __export(src_exports, {
22
- OpenTagEnding: () => OpenTagEnding,
22
+ ErrorCode: () => ErrorCode,
23
+ TagType: () => TagType,
23
24
  createParser: () => createParser
24
25
  });
25
26
  module.exports = __toCommonJS(src_exports);
26
27
 
27
28
  // src/util/constants.ts
28
- var OpenTagEnding = /* @__PURE__ */ ((OpenTagEnding2) => {
29
- OpenTagEnding2[OpenTagEnding2["tag"] = 0] = "tag";
30
- OpenTagEnding2[OpenTagEnding2["self"] = 1] = "self";
31
- OpenTagEnding2[OpenTagEnding2["void"] = 2] = "void";
32
- OpenTagEnding2[OpenTagEnding2["code"] = 4] = "code";
33
- return OpenTagEnding2;
34
- })(OpenTagEnding || {});
29
+ var ErrorCode = /* @__PURE__ */ ((ErrorCode3) => {
30
+ ErrorCode3[ErrorCode3["EXTRA_CLOSING_TAG"] = 0] = "EXTRA_CLOSING_TAG";
31
+ ErrorCode3[ErrorCode3["INVALID_ATTRIBUTE_ARGUMENT"] = 1] = "INVALID_ATTRIBUTE_ARGUMENT";
32
+ ErrorCode3[ErrorCode3["INVALID_ATTRIBUTE_NAME"] = 2] = "INVALID_ATTRIBUTE_NAME";
33
+ ErrorCode3[ErrorCode3["INVALID_ATTRIBUTE_VALUE"] = 3] = "INVALID_ATTRIBUTE_VALUE";
34
+ ErrorCode3[ErrorCode3["INVALID_CHARACTER"] = 4] = "INVALID_CHARACTER";
35
+ ErrorCode3[ErrorCode3["INVALID_CODE_AFTER_SEMICOLON"] = 5] = "INVALID_CODE_AFTER_SEMICOLON";
36
+ ErrorCode3[ErrorCode3["INVALID_EXPRESSION"] = 6] = "INVALID_EXPRESSION";
37
+ ErrorCode3[ErrorCode3["INVALID_INDENTATION"] = 7] = "INVALID_INDENTATION";
38
+ ErrorCode3[ErrorCode3["INVALID_LINE_START"] = 8] = "INVALID_LINE_START";
39
+ ErrorCode3[ErrorCode3["INVALID_REGULAR_EXPRESSION"] = 9] = "INVALID_REGULAR_EXPRESSION";
40
+ ErrorCode3[ErrorCode3["INVALID_STRING"] = 10] = "INVALID_STRING";
41
+ ErrorCode3[ErrorCode3["INVALID_TAG_ARGUMENT"] = 11] = "INVALID_TAG_ARGUMENT";
42
+ ErrorCode3[ErrorCode3["INVALID_TAG_SHORTHAND"] = 12] = "INVALID_TAG_SHORTHAND";
43
+ ErrorCode3[ErrorCode3["INVALID_TEMPLATE_STRING"] = 13] = "INVALID_TEMPLATE_STRING";
44
+ ErrorCode3[ErrorCode3["MALFORMED_CDATA"] = 14] = "MALFORMED_CDATA";
45
+ ErrorCode3[ErrorCode3["MALFORMED_CLOSE_TAG"] = 15] = "MALFORMED_CLOSE_TAG";
46
+ ErrorCode3[ErrorCode3["MALFORMED_COMMENT"] = 16] = "MALFORMED_COMMENT";
47
+ ErrorCode3[ErrorCode3["MALFORMED_DECLARATION"] = 17] = "MALFORMED_DECLARATION";
48
+ ErrorCode3[ErrorCode3["MALFORMED_DOCUMENT_TYPE"] = 18] = "MALFORMED_DOCUMENT_TYPE";
49
+ ErrorCode3[ErrorCode3["MALFORMED_OPEN_TAG"] = 19] = "MALFORMED_OPEN_TAG";
50
+ ErrorCode3[ErrorCode3["MALFORMED_PLACEHOLDER"] = 20] = "MALFORMED_PLACEHOLDER";
51
+ ErrorCode3[ErrorCode3["MISMATCHED_CLOSING_TAG"] = 21] = "MISMATCHED_CLOSING_TAG";
52
+ ErrorCode3[ErrorCode3["MISSING_END_TAG"] = 22] = "MISSING_END_TAG";
53
+ ErrorCode3[ErrorCode3["MISSING_TAG_VARIABLE"] = 23] = "MISSING_TAG_VARIABLE";
54
+ ErrorCode3[ErrorCode3["RESERVED_TAG_NAME"] = 24] = "RESERVED_TAG_NAME";
55
+ ErrorCode3[ErrorCode3["ROOT_TAG_ONLY"] = 25] = "ROOT_TAG_ONLY";
56
+ return ErrorCode3;
57
+ })(ErrorCode || {});
58
+ var TagType = /* @__PURE__ */ ((TagType2) => {
59
+ TagType2[TagType2["html"] = 0] = "html";
60
+ TagType2[TagType2["text"] = 1] = "text";
61
+ TagType2[TagType2["void"] = 2] = "void";
62
+ TagType2[TagType2["statement"] = 3] = "statement";
63
+ return TagType2;
64
+ })(TagType || {});
35
65
 
36
66
  // src/util/util.ts
37
67
  function isWhitespaceCode(code) {
@@ -73,16 +103,16 @@ function htmlEOF() {
73
103
  if (this.activeTag.concise) {
74
104
  this.closeTag(this.pos, this.pos, void 0);
75
105
  } else {
76
- return this.emitError(this.activeTag, "MISSING_END_TAG", 'Missing ending "' + this.read(this.activeTag.tagName) + '" tag');
106
+ return this.emitError(this.activeTag, 22 /* MISSING_END_TAG */, 'Missing ending "' + this.read(this.activeTag.tagName) + '" tag');
77
107
  }
78
108
  }
79
109
  }
80
110
 
81
111
  // src/core/Parser.ts
82
112
  var Parser = class {
83
- constructor(handlers) {
84
- this.handlers = handlers;
85
- this.handlers = handlers;
113
+ constructor(options) {
114
+ this.options = options;
115
+ this.options = options;
86
116
  }
87
117
  pos;
88
118
  maxPos;
@@ -173,13 +203,13 @@ var Parser = class {
173
203
  var _a, _b;
174
204
  const start = this.textPos;
175
205
  if (start !== -1) {
176
- (_b = (_a = this.handlers).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
206
+ (_b = (_a = this.options).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
177
207
  this.textPos = -1;
178
208
  }
179
209
  }
180
210
  beginHtmlBlock(delimiter, singleLine) {
181
211
  var _a;
182
- const content = this.enterState(((_a = this.activeTag) == null ? void 0 : _a.bodyMode) === 1 /* PARSED_TEXT */ ? states_exports.PARSED_TEXT_CONTENT : states_exports.HTML_CONTENT);
212
+ const content = this.enterState(((_a = this.activeTag) == null ? void 0 : _a.type) === 1 /* text */ ? states_exports.PARSED_TEXT_CONTENT : states_exports.HTML_CONTENT);
183
213
  content.singleLine = singleLine;
184
214
  content.delimiter = delimiter;
185
215
  content.indent = this.indent;
@@ -193,7 +223,7 @@ var Parser = class {
193
223
  start = range.start;
194
224
  end = range.end;
195
225
  }
196
- (_b = (_a = this.handlers).onError) == null ? void 0 : _b.call(_a, {
226
+ (_b = (_a = this.options).onError) == null ? void 0 : _b.call(_a, {
197
227
  start,
198
228
  end,
199
229
  code,
@@ -207,7 +237,7 @@ var Parser = class {
207
237
  if (beginMixedMode)
208
238
  this.endingMixedModeAtEOL = true;
209
239
  this.activeTag = parentTag;
210
- (_b = (_a = this.handlers).onCloseTag) == null ? void 0 : _b.call(_a, {
240
+ (_b = (_a = this.options).onCloseTag) == null ? void 0 : _b.call(_a, {
211
241
  start,
212
242
  end,
213
243
  value
@@ -443,7 +473,7 @@ var ATTRIBUTE = {
443
473
  if (this.isConcise) {
444
474
  this.exitState();
445
475
  } else {
446
- 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');
476
+ 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');
447
477
  }
448
478
  },
449
479
  return(child, attr) {
@@ -454,12 +484,12 @@ var ATTRIBUTE = {
454
484
  start: child.start,
455
485
  end: child.end
456
486
  };
457
- (_b = (_a = this.handlers).onAttrName) == null ? void 0 : _b.call(_a, attr.name);
487
+ (_b = (_a = this.options).onAttrName) == null ? void 0 : _b.call(_a, attr.name);
458
488
  break;
459
489
  }
460
490
  case 3 /* ARGUMENT */: {
461
491
  if (attr.args) {
462
- this.emitError(child, "ILLEGAL_ATTRIBUTE_ARGUMENT", "An attribute can only have one set of arguments");
492
+ this.emitError(child, 1 /* INVALID_ATTRIBUTE_ARGUMENT */, "An attribute can only have one set of arguments");
463
493
  return;
464
494
  }
465
495
  const start = child.start - 1;
@@ -476,7 +506,7 @@ var ATTRIBUTE = {
476
506
  };
477
507
  } else {
478
508
  attr.args = true;
479
- (_d = (_c = this.handlers).onAttrArgs) == null ? void 0 : _d.call(_c, {
509
+ (_d = (_c = this.options).onAttrArgs) == null ? void 0 : _d.call(_c, {
480
510
  start,
481
511
  end,
482
512
  value
@@ -488,7 +518,7 @@ var ATTRIBUTE = {
488
518
  const params = attr.args;
489
519
  const start = params.start;
490
520
  const end = ++this.pos;
491
- (_f = (_e = this.handlers).onAttrMethod) == null ? void 0 : _f.call(_e, {
521
+ (_f = (_e = this.options).onAttrMethod) == null ? void 0 : _f.call(_e, {
492
522
  start,
493
523
  end,
494
524
  params,
@@ -506,10 +536,10 @@ var ATTRIBUTE = {
506
536
  }
507
537
  case 2 /* VALUE */: {
508
538
  if (child.start === child.end) {
509
- return this.emitError(child, "ILLEGAL_ATTRIBUTE_VALUE", "Missing value for attribute");
539
+ return this.emitError(child, 3 /* INVALID_ATTRIBUTE_VALUE */, "Missing value for attribute");
510
540
  }
511
541
  if (attr.spread) {
512
- (_h = (_g = this.handlers).onAttrSpread) == null ? void 0 : _h.call(_g, {
542
+ (_h = (_g = this.options).onAttrSpread) == null ? void 0 : _h.call(_g, {
513
543
  start: attr.valueStart,
514
544
  end: child.end,
515
545
  value: {
@@ -518,7 +548,7 @@ var ATTRIBUTE = {
518
548
  }
519
549
  });
520
550
  } else {
521
- (_j = (_i = this.handlers).onAttrValue) == null ? void 0 : _j.call(_i, {
551
+ (_j = (_i = this.options).onAttrValue) == null ? void 0 : _j.call(_i, {
522
552
  start: attr.valueStart,
523
553
  end: child.end,
524
554
  bound: attr.bound,
@@ -537,7 +567,7 @@ var ATTRIBUTE = {
537
567
  function ensureAttrName(parser, attr) {
538
568
  var _a, _b;
539
569
  if (!attr.name) {
540
- (_b = (_a = parser.handlers).onAttrName) == null ? void 0 : _b.call(_a, {
570
+ (_b = (_a = parser.options).onAttrName) == null ? void 0 : _b.call(_a, {
541
571
  start: attr.start,
542
572
  end: attr.start
543
573
  });
@@ -607,7 +637,7 @@ function handleDelimitedBlockEOL(parser, newLineLength, {
607
637
  parser.exitState();
608
638
  parser.exitState();
609
639
  } else {
610
- parser.emitError(parser.pos, "INVALID_CHARACTER", "A concise mode closing block delimiter can only be followed by whitespace.");
640
+ parser.emitError(parser.pos, 4 /* INVALID_CHARACTER */, "A concise mode closing block delimiter can only be followed by whitespace.");
611
641
  }
612
642
  } else if (parser.lookAheadFor(indent, parser.pos + newLineLength)) {
613
643
  parser.startText();
@@ -634,7 +664,7 @@ var CDATA = {
634
664
  },
635
665
  exit(cdata) {
636
666
  var _a, _b;
637
- (_b = (_a = this.handlers).onCDATA) == null ? void 0 : _b.call(_a, {
667
+ (_b = (_a = this.options).onCDATA) == null ? void 0 : _b.call(_a, {
638
668
  start: cdata.start,
639
669
  end: cdata.end,
640
670
  value: {
@@ -653,7 +683,7 @@ var CDATA = {
653
683
  eol() {
654
684
  },
655
685
  eof(cdata) {
656
- this.emitError(cdata, "MALFORMED_CDATA", "EOF reached while parsing CDATA");
686
+ this.emitError(cdata, 14 /* MALFORMED_CDATA */, "EOF reached while parsing CDATA");
657
687
  },
658
688
  return() {
659
689
  }
@@ -692,7 +722,7 @@ var CLOSE_TAG = {
692
722
  eol() {
693
723
  },
694
724
  eof(closeTag) {
695
- this.emitError(closeTag, "MALFORMED_CLOSE_TAG", "EOF reached while parsing closing tag");
725
+ this.emitError(closeTag, 15 /* MALFORMED_CLOSE_TAG */, "EOF reached while parsing closing tag");
696
726
  },
697
727
  return() {
698
728
  }
@@ -729,7 +759,7 @@ function ensureExpectedCloseTag(parser, closeTag) {
729
759
  const closeTagNameStart = closeTag.start + 2;
730
760
  const closeTagNameEnd = closeTag.end - 1;
731
761
  if (!activeTag) {
732
- parser.emitError(closeTag, "EXTRA_CLOSING_TAG", 'The closing "' + parser.read({ start: closeTagNameStart, end: closeTagNameEnd }) + '" tag was not expected');
762
+ parser.emitError(closeTag, 0 /* EXTRA_CLOSING_TAG */, 'The closing "' + parser.read({ start: closeTagNameStart, end: closeTagNameEnd }) + '" tag was not expected');
733
763
  return false;
734
764
  }
735
765
  const closeTagNamePos = {
@@ -742,7 +772,7 @@ function ensureExpectedCloseTag(parser, closeTag) {
742
772
  start: activeTag.tagName.start,
743
773
  end: activeTag.shorthandEnd
744
774
  })) {
745
- parser.emitError(closeTag, "MISMATCHED_CLOSING_TAG", 'The closing "' + parser.read(closeTagNamePos) + '" tag does not match the corresponding opening "' + (parser.read(activeTag.tagName) || "div") + '" tag');
775
+ 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');
746
776
  return false;
747
777
  }
748
778
  }
@@ -778,22 +808,18 @@ var CONCISE_HTML_CONTENT = {
778
808
  parentTag = this.activeTag;
779
809
  }
780
810
  if (!parentTag && curIndent) {
781
- this.emitError(this.pos, "BAD_INDENTATION", "Line has extra indentation at the beginning");
811
+ this.emitError(this.pos, 7 /* INVALID_INDENTATION */, "Line has extra indentation at the beginning");
782
812
  return;
783
813
  }
784
814
  if (parentTag) {
785
- if (parentTag.ending !== 0 /* tag */) {
786
- this.emitError(this.pos, "INVALID_BODY", `The "${this.read(parentTag.tagName)}" tag does not allow nested body content`);
787
- return;
788
- }
789
- if (parentTag.bodyMode === 1 /* PARSED_TEXT */ && code !== 45 /* HTML_BLOCK_DELIMITER */) {
790
- this.emitError(this.pos, "ILLEGAL_LINE_START", 'A line within a tag that only allows text content must begin with a "-" character');
815
+ if (parentTag.type === 1 /* text */ && code !== 45 /* HTML_BLOCK_DELIMITER */) {
816
+ this.emitError(this.pos, 8 /* INVALID_LINE_START */, 'A line within a tag that only allows text content must begin with a "-" character');
791
817
  return;
792
818
  }
793
819
  if (parentTag.nestedIndent === void 0) {
794
820
  parentTag.nestedIndent = this.indent;
795
821
  } else if (parentTag.nestedIndent !== this.indent) {
796
- this.emitError(this.pos, "BAD_INDENTATION", "Line indentation does match indentation of previous line");
822
+ this.emitError(this.pos, 7 /* INVALID_INDENTATION */, "Line indentation does match indentation of previous line");
797
823
  return;
798
824
  }
799
825
  }
@@ -815,7 +841,7 @@ var CONCISE_HTML_CONTENT = {
815
841
  this.enterState(states_exports.BEGIN_DELIMITED_HTML_BLOCK);
816
842
  this.pos--;
817
843
  } else {
818
- 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');
844
+ 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');
819
845
  }
820
846
  return;
821
847
  case 47 /* FORWARD_SLASH */:
@@ -829,7 +855,7 @@ var CONCISE_HTML_CONTENT = {
829
855
  this.pos++;
830
856
  return;
831
857
  default:
832
- this.emitError(this.pos, "ILLEGAL_LINE_START", 'A line in concise mode cannot start with "/" unless it starts a "//" or "/*" comment');
858
+ this.emitError(this.pos, 8 /* INVALID_LINE_START */, 'A line in concise mode cannot start with "/" unless it starts a "//" or "/*" comment');
833
859
  return;
834
860
  }
835
861
  }
@@ -847,7 +873,7 @@ var CONCISE_HTML_CONTENT = {
847
873
  this.isConcise = true;
848
874
  switch (child.state) {
849
875
  case states_exports.JS_COMMENT_LINE:
850
- (_b = (_a = this.handlers).onComment) == null ? void 0 : _b.call(_a, {
876
+ (_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
851
877
  start: child.start,
852
878
  end: child.end,
853
879
  value: {
@@ -857,7 +883,7 @@ var CONCISE_HTML_CONTENT = {
857
883
  });
858
884
  break;
859
885
  case states_exports.JS_COMMENT_BLOCK: {
860
- (_d = (_c = this.handlers).onComment) == null ? void 0 : _d.call(_c, {
886
+ (_d = (_c = this.options).onComment) == null ? void 0 : _d.call(_c, {
861
887
  start: child.start,
862
888
  end: child.end,
863
889
  value: {
@@ -866,7 +892,7 @@ var CONCISE_HTML_CONTENT = {
866
892
  }
867
893
  });
868
894
  if (!this.consumeWhitespaceOnLine(0)) {
869
- this.emitError(this.pos, "INVALID_CHARACTER", "In concise mode a javascript comment block can only be followed by whitespace characters and a newline.");
895
+ this.emitError(this.pos, 4 /* INVALID_CHARACTER */, "In concise mode a javascript comment block can only be followed by whitespace characters and a newline.");
870
896
  }
871
897
  break;
872
898
  }
@@ -900,7 +926,7 @@ var DECLARATION = {
900
926
  eol() {
901
927
  },
902
928
  eof(declaration) {
903
- this.emitError(declaration, "MALFORMED_DECLARATION", "EOF reached while parsing declaration");
929
+ this.emitError(declaration, 17 /* MALFORMED_DECLARATION */, "EOF reached while parsing declaration");
904
930
  },
905
931
  return() {
906
932
  }
@@ -909,7 +935,7 @@ function exitDeclaration(parser, declaration, closeOffset) {
909
935
  var _a, _b;
910
936
  parser.pos += closeOffset;
911
937
  parser.exitState();
912
- (_b = (_a = parser.handlers).onDeclaration) == null ? void 0 : _b.call(_a, {
938
+ (_b = (_a = parser.options).onDeclaration) == null ? void 0 : _b.call(_a, {
913
939
  start: declaration.start,
914
940
  end: declaration.end,
915
941
  value: {
@@ -933,7 +959,7 @@ var DTD = {
933
959
  },
934
960
  exit(documentType) {
935
961
  var _a, _b;
936
- (_b = (_a = this.handlers).onDoctype) == null ? void 0 : _b.call(_a, {
962
+ (_b = (_a = this.options).onDoctype) == null ? void 0 : _b.call(_a, {
937
963
  start: documentType.start,
938
964
  end: documentType.end,
939
965
  value: {
@@ -951,7 +977,7 @@ var DTD = {
951
977
  eol() {
952
978
  },
953
979
  eof(documentType) {
954
- this.emitError(documentType, "MALFORMED_DOCUMENT_TYPE", "EOF reached while parsing document type");
980
+ this.emitError(documentType, 18 /* MALFORMED_DOCUMENT_TYPE */, "EOF reached while parsing document type");
955
981
  },
956
982
  return() {
957
983
  }
@@ -1031,11 +1057,11 @@ var EXPRESSION = {
1031
1057
  case 93 /* CLOSE_SQUARE_BRACKET */:
1032
1058
  case 125 /* CLOSE_CURLY_BRACE */: {
1033
1059
  if (!expression.groupStack.length) {
1034
- 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.');
1060
+ 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.');
1035
1061
  }
1036
1062
  const expectedCode = expression.groupStack.pop();
1037
1063
  if (expectedCode !== code) {
1038
- return this.emitError(expression, "INVALID_EXPRESSION", 'Mismatched group. A "' + String.fromCharCode(code) + '" character was found when "' + String.fromCharCode(expectedCode) + '" was expected.');
1064
+ return this.emitError(expression, 6 /* INVALID_EXPRESSION */, 'Mismatched group. A "' + String.fromCharCode(code) + '" character was found when "' + String.fromCharCode(expectedCode) + '" was expected.');
1039
1065
  }
1040
1066
  break;
1041
1067
  }
@@ -1043,11 +1069,7 @@ var EXPRESSION = {
1043
1069
  },
1044
1070
  eol(_, expression) {
1045
1071
  if (!expression.groupStack.length && (expression.terminatedByWhitespace || expression.terminatedByEOL)) {
1046
- if (checkForOperators(this, expression)) {
1047
- this.forward = 1;
1048
- } else {
1049
- this.exitState();
1050
- }
1072
+ this.exitState();
1051
1073
  }
1052
1074
  },
1053
1075
  eof(expression) {
@@ -1059,16 +1081,16 @@ var EXPRESSION = {
1059
1081
  case states_exports.ATTRIBUTE: {
1060
1082
  const attr = parent;
1061
1083
  if (!attr.spread && !attr.name) {
1062
- return this.emitError(expression, "MALFORMED_OPEN_TAG", 'EOF reached while parsing attribute name for the "' + this.read(this.activeTag.tagName) + '" tag');
1084
+ return this.emitError(expression, 19 /* MALFORMED_OPEN_TAG */, 'EOF reached while parsing attribute name for the "' + this.read(this.activeTag.tagName) + '" tag');
1063
1085
  }
1064
- 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`);
1086
+ 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`);
1065
1087
  }
1066
1088
  case states_exports.TAG_NAME:
1067
- return this.emitError(expression, "MALFORMED_OPEN_TAG", "EOF reached while parsing tag name");
1089
+ return this.emitError(expression, 19 /* MALFORMED_OPEN_TAG */, "EOF reached while parsing tag name");
1068
1090
  case states_exports.PLACEHOLDER:
1069
- return this.emitError(expression, "MALFORMED_PLACEHOLDER", "EOF reached while parsing placeholder");
1091
+ return this.emitError(expression, 20 /* MALFORMED_PLACEHOLDER */, "EOF reached while parsing placeholder");
1070
1092
  }
1071
- return this.emitError(expression, "INVALID_EXPRESSION", "EOF reached while parsing expression");
1093
+ return this.emitError(expression, 6 /* INVALID_EXPRESSION */, "EOF reached while parsing expression");
1072
1094
  }
1073
1095
  },
1074
1096
  return() {
@@ -1136,7 +1158,7 @@ var HTML_COMMENT = {
1136
1158
  },
1137
1159
  exit(comment) {
1138
1160
  var _a, _b;
1139
- (_b = (_a = this.handlers).onComment) == null ? void 0 : _b.call(_a, {
1161
+ (_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
1140
1162
  start: comment.start,
1141
1163
  end: comment.end,
1142
1164
  value: {
@@ -1160,7 +1182,7 @@ var HTML_COMMENT = {
1160
1182
  eol() {
1161
1183
  },
1162
1184
  eof(comment) {
1163
- this.emitError(comment, "MALFORMED_COMMENT", "EOF reached while parsing comment");
1185
+ this.emitError(comment, 16 /* MALFORMED_COMMENT */, "EOF reached while parsing comment");
1164
1186
  },
1165
1187
  return() {
1166
1188
  }
@@ -1266,7 +1288,7 @@ var INLINE_SCRIPT = {
1266
1288
  },
1267
1289
  exit(inlineScript) {
1268
1290
  var _a, _b;
1269
- (_b = (_a = this.handlers).onScriptlet) == null ? void 0 : _b.call(_a, {
1291
+ (_b = (_a = this.options).onScriptlet) == null ? void 0 : _b.call(_a, {
1270
1292
  start: inlineScript.start,
1271
1293
  end: inlineScript.end,
1272
1294
  block: inlineScript.block,
@@ -1325,7 +1347,7 @@ var JS_COMMENT_BLOCK = {
1325
1347
  eol() {
1326
1348
  },
1327
1349
  eof(comment) {
1328
- this.emitError(comment, "MALFORMED_COMMENT", "EOF reached while parsing multi-line JavaScript comment");
1350
+ this.emitError(comment, 16 /* MALFORMED_COMMENT */, "EOF reached while parsing multi-line JavaScript comment");
1329
1351
  },
1330
1352
  return() {
1331
1353
  }
@@ -1346,7 +1368,7 @@ var JS_COMMENT_LINE = {
1346
1368
  },
1347
1369
  char(code) {
1348
1370
  var _a;
1349
- if (!this.isConcise && code === 60 /* OPEN_ANGLE_BRACKET */ && ((_a = this.activeTag) == null ? void 0 : _a.bodyMode) === 1 /* PARSED_TEXT */) {
1371
+ if (!this.isConcise && code === 60 /* OPEN_ANGLE_BRACKET */ && ((_a = this.activeTag) == null ? void 0 : _a.type) === 1 /* text */) {
1350
1372
  states_exports.checkForClosingTag(this);
1351
1373
  }
1352
1374
  },
@@ -1430,7 +1452,7 @@ var PLACEHOLDER = {
1430
1452
  },
1431
1453
  exit(placeholder) {
1432
1454
  var _a, _b;
1433
- (_b = (_a = this.handlers).onPlaceholder) == null ? void 0 : _b.call(_a, {
1455
+ (_b = (_a = this.options).onPlaceholder) == null ? void 0 : _b.call(_a, {
1434
1456
  start: placeholder.start,
1435
1457
  end: placeholder.end,
1436
1458
  escape: placeholder.escape,
@@ -1448,7 +1470,7 @@ var PLACEHOLDER = {
1448
1470
  },
1449
1471
  return(child) {
1450
1472
  if (child.start === child.end) {
1451
- this.emitError(child, "PLACEHOLDER_EXPRESSION_REQUIRED", "Invalid placeholder, the expression cannot be missing");
1473
+ this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
1452
1474
  }
1453
1475
  this.pos++;
1454
1476
  this.exitState();
@@ -1522,10 +1544,10 @@ var REGULAR_EXPRESSION = {
1522
1544
  }
1523
1545
  },
1524
1546
  eol(_, regExp) {
1525
- this.emitError(regExp, "INVALID_REGULAR_EXPRESSION", "EOL reached while parsing regular expression");
1547
+ this.emitError(regExp, 9 /* INVALID_REGULAR_EXPRESSION */, "EOL reached while parsing regular expression");
1526
1548
  },
1527
1549
  eof(regExp) {
1528
- this.emitError(regExp, "INVALID_REGULAR_EXPRESSION", "EOF reached while parsing regular expression");
1550
+ this.emitError(regExp, 9 /* INVALID_REGULAR_EXPRESSION */, "EOF reached while parsing regular expression");
1529
1551
  },
1530
1552
  return() {
1531
1553
  }
@@ -1559,30 +1581,13 @@ var STRING = {
1559
1581
  eol() {
1560
1582
  },
1561
1583
  eof(string) {
1562
- this.emitError(string, "INVALID_STRING", "EOF reached while parsing string expression");
1584
+ this.emitError(string, 10 /* INVALID_STRING */, "EOF reached while parsing string expression");
1563
1585
  },
1564
1586
  return() {
1565
1587
  }
1566
1588
  };
1567
1589
 
1568
1590
  // src/states/TAG_NAME.ts
1569
- var VOID_TAGS = [
1570
- "area",
1571
- "base",
1572
- "br",
1573
- "col",
1574
- "hr",
1575
- "embed",
1576
- "img",
1577
- "input",
1578
- "link",
1579
- "meta",
1580
- "param",
1581
- "source",
1582
- "track",
1583
- "wbr"
1584
- ];
1585
- var CODE_TAGS = ["import", "export", "static", "class"];
1586
1591
  var TAG_NAME = {
1587
1592
  name: "TAG_NAME",
1588
1593
  enter(parent, start) {
@@ -1604,10 +1609,10 @@ var TAG_NAME = {
1604
1609
  switch (tagName.shorthandCode) {
1605
1610
  case 35 /* NUMBER_SIGN */:
1606
1611
  if (this.activeTag.hasShorthandId) {
1607
- return this.emitError(tagName, "INVALID_TAG_SHORTHAND", "Multiple shorthand ID parts are not allowed on the same tag");
1612
+ return this.emitError(tagName, 12 /* INVALID_TAG_SHORTHAND */, "Multiple shorthand ID parts are not allowed on the same tag");
1608
1613
  }
1609
1614
  this.activeTag.hasShorthandId = true;
1610
- (_b = (_a = this.handlers).onTagShorthandId) == null ? void 0 : _b.call(_a, {
1615
+ (_b = (_a = this.options).onTagShorthandId) == null ? void 0 : _b.call(_a, {
1611
1616
  start,
1612
1617
  end,
1613
1618
  quasis,
@@ -1615,7 +1620,7 @@ var TAG_NAME = {
1615
1620
  });
1616
1621
  break;
1617
1622
  case 46 /* PERIOD */:
1618
- (_d = (_c = this.handlers).onTagShorthandClass) == null ? void 0 : _d.call(_c, {
1623
+ (_d = (_c = this.options).onTagShorthandClass) == null ? void 0 : _d.call(_c, {
1619
1624
  start,
1620
1625
  end,
1621
1626
  quasis,
@@ -1624,28 +1629,26 @@ var TAG_NAME = {
1624
1629
  break;
1625
1630
  default: {
1626
1631
  const tag = this.activeTag;
1632
+ const tagType = (_f = (_e = this.options).onTagName) == null ? void 0 : _f.call(_e, {
1633
+ start,
1634
+ end,
1635
+ quasis,
1636
+ expressions,
1637
+ concise: this.isConcise
1638
+ });
1627
1639
  tag.tagName = tagName;
1628
- if (tagName.expressions.length === 0) {
1629
- if (this.matchAnyAtPos(tagName, VOID_TAGS)) {
1630
- tag.ending |= 2 /* void */;
1631
- } else if (this.matchAnyAtPos(tagName, CODE_TAGS)) {
1640
+ if (tagType) {
1641
+ tag.type = tagType;
1642
+ if (tagType === 3 /* statement */) {
1632
1643
  if (!tag.concise) {
1633
- return this.emitError(tagName, "RESERVED_TAG_NAME", `The "${this.read(tagName)}" tag is reserved and cannot be used as an HTML tag.`);
1644
+ return this.emitError(tagName, 24 /* RESERVED_TAG_NAME */, `The "${this.read(tagName)}" tag is reserved and cannot be used as an HTML tag.`);
1634
1645
  }
1635
1646
  if (tag.parentTag) {
1636
- return this.emitError(tagName, "ROOT_TAG_ONLY", `"${this.read(tagName)}" can only be used at the root of the template.`);
1647
+ return this.emitError(tagName, 25 /* ROOT_TAG_ONLY */, `"${this.read(tagName)}" can only be used at the root of the template.`);
1637
1648
  }
1638
- tag.ending |= 4 /* code */;
1639
1649
  this.enterState(states_exports.EXPRESSION).terminatedByEOL = true;
1640
1650
  }
1641
1651
  }
1642
- (_f = (_e = this.handlers).onTagName) == null ? void 0 : _f.call(_e, {
1643
- start,
1644
- end,
1645
- quasis,
1646
- expressions,
1647
- concise: this.isConcise
1648
- });
1649
1652
  break;
1650
1653
  }
1651
1654
  }
@@ -1676,12 +1679,12 @@ var TAG_NAME = {
1676
1679
  if (child.terminatedByEOL)
1677
1680
  return;
1678
1681
  if (child.start === child.end) {
1679
- this.emitError(child, "PLACEHOLDER_EXPRESSION_REQUIRED", "Invalid placeholder, the expression cannot be missing");
1682
+ this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
1680
1683
  }
1681
1684
  const { quasis, expressions } = tagName;
1682
1685
  const start = child.start - 2;
1683
1686
  const end = ++this.pos;
1684
- const nextStart = end + 1;
1687
+ const nextStart = end;
1685
1688
  expressions.push({
1686
1689
  start,
1687
1690
  end,
@@ -1724,20 +1727,19 @@ var TEMPLATE_STRING = {
1724
1727
  }
1725
1728
  },
1726
1729
  eof(templateString) {
1727
- this.emitError(templateString, "INVALID_TEMPLATE_STRING", "EOF reached while parsing template string expression");
1730
+ this.emitError(templateString, 13 /* INVALID_TEMPLATE_STRING */, "EOF reached while parsing template string expression");
1728
1731
  },
1729
1732
  eol() {
1730
1733
  },
1731
1734
  return(child) {
1732
1735
  if (child.start === child.end) {
1733
- this.emitError(child, "PLACEHOLDER_EXPRESSION_REQUIRED", "Invalid placeholder, the expression cannot be missing");
1736
+ this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
1734
1737
  }
1735
1738
  this.pos++;
1736
1739
  }
1737
1740
  };
1738
1741
 
1739
1742
  // src/states/OPEN_TAG.ts
1740
- var PARSED_TEXT_TAGS = ["script", "style", "textarea", "html-comment"];
1741
1743
  var CONCISE_TAG_VAR_TERMINATORS = [
1742
1744
  59 /* SEMICOLON */,
1743
1745
  40 /* OPEN_PAREN */,
@@ -1758,6 +1760,7 @@ var OPEN_TAG = {
1758
1760
  enter(parent, start) {
1759
1761
  const tag = this.activeTag = {
1760
1762
  state: OPEN_TAG,
1763
+ type: 0 /* html */,
1761
1764
  parent,
1762
1765
  start,
1763
1766
  end: start,
@@ -1768,11 +1771,10 @@ var OPEN_TAG = {
1768
1771
  hasShorthandId: false,
1769
1772
  hasArgs: false,
1770
1773
  hasAttrs: false,
1774
+ selfClosed: false,
1771
1775
  shorthandEnd: -1,
1772
1776
  tagName: void 0,
1773
- ending: 0 /* tag */,
1774
1777
  concise: this.isConcise,
1775
- bodyMode: 0 /* HTML */,
1776
1778
  beginMixedMode: this.beginMixedMode || this.endingMixedModeAtEOL
1777
1779
  };
1778
1780
  this.beginMixedMode = false;
@@ -1782,21 +1784,27 @@ var OPEN_TAG = {
1782
1784
  },
1783
1785
  exit(tag) {
1784
1786
  var _a, _b;
1785
- const { tagName, ending } = tag;
1786
- (_b = (_a = this.handlers).onOpenTagEnd) == null ? void 0 : _b.call(_a, {
1787
- start: this.pos - (this.isConcise ? 0 : ending & 1 /* self */ ? 2 : 1),
1787
+ const { selfClosed } = tag;
1788
+ (_b = (_a = this.options).onOpenTagEnd) == null ? void 0 : _b.call(_a, {
1789
+ start: this.pos - (this.isConcise ? 0 : selfClosed ? 2 : 1),
1788
1790
  end: this.pos,
1789
- ending
1791
+ selfClosed
1790
1792
  });
1791
- if (!this.isConcise && ending !== 0 /* tag */) {
1792
- this.closeTag(this.pos, this.pos, void 0);
1793
- } else if (tagName.expressions.length === 0 && this.matchAnyAtPos(tagName, PARSED_TEXT_TAGS)) {
1794
- tag.bodyMode = 1 /* PARSED_TEXT */;
1795
- if (this.isConcise) {
1796
- this.enterState(states_exports.CONCISE_HTML_CONTENT);
1797
- } else {
1798
- this.enterState(states_exports.PARSED_TEXT_CONTENT);
1793
+ switch (selfClosed ? 2 /* void */ : tag.type) {
1794
+ case 2 /* void */:
1795
+ case 3 /* statement */: {
1796
+ if (tag.beginMixedMode)
1797
+ this.endingMixedModeAtEOL = true;
1798
+ this.activeTag = tag.parentTag;
1799
+ break;
1799
1800
  }
1801
+ case 1 /* text */:
1802
+ if (this.isConcise) {
1803
+ this.enterState(states_exports.CONCISE_HTML_CONTENT);
1804
+ } else {
1805
+ this.enterState(states_exports.PARSED_TEXT_CONTENT);
1806
+ }
1807
+ break;
1800
1808
  }
1801
1809
  },
1802
1810
  eol(_, tag) {
@@ -1807,12 +1815,12 @@ var OPEN_TAG = {
1807
1815
  eof(tag) {
1808
1816
  if (this.isConcise) {
1809
1817
  if (tag.stage === 4 /* ATTR_GROUP */) {
1810
- this.emitError(tag, "MALFORMED_OPEN_TAG", 'EOF reached while within an attribute group (e.g. "[ ... ]").');
1818
+ this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, 'EOF reached while within an attribute group (e.g. "[ ... ]").');
1811
1819
  return;
1812
1820
  }
1813
1821
  this.exitState();
1814
1822
  } else {
1815
- this.emitError(tag, "MALFORMED_OPEN_TAG", "EOF reached while parsing open tag");
1823
+ this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, "EOF reached while parsing open tag");
1816
1824
  }
1817
1825
  },
1818
1826
  char(code, tag) {
@@ -1842,17 +1850,17 @@ var OPEN_TAG = {
1842
1850
  }
1843
1851
  break;
1844
1852
  }
1845
- this.emitError(this.pos, "INVALID_CODE_AFTER_SEMICOLON", "A semicolon indicates the end of a line. Only comments may follow it.");
1853
+ this.emitError(this.pos, 5 /* INVALID_CODE_AFTER_SEMICOLON */, "A semicolon indicates the end of a line. Only comments may follow it.");
1846
1854
  }
1847
1855
  return;
1848
1856
  }
1849
1857
  if (code === 45 /* HTML_BLOCK_DELIMITER */) {
1850
1858
  if (this.lookAtCharCodeAhead(1) !== 45 /* HTML_BLOCK_DELIMITER */) {
1851
- this.emitError(tag, "MALFORMED_OPEN_TAG", '"-" not allowed as first character of attribute name');
1859
+ this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, '"-" not allowed as first character of attribute name');
1852
1860
  return;
1853
1861
  }
1854
1862
  if (tag.stage === 4 /* ATTR_GROUP */) {
1855
- this.emitError(this.pos, "MALFORMED_OPEN_TAG", "Attribute group was not properly ended");
1863
+ this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, "Attribute group was not properly ended");
1856
1864
  return;
1857
1865
  }
1858
1866
  this.exitState();
@@ -1877,14 +1885,14 @@ var OPEN_TAG = {
1877
1885
  return;
1878
1886
  } else if (code === 91 /* OPEN_SQUARE_BRACKET */) {
1879
1887
  if (tag.stage === 4 /* ATTR_GROUP */) {
1880
- this.emitError(this.pos, "MALFORMED_OPEN_TAG", 'Unexpected "[" character within open tag.');
1888
+ this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, 'Unexpected "[" character within open tag.');
1881
1889
  return;
1882
1890
  }
1883
1891
  tag.stage = 4 /* ATTR_GROUP */;
1884
1892
  return;
1885
1893
  } else if (code === 93 /* CLOSE_SQUARE_BRACKET */) {
1886
1894
  if (tag.stage !== 4 /* ATTR_GROUP */) {
1887
- this.emitError(this.pos, "MALFORMED_OPEN_TAG", 'Unexpected "]" character within open tag.');
1895
+ this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, 'Unexpected "]" character within open tag.');
1888
1896
  return;
1889
1897
  }
1890
1898
  tag.stage = 0 /* UNKNOWN */;
@@ -1895,13 +1903,13 @@ var OPEN_TAG = {
1895
1903
  this.exitState();
1896
1904
  return;
1897
1905
  } else if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 62 /* CLOSE_ANGLE_BRACKET */) {
1898
- tag.ending |= 1 /* self */;
1906
+ tag.selfClosed = true;
1899
1907
  this.pos += 2;
1900
1908
  this.exitState();
1901
1909
  return;
1902
1910
  }
1903
1911
  if (code === 60 /* OPEN_ANGLE_BRACKET */) {
1904
- return this.emitError(this.pos, "ILLEGAL_ATTRIBUTE_NAME", 'Invalid attribute name. Attribute name cannot begin with the "<" character.');
1912
+ return this.emitError(this.pos, 2 /* INVALID_ATTRIBUTE_NAME */, 'Invalid attribute name. Attribute name cannot begin with the "<" character.');
1905
1913
  }
1906
1914
  if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 42 /* ASTERISK */) {
1907
1915
  this.enterState(states_exports.JS_COMMENT_BLOCK);
@@ -1923,7 +1931,7 @@ var OPEN_TAG = {
1923
1931
  this.pos--;
1924
1932
  } else if (code === 40 /* OPEN_PAREN */ && !tag.hasAttrs) {
1925
1933
  if (tag.hasArgs) {
1926
- this.emitError(this.pos, "ILLEGAL_TAG_ARGUMENT", "A tag can only have one argument");
1934
+ this.emitError(this.pos, 11 /* INVALID_TAG_ARGUMENT */, "A tag can only have one argument");
1927
1935
  return;
1928
1936
  }
1929
1937
  tag.stage = 2 /* ARGUMENT */;
@@ -1959,9 +1967,9 @@ var OPEN_TAG = {
1959
1967
  switch (tag.stage) {
1960
1968
  case 1 /* VAR */: {
1961
1969
  if (child.start === child.end) {
1962
- return this.emitError(child, "MISSING_TAG_VARIABLE", "A slash was found that was not followed by a variable name or lhs expression");
1970
+ return this.emitError(child, 23 /* MISSING_TAG_VARIABLE */, "A slash was found that was not followed by a variable name or lhs expression");
1963
1971
  }
1964
- (_b = (_a = this.handlers).onTagVar) == null ? void 0 : _b.call(_a, {
1972
+ (_b = (_a = this.options).onTagVar) == null ? void 0 : _b.call(_a, {
1965
1973
  start: child.start - 1,
1966
1974
  end: child.end,
1967
1975
  value: {
@@ -1986,7 +1994,7 @@ var OPEN_TAG = {
1986
1994
  this.pos--;
1987
1995
  } else {
1988
1996
  tag.hasArgs = true;
1989
- (_d = (_c = this.handlers).onTagArgs) == null ? void 0 : _d.call(_c, {
1997
+ (_d = (_c = this.options).onTagArgs) == null ? void 0 : _d.call(_c, {
1990
1998
  start,
1991
1999
  end,
1992
2000
  value
@@ -1996,7 +2004,7 @@ var OPEN_TAG = {
1996
2004
  }
1997
2005
  case 3 /* PARAMS */: {
1998
2006
  const end = ++this.pos;
1999
- (_f = (_e = this.handlers).onTagParams) == null ? void 0 : _f.call(_e, {
2007
+ (_f = (_e = this.options).onTagParams) == null ? void 0 : _f.call(_e, {
2000
2008
  start: child.start - 1,
2001
2009
  end,
2002
2010
  value: {
@@ -2023,8 +2031,8 @@ function createParser(handlers) {
2023
2031
  read(range) {
2024
2032
  return parser.read(range);
2025
2033
  },
2026
- positionAt(index) {
2027
- return parser.positionAt(index);
2034
+ positionAt(offset) {
2035
+ return parser.positionAt(offset);
2028
2036
  },
2029
2037
  locationAt(range) {
2030
2038
  return parser.locationAt(range);
@@ -2033,6 +2041,7 @@ function createParser(handlers) {
2033
2041
  }
2034
2042
  // Annotate the CommonJS export names for ESM import in node:
2035
2043
  0 && (module.exports = {
2036
- OpenTagEnding,
2044
+ ErrorCode,
2045
+ TagType,
2037
2046
  createParser
2038
2047
  });