htmljs-parser 3.2.0 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -5,6 +5,35 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/util/constants.ts
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 || {});
8
37
  var TagType = /* @__PURE__ */ ((TagType2) => {
9
38
  TagType2[TagType2["html"] = 0] = "html";
10
39
  TagType2[TagType2["text"] = 1] = "text";
@@ -53,7 +82,7 @@ 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
  }
@@ -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) {
@@ -439,7 +468,7 @@ var ATTRIBUTE = {
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;
@@ -486,7 +515,7 @@ 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
521
  (_h = (_g = this.options).onAttrSpread) == null ? void 0 : _h.call(_g, {
@@ -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();
@@ -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,18 +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
794
  if (parentTag.type === 1 /* text */ && code !== 45 /* HTML_BLOCK_DELIMITER */) {
766
- this.emitError(this.pos, "ILLEGAL_LINE_START", 'A line within a tag that only allows text content must begin with a "-" character');
795
+ this.emitError(this.pos, 8 /* INVALID_LINE_START */, 'A line within a tag that only allows text content must begin with a "-" character');
767
796
  return;
768
797
  }
769
798
  if (parentTag.nestedIndent === void 0) {
770
799
  parentTag.nestedIndent = this.indent;
771
800
  } else if (parentTag.nestedIndent !== this.indent) {
772
- 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");
773
802
  return;
774
803
  }
775
804
  }
@@ -791,7 +820,7 @@ var CONCISE_HTML_CONTENT = {
791
820
  this.enterState(states_exports.BEGIN_DELIMITED_HTML_BLOCK);
792
821
  this.pos--;
793
822
  } else {
794
- 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');
795
824
  }
796
825
  return;
797
826
  case 47 /* FORWARD_SLASH */:
@@ -805,7 +834,7 @@ var CONCISE_HTML_CONTENT = {
805
834
  this.pos++;
806
835
  return;
807
836
  default:
808
- 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');
809
838
  return;
810
839
  }
811
840
  }
@@ -842,7 +871,7 @@ var CONCISE_HTML_CONTENT = {
842
871
  }
843
872
  });
844
873
  if (!this.consumeWhitespaceOnLine(0)) {
845
- 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.");
846
875
  }
847
876
  break;
848
877
  }
@@ -876,7 +905,7 @@ var DECLARATION = {
876
905
  eol() {
877
906
  },
878
907
  eof(declaration) {
879
- this.emitError(declaration, "MALFORMED_DECLARATION", "EOF reached while parsing declaration");
908
+ this.emitError(declaration, 17 /* MALFORMED_DECLARATION */, "EOF reached while parsing declaration");
880
909
  },
881
910
  return() {
882
911
  }
@@ -927,7 +956,7 @@ var DTD = {
927
956
  eol() {
928
957
  },
929
958
  eof(documentType) {
930
- 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");
931
960
  },
932
961
  return() {
933
962
  }
@@ -1007,11 +1036,11 @@ var EXPRESSION = {
1007
1036
  case 93 /* CLOSE_SQUARE_BRACKET */:
1008
1037
  case 125 /* CLOSE_CURLY_BRACE */: {
1009
1038
  if (!expression.groupStack.length) {
1010
- 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.');
1011
1040
  }
1012
1041
  const expectedCode = expression.groupStack.pop();
1013
1042
  if (expectedCode !== code) {
1014
- 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.');
1015
1044
  }
1016
1045
  break;
1017
1046
  }
@@ -1019,11 +1048,10 @@ var EXPRESSION = {
1019
1048
  },
1020
1049
  eol(_, expression) {
1021
1050
  if (!expression.groupStack.length && (expression.terminatedByWhitespace || expression.terminatedByEOL)) {
1022
- if (checkForOperators(this, expression)) {
1051
+ if (checkForOperators(this, expression))
1023
1052
  this.forward = 1;
1024
- } else {
1053
+ else
1025
1054
  this.exitState();
1026
- }
1027
1055
  }
1028
1056
  },
1029
1057
  eof(expression) {
@@ -1035,16 +1063,16 @@ var EXPRESSION = {
1035
1063
  case states_exports.ATTRIBUTE: {
1036
1064
  const attr = parent;
1037
1065
  if (!attr.spread && !attr.name) {
1038
- return this.emitError(expression, "MALFORMED_OPEN_TAG", 'EOF reached while parsing attribute name for the "' + this.read(this.activeTag.tagName) + '" tag');
1066
+ return this.emitError(expression, 19 /* MALFORMED_OPEN_TAG */, 'EOF reached while parsing attribute name for the "' + this.read(this.activeTag.tagName) + '" tag');
1039
1067
  }
1040
- 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`);
1068
+ 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`);
1041
1069
  }
1042
1070
  case states_exports.TAG_NAME:
1043
- return this.emitError(expression, "MALFORMED_OPEN_TAG", "EOF reached while parsing tag name");
1071
+ return this.emitError(expression, 19 /* MALFORMED_OPEN_TAG */, "EOF reached while parsing tag name");
1044
1072
  case states_exports.PLACEHOLDER:
1045
- return this.emitError(expression, "MALFORMED_PLACEHOLDER", "EOF reached while parsing placeholder");
1073
+ return this.emitError(expression, 20 /* MALFORMED_PLACEHOLDER */, "EOF reached while parsing placeholder");
1046
1074
  }
1047
- return this.emitError(expression, "INVALID_EXPRESSION", "EOF reached while parsing expression");
1075
+ return this.emitError(expression, 6 /* INVALID_EXPRESSION */, "EOF reached while parsing expression");
1048
1076
  }
1049
1077
  },
1050
1078
  return() {
@@ -1061,7 +1089,7 @@ function checkForOperators(parser, expression) {
1061
1089
  if (expression.skipOperators) {
1062
1090
  return false;
1063
1091
  }
1064
- const pattern = parser.isConcise ? conciseOperatorPattern : htmlOperatorPattern;
1092
+ const pattern = parser.isConcise || expression.terminatedByEOL ? conciseOperatorPattern : htmlOperatorPattern;
1065
1093
  pattern.lastIndex = parser.pos;
1066
1094
  const matches = pattern.exec(parser.data);
1067
1095
  if (matches) {
@@ -1136,7 +1164,7 @@ var HTML_COMMENT = {
1136
1164
  eol() {
1137
1165
  },
1138
1166
  eof(comment) {
1139
- this.emitError(comment, "MALFORMED_COMMENT", "EOF reached while parsing comment");
1167
+ this.emitError(comment, 16 /* MALFORMED_COMMENT */, "EOF reached while parsing comment");
1140
1168
  },
1141
1169
  return() {
1142
1170
  }
@@ -1301,7 +1329,7 @@ var JS_COMMENT_BLOCK = {
1301
1329
  eol() {
1302
1330
  },
1303
1331
  eof(comment) {
1304
- this.emitError(comment, "MALFORMED_COMMENT", "EOF reached while parsing multi-line JavaScript comment");
1332
+ this.emitError(comment, 16 /* MALFORMED_COMMENT */, "EOF reached while parsing multi-line JavaScript comment");
1305
1333
  },
1306
1334
  return() {
1307
1335
  }
@@ -1424,7 +1452,7 @@ var PLACEHOLDER = {
1424
1452
  },
1425
1453
  return(child) {
1426
1454
  if (child.start === child.end) {
1427
- this.emitError(child, "PLACEHOLDER_EXPRESSION_REQUIRED", "Invalid placeholder, the expression cannot be missing");
1455
+ this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
1428
1456
  }
1429
1457
  this.pos++;
1430
1458
  this.exitState();
@@ -1498,10 +1526,10 @@ var REGULAR_EXPRESSION = {
1498
1526
  }
1499
1527
  },
1500
1528
  eol(_, regExp) {
1501
- this.emitError(regExp, "INVALID_REGULAR_EXPRESSION", "EOL reached while parsing regular expression");
1529
+ this.emitError(regExp, 9 /* INVALID_REGULAR_EXPRESSION */, "EOL reached while parsing regular expression");
1502
1530
  },
1503
1531
  eof(regExp) {
1504
- this.emitError(regExp, "INVALID_REGULAR_EXPRESSION", "EOF reached while parsing regular expression");
1532
+ this.emitError(regExp, 9 /* INVALID_REGULAR_EXPRESSION */, "EOF reached while parsing regular expression");
1505
1533
  },
1506
1534
  return() {
1507
1535
  }
@@ -1535,7 +1563,7 @@ var STRING = {
1535
1563
  eol() {
1536
1564
  },
1537
1565
  eof(string) {
1538
- this.emitError(string, "INVALID_STRING", "EOF reached while parsing string expression");
1566
+ this.emitError(string, 10 /* INVALID_STRING */, "EOF reached while parsing string expression");
1539
1567
  },
1540
1568
  return() {
1541
1569
  }
@@ -1563,7 +1591,7 @@ var TAG_NAME = {
1563
1591
  switch (tagName.shorthandCode) {
1564
1592
  case 35 /* NUMBER_SIGN */:
1565
1593
  if (this.activeTag.hasShorthandId) {
1566
- return this.emitError(tagName, "INVALID_TAG_SHORTHAND", "Multiple shorthand ID parts are not allowed on the same tag");
1594
+ return this.emitError(tagName, 12 /* INVALID_TAG_SHORTHAND */, "Multiple shorthand ID parts are not allowed on the same tag");
1567
1595
  }
1568
1596
  this.activeTag.hasShorthandId = true;
1569
1597
  (_b = (_a = this.options).onTagShorthandId) == null ? void 0 : _b.call(_a, {
@@ -1595,10 +1623,10 @@ var TAG_NAME = {
1595
1623
  tag.type = tagType;
1596
1624
  if (tagType === 3 /* statement */) {
1597
1625
  if (!tag.concise) {
1598
- return this.emitError(tagName, "RESERVED_TAG_NAME", `The "${this.read(tagName)}" tag is reserved and cannot be used as an HTML tag.`);
1626
+ return this.emitError(tagName, 24 /* RESERVED_TAG_NAME */, `The "${this.read(tagName)}" tag is reserved and cannot be used as an HTML tag.`);
1599
1627
  }
1600
1628
  if (tag.parentTag) {
1601
- return this.emitError(tagName, "ROOT_TAG_ONLY", `"${this.read(tagName)}" can only be used at the root of the template.`);
1629
+ return this.emitError(tagName, 25 /* ROOT_TAG_ONLY */, `"${this.read(tagName)}" can only be used at the root of the template.`);
1602
1630
  }
1603
1631
  this.enterState(states_exports.EXPRESSION).terminatedByEOL = true;
1604
1632
  }
@@ -1633,12 +1661,12 @@ var TAG_NAME = {
1633
1661
  if (child.terminatedByEOL)
1634
1662
  return;
1635
1663
  if (child.start === child.end) {
1636
- this.emitError(child, "PLACEHOLDER_EXPRESSION_REQUIRED", "Invalid placeholder, the expression cannot be missing");
1664
+ this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
1637
1665
  }
1638
1666
  const { quasis, expressions } = tagName;
1639
1667
  const start = child.start - 2;
1640
1668
  const end = ++this.pos;
1641
- const nextStart = end + 1;
1669
+ const nextStart = end;
1642
1670
  expressions.push({
1643
1671
  start,
1644
1672
  end,
@@ -1681,13 +1709,13 @@ var TEMPLATE_STRING = {
1681
1709
  }
1682
1710
  },
1683
1711
  eof(templateString) {
1684
- this.emitError(templateString, "INVALID_TEMPLATE_STRING", "EOF reached while parsing template string expression");
1712
+ this.emitError(templateString, 13 /* INVALID_TEMPLATE_STRING */, "EOF reached while parsing template string expression");
1685
1713
  },
1686
1714
  eol() {
1687
1715
  },
1688
1716
  return(child) {
1689
1717
  if (child.start === child.end) {
1690
- this.emitError(child, "PLACEHOLDER_EXPRESSION_REQUIRED", "Invalid placeholder, the expression cannot be missing");
1718
+ this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
1691
1719
  }
1692
1720
  this.pos++;
1693
1721
  }
@@ -1769,12 +1797,12 @@ var OPEN_TAG = {
1769
1797
  eof(tag) {
1770
1798
  if (this.isConcise) {
1771
1799
  if (tag.stage === 4 /* ATTR_GROUP */) {
1772
- this.emitError(tag, "MALFORMED_OPEN_TAG", 'EOF reached while within an attribute group (e.g. "[ ... ]").');
1800
+ this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, 'EOF reached while within an attribute group (e.g. "[ ... ]").');
1773
1801
  return;
1774
1802
  }
1775
1803
  this.exitState();
1776
1804
  } else {
1777
- this.emitError(tag, "MALFORMED_OPEN_TAG", "EOF reached while parsing open tag");
1805
+ this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, "EOF reached while parsing open tag");
1778
1806
  }
1779
1807
  },
1780
1808
  char(code, tag) {
@@ -1804,17 +1832,17 @@ var OPEN_TAG = {
1804
1832
  }
1805
1833
  break;
1806
1834
  }
1807
- this.emitError(this.pos, "INVALID_CODE_AFTER_SEMICOLON", "A semicolon indicates the end of a line. Only comments may follow it.");
1835
+ this.emitError(this.pos, 5 /* INVALID_CODE_AFTER_SEMICOLON */, "A semicolon indicates the end of a line. Only comments may follow it.");
1808
1836
  }
1809
1837
  return;
1810
1838
  }
1811
1839
  if (code === 45 /* HTML_BLOCK_DELIMITER */) {
1812
1840
  if (this.lookAtCharCodeAhead(1) !== 45 /* HTML_BLOCK_DELIMITER */) {
1813
- this.emitError(tag, "MALFORMED_OPEN_TAG", '"-" not allowed as first character of attribute name');
1841
+ this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, '"-" not allowed as first character of attribute name');
1814
1842
  return;
1815
1843
  }
1816
1844
  if (tag.stage === 4 /* ATTR_GROUP */) {
1817
- this.emitError(this.pos, "MALFORMED_OPEN_TAG", "Attribute group was not properly ended");
1845
+ this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, "Attribute group was not properly ended");
1818
1846
  return;
1819
1847
  }
1820
1848
  this.exitState();
@@ -1839,14 +1867,14 @@ var OPEN_TAG = {
1839
1867
  return;
1840
1868
  } else if (code === 91 /* OPEN_SQUARE_BRACKET */) {
1841
1869
  if (tag.stage === 4 /* ATTR_GROUP */) {
1842
- this.emitError(this.pos, "MALFORMED_OPEN_TAG", 'Unexpected "[" character within open tag.');
1870
+ this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, 'Unexpected "[" character within open tag.');
1843
1871
  return;
1844
1872
  }
1845
1873
  tag.stage = 4 /* ATTR_GROUP */;
1846
1874
  return;
1847
1875
  } else if (code === 93 /* CLOSE_SQUARE_BRACKET */) {
1848
1876
  if (tag.stage !== 4 /* ATTR_GROUP */) {
1849
- this.emitError(this.pos, "MALFORMED_OPEN_TAG", 'Unexpected "]" character within open tag.');
1877
+ this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, 'Unexpected "]" character within open tag.');
1850
1878
  return;
1851
1879
  }
1852
1880
  tag.stage = 0 /* UNKNOWN */;
@@ -1863,7 +1891,7 @@ var OPEN_TAG = {
1863
1891
  return;
1864
1892
  }
1865
1893
  if (code === 60 /* OPEN_ANGLE_BRACKET */) {
1866
- return this.emitError(this.pos, "ILLEGAL_ATTRIBUTE_NAME", 'Invalid attribute name. Attribute name cannot begin with the "<" character.');
1894
+ return this.emitError(this.pos, 2 /* INVALID_ATTRIBUTE_NAME */, 'Invalid attribute name. Attribute name cannot begin with the "<" character.');
1867
1895
  }
1868
1896
  if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 42 /* ASTERISK */) {
1869
1897
  this.enterState(states_exports.JS_COMMENT_BLOCK);
@@ -1885,7 +1913,7 @@ var OPEN_TAG = {
1885
1913
  this.pos--;
1886
1914
  } else if (code === 40 /* OPEN_PAREN */ && !tag.hasAttrs) {
1887
1915
  if (tag.hasArgs) {
1888
- this.emitError(this.pos, "ILLEGAL_TAG_ARGUMENT", "A tag can only have one argument");
1916
+ this.emitError(this.pos, 11 /* INVALID_TAG_ARGUMENT */, "A tag can only have one argument");
1889
1917
  return;
1890
1918
  }
1891
1919
  tag.stage = 2 /* ARGUMENT */;
@@ -1921,7 +1949,7 @@ var OPEN_TAG = {
1921
1949
  switch (tag.stage) {
1922
1950
  case 1 /* VAR */: {
1923
1951
  if (child.start === child.end) {
1924
- return this.emitError(child, "MISSING_TAG_VARIABLE", "A slash was found that was not followed by a variable name or lhs expression");
1952
+ return this.emitError(child, 23 /* MISSING_TAG_VARIABLE */, "A slash was found that was not followed by a variable name or lhs expression");
1925
1953
  }
1926
1954
  (_b = (_a = this.options).onTagVar) == null ? void 0 : _b.call(_a, {
1927
1955
  start: child.start - 1,
@@ -1985,8 +2013,8 @@ function createParser(handlers) {
1985
2013
  read(range) {
1986
2014
  return parser.read(range);
1987
2015
  },
1988
- positionAt(index) {
1989
- return parser.positionAt(index);
2016
+ positionAt(offset) {
2017
+ return parser.positionAt(offset);
1990
2018
  },
1991
2019
  locationAt(range) {
1992
2020
  return parser.locationAt(range);
@@ -1994,6 +2022,7 @@ function createParser(handlers) {
1994
2022
  };
1995
2023
  }
1996
2024
  export {
2025
+ ErrorCode,
1997
2026
  TagType,
1998
2027
  createParser
1999
2028
  };
@@ -70,7 +70,7 @@ export declare namespace Ranges {
70
70
  quasis: Range[];
71
71
  }
72
72
  interface Error extends Range {
73
- code: string;
73
+ code: ErrorCode;
74
74
  message: string;
75
75
  }
76
76
  interface Scriptlet extends Value {
@@ -96,6 +96,34 @@ export declare namespace Ranges {
96
96
  value: Range | undefined;
97
97
  }
98
98
  }
99
+ export declare enum ErrorCode {
100
+ EXTRA_CLOSING_TAG = 0,
101
+ INVALID_ATTRIBUTE_ARGUMENT = 1,
102
+ INVALID_ATTRIBUTE_NAME = 2,
103
+ INVALID_ATTRIBUTE_VALUE = 3,
104
+ INVALID_CHARACTER = 4,
105
+ INVALID_CODE_AFTER_SEMICOLON = 5,
106
+ INVALID_EXPRESSION = 6,
107
+ INVALID_INDENTATION = 7,
108
+ INVALID_LINE_START = 8,
109
+ INVALID_REGULAR_EXPRESSION = 9,
110
+ INVALID_STRING = 10,
111
+ INVALID_TAG_ARGUMENT = 11,
112
+ INVALID_TAG_SHORTHAND = 12,
113
+ INVALID_TEMPLATE_STRING = 13,
114
+ MALFORMED_CDATA = 14,
115
+ MALFORMED_CLOSE_TAG = 15,
116
+ MALFORMED_COMMENT = 16,
117
+ MALFORMED_DECLARATION = 17,
118
+ MALFORMED_DOCUMENT_TYPE = 18,
119
+ MALFORMED_OPEN_TAG = 19,
120
+ MALFORMED_PLACEHOLDER = 20,
121
+ MISMATCHED_CLOSING_TAG = 21,
122
+ MISSING_END_TAG = 22,
123
+ MISSING_TAG_VARIABLE = 23,
124
+ RESERVED_TAG_NAME = 24,
125
+ ROOT_TAG_ONLY = 25
126
+ }
99
127
  export declare const enum TagType {
100
128
  html = 0,
101
129
  text = 1,
@@ -105,12 +133,12 @@ export declare const enum TagType {
105
133
  export interface ParserOptions {
106
134
  onError?(data: Ranges.Error): void;
107
135
  onText?(data: Range): void;
136
+ onPlaceholder?(data: Ranges.Placeholder): void;
108
137
  onComment?(data: Ranges.Value): void;
109
138
  onCDATA?(data: Ranges.Value): void;
110
139
  onDeclaration?(data: Ranges.Value): void;
111
140
  onDoctype?(data: Ranges.Value): void;
112
141
  onScriptlet?(data: Ranges.Scriptlet): void;
113
- onPlaceholder?(data: Ranges.Placeholder): void;
114
142
  onTagName?(data: Ranges.TagName): TagType | void;
115
143
  onTagShorthandId?(data: Ranges.Template): void;
116
144
  onTagShorthandClass?(data: Ranges.Template): void;
@@ -1,5 +1,5 @@
1
1
  import { type Parser } from "../internal";
2
- import type { Location, Position, Range } from "./constants";
2
+ import { Location, Position, Range } from "./constants";
3
3
  export declare function isWhitespaceCode(code: number): boolean;
4
4
  export declare function getLoc(lines: number[], range: Range): Location;
5
5
  export declare function getPos(lines: number[], startLine: number, index: number): Position;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "htmljs-parser",
3
3
  "description": "An HTML parser recognizes content and string placeholders and allows JavaScript expressions as attribute values",
4
- "version": "3.2.0",
4
+ "version": "3.2.3",
5
5
  "author": "Phillip Gates-Idem <phillip.idem@gmail.com>",
6
6
  "devDependencies": {
7
7
  "@commitlint/cli": "^16.2.3",
@@ -63,7 +63,7 @@
63
63
  "scripts": {
64
64
  "bench": "npm run build && node -r esbuild-register ./src/__tests__/bench",
65
65
  "build": "tsc -b && node -r esbuild-register build",
66
- "ci:test": "nyc npm run mocha -- --forbid-pending --forbid-only",
66
+ "ci:test": "nyc npm run mocha -- --forbid-only",
67
67
  "format": "npm run lint:eslint -- --fix && npm run lint:prettier -- --write && (fixpack || true)",
68
68
  "lint": "tsc -b && npm run lint:eslint && npm run lint:prettier -- -l && fixpack",
69
69
  "lint:eslint": "eslint -f visualstudio .",