htmljs-parser 3.0.0 → 3.2.1

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.
@@ -1,4 +1,4 @@
1
- import { STATE, Range, Handlers } from "../internal";
1
+ import { STATE, Range, ParserOptions as Options } from "../internal";
2
2
  export interface Meta extends Range {
3
3
  parent: Meta;
4
4
  state: StateDefinition;
@@ -15,7 +15,7 @@ export interface StateDefinition<P extends Meta = Meta> {
15
15
  return: (this: Parser, child: Meta, activeRange: P) => void;
16
16
  }
17
17
  export declare class Parser {
18
- handlers: Handlers;
18
+ options: Options;
19
19
  pos: number;
20
20
  maxPos: number;
21
21
  data: string;
@@ -30,7 +30,7 @@ export declare class Parser {
30
30
  endingMixedModeAtEOL?: boolean;
31
31
  textPos: number;
32
32
  lines: undefined | number[];
33
- constructor(handlers: Handlers);
33
+ constructor(options: Options);
34
34
  read(range: Range): string;
35
35
  positionAt(index: number): import("../internal").Position;
36
36
  locationAt(range: Range): import("../internal").Location;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { type Handlers, type Range } from "./internal";
2
- export { OpenTagEnding, type Handlers, type Position, type Location, type Ranges, type Range, } from "./internal";
1
+ import { type ParserOptions, type Range } from "./internal";
2
+ export { TagType, type ParserOptions as Handlers, type Position, type Location, type Ranges, type Range, } from "./internal";
3
3
  /**
4
4
  * Creates a new Marko parser.
5
5
  */
6
- export declare function createParser(handlers: Handlers): {
6
+ export declare function createParser(handlers: ParserOptions): {
7
7
  /**
8
8
  * Parses code and calls the provided handlers.
9
9
  */
package/dist/index.js CHANGED
@@ -19,19 +19,19 @@ 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
+ TagType: () => TagType,
23
23
  createParser: () => createParser
24
24
  });
25
25
  module.exports = __toCommonJS(src_exports);
26
26
 
27
27
  // 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 || {});
28
+ var TagType = /* @__PURE__ */ ((TagType2) => {
29
+ TagType2[TagType2["html"] = 0] = "html";
30
+ TagType2[TagType2["text"] = 1] = "text";
31
+ TagType2[TagType2["void"] = 2] = "void";
32
+ TagType2[TagType2["statement"] = 3] = "statement";
33
+ return TagType2;
34
+ })(TagType || {});
35
35
 
36
36
  // src/util/util.ts
37
37
  function isWhitespaceCode(code) {
@@ -80,9 +80,9 @@ function htmlEOF() {
80
80
 
81
81
  // src/core/Parser.ts
82
82
  var Parser = class {
83
- constructor(handlers) {
84
- this.handlers = handlers;
85
- this.handlers = handlers;
83
+ constructor(options) {
84
+ this.options = options;
85
+ this.options = options;
86
86
  }
87
87
  pos;
88
88
  maxPos;
@@ -173,13 +173,13 @@ var Parser = class {
173
173
  var _a, _b;
174
174
  const start = this.textPos;
175
175
  if (start !== -1) {
176
- (_b = (_a = this.handlers).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
176
+ (_b = (_a = this.options).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
177
177
  this.textPos = -1;
178
178
  }
179
179
  }
180
180
  beginHtmlBlock(delimiter, singleLine) {
181
181
  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);
182
+ const content = this.enterState(((_a = this.activeTag) == null ? void 0 : _a.type) === 1 /* text */ ? states_exports.PARSED_TEXT_CONTENT : states_exports.HTML_CONTENT);
183
183
  content.singleLine = singleLine;
184
184
  content.delimiter = delimiter;
185
185
  content.indent = this.indent;
@@ -193,7 +193,7 @@ var Parser = class {
193
193
  start = range.start;
194
194
  end = range.end;
195
195
  }
196
- (_b = (_a = this.handlers).onError) == null ? void 0 : _b.call(_a, {
196
+ (_b = (_a = this.options).onError) == null ? void 0 : _b.call(_a, {
197
197
  start,
198
198
  end,
199
199
  code,
@@ -207,7 +207,7 @@ var Parser = class {
207
207
  if (beginMixedMode)
208
208
  this.endingMixedModeAtEOL = true;
209
209
  this.activeTag = parentTag;
210
- (_b = (_a = this.handlers).onCloseTag) == null ? void 0 : _b.call(_a, {
210
+ (_b = (_a = this.options).onCloseTag) == null ? void 0 : _b.call(_a, {
211
211
  start,
212
212
  end,
213
213
  value
@@ -454,7 +454,7 @@ var ATTRIBUTE = {
454
454
  start: child.start,
455
455
  end: child.end
456
456
  };
457
- (_b = (_a = this.handlers).onAttrName) == null ? void 0 : _b.call(_a, attr.name);
457
+ (_b = (_a = this.options).onAttrName) == null ? void 0 : _b.call(_a, attr.name);
458
458
  break;
459
459
  }
460
460
  case 3 /* ARGUMENT */: {
@@ -476,7 +476,7 @@ var ATTRIBUTE = {
476
476
  };
477
477
  } else {
478
478
  attr.args = true;
479
- (_d = (_c = this.handlers).onAttrArgs) == null ? void 0 : _d.call(_c, {
479
+ (_d = (_c = this.options).onAttrArgs) == null ? void 0 : _d.call(_c, {
480
480
  start,
481
481
  end,
482
482
  value
@@ -488,7 +488,7 @@ var ATTRIBUTE = {
488
488
  const params = attr.args;
489
489
  const start = params.start;
490
490
  const end = ++this.pos;
491
- (_f = (_e = this.handlers).onAttrMethod) == null ? void 0 : _f.call(_e, {
491
+ (_f = (_e = this.options).onAttrMethod) == null ? void 0 : _f.call(_e, {
492
492
  start,
493
493
  end,
494
494
  params,
@@ -509,7 +509,7 @@ var ATTRIBUTE = {
509
509
  return this.emitError(child, "ILLEGAL_ATTRIBUTE_VALUE", "Missing value for attribute");
510
510
  }
511
511
  if (attr.spread) {
512
- (_h = (_g = this.handlers).onAttrSpread) == null ? void 0 : _h.call(_g, {
512
+ (_h = (_g = this.options).onAttrSpread) == null ? void 0 : _h.call(_g, {
513
513
  start: attr.valueStart,
514
514
  end: child.end,
515
515
  value: {
@@ -518,7 +518,7 @@ var ATTRIBUTE = {
518
518
  }
519
519
  });
520
520
  } else {
521
- (_j = (_i = this.handlers).onAttrValue) == null ? void 0 : _j.call(_i, {
521
+ (_j = (_i = this.options).onAttrValue) == null ? void 0 : _j.call(_i, {
522
522
  start: attr.valueStart,
523
523
  end: child.end,
524
524
  bound: attr.bound,
@@ -537,7 +537,7 @@ var ATTRIBUTE = {
537
537
  function ensureAttrName(parser, attr) {
538
538
  var _a, _b;
539
539
  if (!attr.name) {
540
- (_b = (_a = parser.handlers).onAttrName) == null ? void 0 : _b.call(_a, {
540
+ (_b = (_a = parser.options).onAttrName) == null ? void 0 : _b.call(_a, {
541
541
  start: attr.start,
542
542
  end: attr.start
543
543
  });
@@ -634,7 +634,7 @@ var CDATA = {
634
634
  },
635
635
  exit(cdata) {
636
636
  var _a, _b;
637
- (_b = (_a = this.handlers).onCDATA) == null ? void 0 : _b.call(_a, {
637
+ (_b = (_a = this.options).onCDATA) == null ? void 0 : _b.call(_a, {
638
638
  start: cdata.start,
639
639
  end: cdata.end,
640
640
  value: {
@@ -782,11 +782,7 @@ var CONCISE_HTML_CONTENT = {
782
782
  return;
783
783
  }
784
784
  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 */) {
785
+ if (parentTag.type === 1 /* text */ && code !== 45 /* HTML_BLOCK_DELIMITER */) {
790
786
  this.emitError(this.pos, "ILLEGAL_LINE_START", 'A line within a tag that only allows text content must begin with a "-" character');
791
787
  return;
792
788
  }
@@ -847,7 +843,7 @@ var CONCISE_HTML_CONTENT = {
847
843
  this.isConcise = true;
848
844
  switch (child.state) {
849
845
  case states_exports.JS_COMMENT_LINE:
850
- (_b = (_a = this.handlers).onComment) == null ? void 0 : _b.call(_a, {
846
+ (_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
851
847
  start: child.start,
852
848
  end: child.end,
853
849
  value: {
@@ -857,7 +853,7 @@ var CONCISE_HTML_CONTENT = {
857
853
  });
858
854
  break;
859
855
  case states_exports.JS_COMMENT_BLOCK: {
860
- (_d = (_c = this.handlers).onComment) == null ? void 0 : _d.call(_c, {
856
+ (_d = (_c = this.options).onComment) == null ? void 0 : _d.call(_c, {
861
857
  start: child.start,
862
858
  end: child.end,
863
859
  value: {
@@ -909,7 +905,7 @@ function exitDeclaration(parser, declaration, closeOffset) {
909
905
  var _a, _b;
910
906
  parser.pos += closeOffset;
911
907
  parser.exitState();
912
- (_b = (_a = parser.handlers).onDeclaration) == null ? void 0 : _b.call(_a, {
908
+ (_b = (_a = parser.options).onDeclaration) == null ? void 0 : _b.call(_a, {
913
909
  start: declaration.start,
914
910
  end: declaration.end,
915
911
  value: {
@@ -933,7 +929,7 @@ var DTD = {
933
929
  },
934
930
  exit(documentType) {
935
931
  var _a, _b;
936
- (_b = (_a = this.handlers).onDoctype) == null ? void 0 : _b.call(_a, {
932
+ (_b = (_a = this.options).onDoctype) == null ? void 0 : _b.call(_a, {
937
933
  start: documentType.start,
938
934
  end: documentType.end,
939
935
  value: {
@@ -1071,7 +1067,7 @@ var EXPRESSION = {
1071
1067
  }
1072
1068
  };
1073
1069
  function buildOperatorPattern(isConcise) {
1074
- const binary = `[!~*%&^|?:]+|(?<=[!=<>&^~|/*?%+-])=|=(?=[!=<>&^~|/*?%+-])|(?<!\\+)\\s*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)${isConcise ? "-" : "\\s*-(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<![/*])/(?![/*${isConcise ? "" : ">"}])|(?<!${isConcise ? "^\\s*|" : ""}\\.)\\.(?!\\.)|<${isConcise ? "{2,}|(?<!^\\s*)<" : "+"}|>${isConcise ? "+" : "{2,}"}|\\bin(?:stanceof)?(?=\\s+[^=/,;:>])`;
1070
+ const binary = `[!~*%&^|?:]+|(?<=[!=<>&^~|/*?%+-])=|=(?=[!=<>&^~|/*?%+-])|(?<!\\+)\\s*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!^\\s*|-)-${isConcise ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<![/*])/(?![/*${isConcise ? "" : ">"}])|(?<!${isConcise ? "^\\s*|" : ""}\\.)\\.(?!\\.)|<${isConcise ? "{2,}|(?<!^\\s*)<" : "+"}|>${isConcise ? "+" : "{2,}"}|\\bin(?:stanceof)?(?=\\s+[^=/,;:>])`;
1075
1071
  const unary = "\\b(?:a(?:sync|wait)|class|function|new|typeof|void)\\b";
1076
1072
  const lookAheadPattern = "\\s*(?:" + binary + `)\\s*|\\s+(?=[${isConcise ? "" : "["}{(])`;
1077
1073
  const lookBehindPattern = `(?<=${unary}|${binary})`;
@@ -1132,7 +1128,7 @@ var HTML_COMMENT = {
1132
1128
  },
1133
1129
  exit(comment) {
1134
1130
  var _a, _b;
1135
- (_b = (_a = this.handlers).onComment) == null ? void 0 : _b.call(_a, {
1131
+ (_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
1136
1132
  start: comment.start,
1137
1133
  end: comment.end,
1138
1134
  value: {
@@ -1262,7 +1258,7 @@ var INLINE_SCRIPT = {
1262
1258
  },
1263
1259
  exit(inlineScript) {
1264
1260
  var _a, _b;
1265
- (_b = (_a = this.handlers).onScriptlet) == null ? void 0 : _b.call(_a, {
1261
+ (_b = (_a = this.options).onScriptlet) == null ? void 0 : _b.call(_a, {
1266
1262
  start: inlineScript.start,
1267
1263
  end: inlineScript.end,
1268
1264
  block: inlineScript.block,
@@ -1342,7 +1338,7 @@ var JS_COMMENT_LINE = {
1342
1338
  },
1343
1339
  char(code) {
1344
1340
  var _a;
1345
- if (!this.isConcise && code === 60 /* OPEN_ANGLE_BRACKET */ && ((_a = this.activeTag) == null ? void 0 : _a.bodyMode) === 1 /* PARSED_TEXT */) {
1341
+ if (!this.isConcise && code === 60 /* OPEN_ANGLE_BRACKET */ && ((_a = this.activeTag) == null ? void 0 : _a.type) === 1 /* text */) {
1346
1342
  states_exports.checkForClosingTag(this);
1347
1343
  }
1348
1344
  },
@@ -1426,7 +1422,7 @@ var PLACEHOLDER = {
1426
1422
  },
1427
1423
  exit(placeholder) {
1428
1424
  var _a, _b;
1429
- (_b = (_a = this.handlers).onPlaceholder) == null ? void 0 : _b.call(_a, {
1425
+ (_b = (_a = this.options).onPlaceholder) == null ? void 0 : _b.call(_a, {
1430
1426
  start: placeholder.start,
1431
1427
  end: placeholder.end,
1432
1428
  escape: placeholder.escape,
@@ -1562,23 +1558,6 @@ var STRING = {
1562
1558
  };
1563
1559
 
1564
1560
  // src/states/TAG_NAME.ts
1565
- var VOID_TAGS = [
1566
- "area",
1567
- "base",
1568
- "br",
1569
- "col",
1570
- "hr",
1571
- "embed",
1572
- "img",
1573
- "input",
1574
- "link",
1575
- "meta",
1576
- "param",
1577
- "source",
1578
- "track",
1579
- "wbr"
1580
- ];
1581
- var CODE_TAGS = ["import", "export", "static", "class"];
1582
1561
  var TAG_NAME = {
1583
1562
  name: "TAG_NAME",
1584
1563
  enter(parent, start) {
@@ -1603,7 +1582,7 @@ var TAG_NAME = {
1603
1582
  return this.emitError(tagName, "INVALID_TAG_SHORTHAND", "Multiple shorthand ID parts are not allowed on the same tag");
1604
1583
  }
1605
1584
  this.activeTag.hasShorthandId = true;
1606
- (_b = (_a = this.handlers).onTagShorthandId) == null ? void 0 : _b.call(_a, {
1585
+ (_b = (_a = this.options).onTagShorthandId) == null ? void 0 : _b.call(_a, {
1607
1586
  start,
1608
1587
  end,
1609
1588
  quasis,
@@ -1611,7 +1590,7 @@ var TAG_NAME = {
1611
1590
  });
1612
1591
  break;
1613
1592
  case 46 /* PERIOD */:
1614
- (_d = (_c = this.handlers).onTagShorthandClass) == null ? void 0 : _d.call(_c, {
1593
+ (_d = (_c = this.options).onTagShorthandClass) == null ? void 0 : _d.call(_c, {
1615
1594
  start,
1616
1595
  end,
1617
1596
  quasis,
@@ -1620,28 +1599,26 @@ var TAG_NAME = {
1620
1599
  break;
1621
1600
  default: {
1622
1601
  const tag = this.activeTag;
1602
+ const tagType = (_f = (_e = this.options).onTagName) == null ? void 0 : _f.call(_e, {
1603
+ start,
1604
+ end,
1605
+ quasis,
1606
+ expressions,
1607
+ concise: this.isConcise
1608
+ });
1623
1609
  tag.tagName = tagName;
1624
- if (tagName.expressions.length === 0) {
1625
- if (this.matchAnyAtPos(tagName, VOID_TAGS)) {
1626
- tag.ending |= 2 /* void */;
1627
- } else if (this.matchAnyAtPos(tagName, CODE_TAGS)) {
1610
+ if (tagType) {
1611
+ tag.type = tagType;
1612
+ if (tagType === 3 /* statement */) {
1628
1613
  if (!tag.concise) {
1629
1614
  return this.emitError(tagName, "RESERVED_TAG_NAME", `The "${this.read(tagName)}" tag is reserved and cannot be used as an HTML tag.`);
1630
1615
  }
1631
1616
  if (tag.parentTag) {
1632
1617
  return this.emitError(tagName, "ROOT_TAG_ONLY", `"${this.read(tagName)}" can only be used at the root of the template.`);
1633
1618
  }
1634
- tag.ending |= 4 /* code */;
1635
1619
  this.enterState(states_exports.EXPRESSION).terminatedByEOL = true;
1636
1620
  }
1637
1621
  }
1638
- (_f = (_e = this.handlers).onTagName) == null ? void 0 : _f.call(_e, {
1639
- start,
1640
- end,
1641
- quasis,
1642
- expressions,
1643
- concise: this.isConcise
1644
- });
1645
1622
  break;
1646
1623
  }
1647
1624
  }
@@ -1733,7 +1710,6 @@ var TEMPLATE_STRING = {
1733
1710
  };
1734
1711
 
1735
1712
  // src/states/OPEN_TAG.ts
1736
- var PARSED_TEXT_TAGS = ["script", "style", "textarea", "html-comment"];
1737
1713
  var CONCISE_TAG_VAR_TERMINATORS = [
1738
1714
  59 /* SEMICOLON */,
1739
1715
  40 /* OPEN_PAREN */,
@@ -1754,6 +1730,7 @@ var OPEN_TAG = {
1754
1730
  enter(parent, start) {
1755
1731
  const tag = this.activeTag = {
1756
1732
  state: OPEN_TAG,
1733
+ type: 0 /* html */,
1757
1734
  parent,
1758
1735
  start,
1759
1736
  end: start,
@@ -1764,11 +1741,10 @@ var OPEN_TAG = {
1764
1741
  hasShorthandId: false,
1765
1742
  hasArgs: false,
1766
1743
  hasAttrs: false,
1744
+ selfClosed: false,
1767
1745
  shorthandEnd: -1,
1768
1746
  tagName: void 0,
1769
- ending: 0 /* tag */,
1770
1747
  concise: this.isConcise,
1771
- bodyMode: 0 /* HTML */,
1772
1748
  beginMixedMode: this.beginMixedMode || this.endingMixedModeAtEOL
1773
1749
  };
1774
1750
  this.beginMixedMode = false;
@@ -1778,21 +1754,27 @@ var OPEN_TAG = {
1778
1754
  },
1779
1755
  exit(tag) {
1780
1756
  var _a, _b;
1781
- const { tagName, ending } = tag;
1782
- (_b = (_a = this.handlers).onOpenTagEnd) == null ? void 0 : _b.call(_a, {
1783
- start: this.pos - (this.isConcise ? 0 : ending & 1 /* self */ ? 2 : 1),
1757
+ const { selfClosed } = tag;
1758
+ (_b = (_a = this.options).onOpenTagEnd) == null ? void 0 : _b.call(_a, {
1759
+ start: this.pos - (this.isConcise ? 0 : selfClosed ? 2 : 1),
1784
1760
  end: this.pos,
1785
- ending
1761
+ selfClosed
1786
1762
  });
1787
- if (!this.isConcise && ending !== 0 /* tag */) {
1788
- this.closeTag(this.pos, this.pos, void 0);
1789
- } else if (tagName.expressions.length === 0 && this.matchAnyAtPos(tagName, PARSED_TEXT_TAGS)) {
1790
- tag.bodyMode = 1 /* PARSED_TEXT */;
1791
- if (this.isConcise) {
1792
- this.enterState(states_exports.CONCISE_HTML_CONTENT);
1793
- } else {
1794
- this.enterState(states_exports.PARSED_TEXT_CONTENT);
1763
+ switch (selfClosed ? 2 /* void */ : tag.type) {
1764
+ case 2 /* void */:
1765
+ case 3 /* statement */: {
1766
+ if (tag.beginMixedMode)
1767
+ this.endingMixedModeAtEOL = true;
1768
+ this.activeTag = tag.parentTag;
1769
+ break;
1795
1770
  }
1771
+ case 1 /* text */:
1772
+ if (this.isConcise) {
1773
+ this.enterState(states_exports.CONCISE_HTML_CONTENT);
1774
+ } else {
1775
+ this.enterState(states_exports.PARSED_TEXT_CONTENT);
1776
+ }
1777
+ break;
1796
1778
  }
1797
1779
  },
1798
1780
  eol(_, tag) {
@@ -1891,7 +1873,7 @@ var OPEN_TAG = {
1891
1873
  this.exitState();
1892
1874
  return;
1893
1875
  } else if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 62 /* CLOSE_ANGLE_BRACKET */) {
1894
- tag.ending |= 1 /* self */;
1876
+ tag.selfClosed = true;
1895
1877
  this.pos += 2;
1896
1878
  this.exitState();
1897
1879
  return;
@@ -1957,7 +1939,7 @@ var OPEN_TAG = {
1957
1939
  if (child.start === child.end) {
1958
1940
  return this.emitError(child, "MISSING_TAG_VARIABLE", "A slash was found that was not followed by a variable name or lhs expression");
1959
1941
  }
1960
- (_b = (_a = this.handlers).onTagVar) == null ? void 0 : _b.call(_a, {
1942
+ (_b = (_a = this.options).onTagVar) == null ? void 0 : _b.call(_a, {
1961
1943
  start: child.start - 1,
1962
1944
  end: child.end,
1963
1945
  value: {
@@ -1982,7 +1964,7 @@ var OPEN_TAG = {
1982
1964
  this.pos--;
1983
1965
  } else {
1984
1966
  tag.hasArgs = true;
1985
- (_d = (_c = this.handlers).onTagArgs) == null ? void 0 : _d.call(_c, {
1967
+ (_d = (_c = this.options).onTagArgs) == null ? void 0 : _d.call(_c, {
1986
1968
  start,
1987
1969
  end,
1988
1970
  value
@@ -1992,7 +1974,7 @@ var OPEN_TAG = {
1992
1974
  }
1993
1975
  case 3 /* PARAMS */: {
1994
1976
  const end = ++this.pos;
1995
- (_f = (_e = this.handlers).onTagParams) == null ? void 0 : _f.call(_e, {
1977
+ (_f = (_e = this.options).onTagParams) == null ? void 0 : _f.call(_e, {
1996
1978
  start: child.start - 1,
1997
1979
  end,
1998
1980
  value: {
@@ -2029,6 +2011,6 @@ function createParser(handlers) {
2029
2011
  }
2030
2012
  // Annotate the CommonJS export names for ESM import in node:
2031
2013
  0 && (module.exports = {
2032
- OpenTagEnding,
2014
+ TagType,
2033
2015
  createParser
2034
2016
  });
package/dist/index.mjs CHANGED
@@ -5,13 +5,13 @@ 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 TagType = /* @__PURE__ */ ((TagType2) => {
9
+ TagType2[TagType2["html"] = 0] = "html";
10
+ TagType2[TagType2["text"] = 1] = "text";
11
+ TagType2[TagType2["void"] = 2] = "void";
12
+ TagType2[TagType2["statement"] = 3] = "statement";
13
+ return TagType2;
14
+ })(TagType || {});
15
15
 
16
16
  // src/util/util.ts
17
17
  function isWhitespaceCode(code) {
@@ -60,9 +60,9 @@ function htmlEOF() {
60
60
 
61
61
  // src/core/Parser.ts
62
62
  var Parser = class {
63
- constructor(handlers) {
64
- this.handlers = handlers;
65
- this.handlers = handlers;
63
+ constructor(options) {
64
+ this.options = options;
65
+ this.options = options;
66
66
  }
67
67
  pos;
68
68
  maxPos;
@@ -153,13 +153,13 @@ var Parser = class {
153
153
  var _a, _b;
154
154
  const start = this.textPos;
155
155
  if (start !== -1) {
156
- (_b = (_a = this.handlers).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
156
+ (_b = (_a = this.options).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
157
157
  this.textPos = -1;
158
158
  }
159
159
  }
160
160
  beginHtmlBlock(delimiter, singleLine) {
161
161
  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);
162
+ const content = this.enterState(((_a = this.activeTag) == null ? void 0 : _a.type) === 1 /* text */ ? states_exports.PARSED_TEXT_CONTENT : states_exports.HTML_CONTENT);
163
163
  content.singleLine = singleLine;
164
164
  content.delimiter = delimiter;
165
165
  content.indent = this.indent;
@@ -173,7 +173,7 @@ var Parser = class {
173
173
  start = range.start;
174
174
  end = range.end;
175
175
  }
176
- (_b = (_a = this.handlers).onError) == null ? void 0 : _b.call(_a, {
176
+ (_b = (_a = this.options).onError) == null ? void 0 : _b.call(_a, {
177
177
  start,
178
178
  end,
179
179
  code,
@@ -187,7 +187,7 @@ var Parser = class {
187
187
  if (beginMixedMode)
188
188
  this.endingMixedModeAtEOL = true;
189
189
  this.activeTag = parentTag;
190
- (_b = (_a = this.handlers).onCloseTag) == null ? void 0 : _b.call(_a, {
190
+ (_b = (_a = this.options).onCloseTag) == null ? void 0 : _b.call(_a, {
191
191
  start,
192
192
  end,
193
193
  value
@@ -434,7 +434,7 @@ var ATTRIBUTE = {
434
434
  start: child.start,
435
435
  end: child.end
436
436
  };
437
- (_b = (_a = this.handlers).onAttrName) == null ? void 0 : _b.call(_a, attr.name);
437
+ (_b = (_a = this.options).onAttrName) == null ? void 0 : _b.call(_a, attr.name);
438
438
  break;
439
439
  }
440
440
  case 3 /* ARGUMENT */: {
@@ -456,7 +456,7 @@ var ATTRIBUTE = {
456
456
  };
457
457
  } else {
458
458
  attr.args = true;
459
- (_d = (_c = this.handlers).onAttrArgs) == null ? void 0 : _d.call(_c, {
459
+ (_d = (_c = this.options).onAttrArgs) == null ? void 0 : _d.call(_c, {
460
460
  start,
461
461
  end,
462
462
  value
@@ -468,7 +468,7 @@ var ATTRIBUTE = {
468
468
  const params = attr.args;
469
469
  const start = params.start;
470
470
  const end = ++this.pos;
471
- (_f = (_e = this.handlers).onAttrMethod) == null ? void 0 : _f.call(_e, {
471
+ (_f = (_e = this.options).onAttrMethod) == null ? void 0 : _f.call(_e, {
472
472
  start,
473
473
  end,
474
474
  params,
@@ -489,7 +489,7 @@ var ATTRIBUTE = {
489
489
  return this.emitError(child, "ILLEGAL_ATTRIBUTE_VALUE", "Missing value for attribute");
490
490
  }
491
491
  if (attr.spread) {
492
- (_h = (_g = this.handlers).onAttrSpread) == null ? void 0 : _h.call(_g, {
492
+ (_h = (_g = this.options).onAttrSpread) == null ? void 0 : _h.call(_g, {
493
493
  start: attr.valueStart,
494
494
  end: child.end,
495
495
  value: {
@@ -498,7 +498,7 @@ var ATTRIBUTE = {
498
498
  }
499
499
  });
500
500
  } else {
501
- (_j = (_i = this.handlers).onAttrValue) == null ? void 0 : _j.call(_i, {
501
+ (_j = (_i = this.options).onAttrValue) == null ? void 0 : _j.call(_i, {
502
502
  start: attr.valueStart,
503
503
  end: child.end,
504
504
  bound: attr.bound,
@@ -517,7 +517,7 @@ var ATTRIBUTE = {
517
517
  function ensureAttrName(parser, attr) {
518
518
  var _a, _b;
519
519
  if (!attr.name) {
520
- (_b = (_a = parser.handlers).onAttrName) == null ? void 0 : _b.call(_a, {
520
+ (_b = (_a = parser.options).onAttrName) == null ? void 0 : _b.call(_a, {
521
521
  start: attr.start,
522
522
  end: attr.start
523
523
  });
@@ -614,7 +614,7 @@ var CDATA = {
614
614
  },
615
615
  exit(cdata) {
616
616
  var _a, _b;
617
- (_b = (_a = this.handlers).onCDATA) == null ? void 0 : _b.call(_a, {
617
+ (_b = (_a = this.options).onCDATA) == null ? void 0 : _b.call(_a, {
618
618
  start: cdata.start,
619
619
  end: cdata.end,
620
620
  value: {
@@ -762,11 +762,7 @@ var CONCISE_HTML_CONTENT = {
762
762
  return;
763
763
  }
764
764
  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 */) {
765
+ if (parentTag.type === 1 /* text */ && code !== 45 /* HTML_BLOCK_DELIMITER */) {
770
766
  this.emitError(this.pos, "ILLEGAL_LINE_START", 'A line within a tag that only allows text content must begin with a "-" character');
771
767
  return;
772
768
  }
@@ -827,7 +823,7 @@ var CONCISE_HTML_CONTENT = {
827
823
  this.isConcise = true;
828
824
  switch (child.state) {
829
825
  case states_exports.JS_COMMENT_LINE:
830
- (_b = (_a = this.handlers).onComment) == null ? void 0 : _b.call(_a, {
826
+ (_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
831
827
  start: child.start,
832
828
  end: child.end,
833
829
  value: {
@@ -837,7 +833,7 @@ var CONCISE_HTML_CONTENT = {
837
833
  });
838
834
  break;
839
835
  case states_exports.JS_COMMENT_BLOCK: {
840
- (_d = (_c = this.handlers).onComment) == null ? void 0 : _d.call(_c, {
836
+ (_d = (_c = this.options).onComment) == null ? void 0 : _d.call(_c, {
841
837
  start: child.start,
842
838
  end: child.end,
843
839
  value: {
@@ -889,7 +885,7 @@ function exitDeclaration(parser, declaration, closeOffset) {
889
885
  var _a, _b;
890
886
  parser.pos += closeOffset;
891
887
  parser.exitState();
892
- (_b = (_a = parser.handlers).onDeclaration) == null ? void 0 : _b.call(_a, {
888
+ (_b = (_a = parser.options).onDeclaration) == null ? void 0 : _b.call(_a, {
893
889
  start: declaration.start,
894
890
  end: declaration.end,
895
891
  value: {
@@ -913,7 +909,7 @@ var DTD = {
913
909
  },
914
910
  exit(documentType) {
915
911
  var _a, _b;
916
- (_b = (_a = this.handlers).onDoctype) == null ? void 0 : _b.call(_a, {
912
+ (_b = (_a = this.options).onDoctype) == null ? void 0 : _b.call(_a, {
917
913
  start: documentType.start,
918
914
  end: documentType.end,
919
915
  value: {
@@ -1051,7 +1047,7 @@ var EXPRESSION = {
1051
1047
  }
1052
1048
  };
1053
1049
  function buildOperatorPattern(isConcise) {
1054
- const binary = `[!~*%&^|?:]+|(?<=[!=<>&^~|/*?%+-])=|=(?=[!=<>&^~|/*?%+-])|(?<!\\+)\\s*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)${isConcise ? "-" : "\\s*-(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<![/*])/(?![/*${isConcise ? "" : ">"}])|(?<!${isConcise ? "^\\s*|" : ""}\\.)\\.(?!\\.)|<${isConcise ? "{2,}|(?<!^\\s*)<" : "+"}|>${isConcise ? "+" : "{2,}"}|\\bin(?:stanceof)?(?=\\s+[^=/,;:>])`;
1050
+ const binary = `[!~*%&^|?:]+|(?<=[!=<>&^~|/*?%+-])=|=(?=[!=<>&^~|/*?%+-])|(?<!\\+)\\s*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!^\\s*|-)-${isConcise ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<![/*])/(?![/*${isConcise ? "" : ">"}])|(?<!${isConcise ? "^\\s*|" : ""}\\.)\\.(?!\\.)|<${isConcise ? "{2,}|(?<!^\\s*)<" : "+"}|>${isConcise ? "+" : "{2,}"}|\\bin(?:stanceof)?(?=\\s+[^=/,;:>])`;
1055
1051
  const unary = "\\b(?:a(?:sync|wait)|class|function|new|typeof|void)\\b";
1056
1052
  const lookAheadPattern = "\\s*(?:" + binary + `)\\s*|\\s+(?=[${isConcise ? "" : "["}{(])`;
1057
1053
  const lookBehindPattern = `(?<=${unary}|${binary})`;
@@ -1112,7 +1108,7 @@ var HTML_COMMENT = {
1112
1108
  },
1113
1109
  exit(comment) {
1114
1110
  var _a, _b;
1115
- (_b = (_a = this.handlers).onComment) == null ? void 0 : _b.call(_a, {
1111
+ (_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
1116
1112
  start: comment.start,
1117
1113
  end: comment.end,
1118
1114
  value: {
@@ -1242,7 +1238,7 @@ var INLINE_SCRIPT = {
1242
1238
  },
1243
1239
  exit(inlineScript) {
1244
1240
  var _a, _b;
1245
- (_b = (_a = this.handlers).onScriptlet) == null ? void 0 : _b.call(_a, {
1241
+ (_b = (_a = this.options).onScriptlet) == null ? void 0 : _b.call(_a, {
1246
1242
  start: inlineScript.start,
1247
1243
  end: inlineScript.end,
1248
1244
  block: inlineScript.block,
@@ -1322,7 +1318,7 @@ var JS_COMMENT_LINE = {
1322
1318
  },
1323
1319
  char(code) {
1324
1320
  var _a;
1325
- if (!this.isConcise && code === 60 /* OPEN_ANGLE_BRACKET */ && ((_a = this.activeTag) == null ? void 0 : _a.bodyMode) === 1 /* PARSED_TEXT */) {
1321
+ if (!this.isConcise && code === 60 /* OPEN_ANGLE_BRACKET */ && ((_a = this.activeTag) == null ? void 0 : _a.type) === 1 /* text */) {
1326
1322
  states_exports.checkForClosingTag(this);
1327
1323
  }
1328
1324
  },
@@ -1406,7 +1402,7 @@ var PLACEHOLDER = {
1406
1402
  },
1407
1403
  exit(placeholder) {
1408
1404
  var _a, _b;
1409
- (_b = (_a = this.handlers).onPlaceholder) == null ? void 0 : _b.call(_a, {
1405
+ (_b = (_a = this.options).onPlaceholder) == null ? void 0 : _b.call(_a, {
1410
1406
  start: placeholder.start,
1411
1407
  end: placeholder.end,
1412
1408
  escape: placeholder.escape,
@@ -1542,23 +1538,6 @@ var STRING = {
1542
1538
  };
1543
1539
 
1544
1540
  // src/states/TAG_NAME.ts
1545
- var VOID_TAGS = [
1546
- "area",
1547
- "base",
1548
- "br",
1549
- "col",
1550
- "hr",
1551
- "embed",
1552
- "img",
1553
- "input",
1554
- "link",
1555
- "meta",
1556
- "param",
1557
- "source",
1558
- "track",
1559
- "wbr"
1560
- ];
1561
- var CODE_TAGS = ["import", "export", "static", "class"];
1562
1541
  var TAG_NAME = {
1563
1542
  name: "TAG_NAME",
1564
1543
  enter(parent, start) {
@@ -1583,7 +1562,7 @@ var TAG_NAME = {
1583
1562
  return this.emitError(tagName, "INVALID_TAG_SHORTHAND", "Multiple shorthand ID parts are not allowed on the same tag");
1584
1563
  }
1585
1564
  this.activeTag.hasShorthandId = true;
1586
- (_b = (_a = this.handlers).onTagShorthandId) == null ? void 0 : _b.call(_a, {
1565
+ (_b = (_a = this.options).onTagShorthandId) == null ? void 0 : _b.call(_a, {
1587
1566
  start,
1588
1567
  end,
1589
1568
  quasis,
@@ -1591,7 +1570,7 @@ var TAG_NAME = {
1591
1570
  });
1592
1571
  break;
1593
1572
  case 46 /* PERIOD */:
1594
- (_d = (_c = this.handlers).onTagShorthandClass) == null ? void 0 : _d.call(_c, {
1573
+ (_d = (_c = this.options).onTagShorthandClass) == null ? void 0 : _d.call(_c, {
1595
1574
  start,
1596
1575
  end,
1597
1576
  quasis,
@@ -1600,28 +1579,26 @@ var TAG_NAME = {
1600
1579
  break;
1601
1580
  default: {
1602
1581
  const tag = this.activeTag;
1582
+ const tagType = (_f = (_e = this.options).onTagName) == null ? void 0 : _f.call(_e, {
1583
+ start,
1584
+ end,
1585
+ quasis,
1586
+ expressions,
1587
+ concise: this.isConcise
1588
+ });
1603
1589
  tag.tagName = tagName;
1604
- if (tagName.expressions.length === 0) {
1605
- if (this.matchAnyAtPos(tagName, VOID_TAGS)) {
1606
- tag.ending |= 2 /* void */;
1607
- } else if (this.matchAnyAtPos(tagName, CODE_TAGS)) {
1590
+ if (tagType) {
1591
+ tag.type = tagType;
1592
+ if (tagType === 3 /* statement */) {
1608
1593
  if (!tag.concise) {
1609
1594
  return this.emitError(tagName, "RESERVED_TAG_NAME", `The "${this.read(tagName)}" tag is reserved and cannot be used as an HTML tag.`);
1610
1595
  }
1611
1596
  if (tag.parentTag) {
1612
1597
  return this.emitError(tagName, "ROOT_TAG_ONLY", `"${this.read(tagName)}" can only be used at the root of the template.`);
1613
1598
  }
1614
- tag.ending |= 4 /* code */;
1615
1599
  this.enterState(states_exports.EXPRESSION).terminatedByEOL = true;
1616
1600
  }
1617
1601
  }
1618
- (_f = (_e = this.handlers).onTagName) == null ? void 0 : _f.call(_e, {
1619
- start,
1620
- end,
1621
- quasis,
1622
- expressions,
1623
- concise: this.isConcise
1624
- });
1625
1602
  break;
1626
1603
  }
1627
1604
  }
@@ -1713,7 +1690,6 @@ var TEMPLATE_STRING = {
1713
1690
  };
1714
1691
 
1715
1692
  // src/states/OPEN_TAG.ts
1716
- var PARSED_TEXT_TAGS = ["script", "style", "textarea", "html-comment"];
1717
1693
  var CONCISE_TAG_VAR_TERMINATORS = [
1718
1694
  59 /* SEMICOLON */,
1719
1695
  40 /* OPEN_PAREN */,
@@ -1734,6 +1710,7 @@ var OPEN_TAG = {
1734
1710
  enter(parent, start) {
1735
1711
  const tag = this.activeTag = {
1736
1712
  state: OPEN_TAG,
1713
+ type: 0 /* html */,
1737
1714
  parent,
1738
1715
  start,
1739
1716
  end: start,
@@ -1744,11 +1721,10 @@ var OPEN_TAG = {
1744
1721
  hasShorthandId: false,
1745
1722
  hasArgs: false,
1746
1723
  hasAttrs: false,
1724
+ selfClosed: false,
1747
1725
  shorthandEnd: -1,
1748
1726
  tagName: void 0,
1749
- ending: 0 /* tag */,
1750
1727
  concise: this.isConcise,
1751
- bodyMode: 0 /* HTML */,
1752
1728
  beginMixedMode: this.beginMixedMode || this.endingMixedModeAtEOL
1753
1729
  };
1754
1730
  this.beginMixedMode = false;
@@ -1758,21 +1734,27 @@ var OPEN_TAG = {
1758
1734
  },
1759
1735
  exit(tag) {
1760
1736
  var _a, _b;
1761
- const { tagName, ending } = tag;
1762
- (_b = (_a = this.handlers).onOpenTagEnd) == null ? void 0 : _b.call(_a, {
1763
- start: this.pos - (this.isConcise ? 0 : ending & 1 /* self */ ? 2 : 1),
1737
+ const { selfClosed } = tag;
1738
+ (_b = (_a = this.options).onOpenTagEnd) == null ? void 0 : _b.call(_a, {
1739
+ start: this.pos - (this.isConcise ? 0 : selfClosed ? 2 : 1),
1764
1740
  end: this.pos,
1765
- ending
1741
+ selfClosed
1766
1742
  });
1767
- if (!this.isConcise && ending !== 0 /* tag */) {
1768
- this.closeTag(this.pos, this.pos, void 0);
1769
- } else if (tagName.expressions.length === 0 && this.matchAnyAtPos(tagName, PARSED_TEXT_TAGS)) {
1770
- tag.bodyMode = 1 /* PARSED_TEXT */;
1771
- if (this.isConcise) {
1772
- this.enterState(states_exports.CONCISE_HTML_CONTENT);
1773
- } else {
1774
- this.enterState(states_exports.PARSED_TEXT_CONTENT);
1743
+ switch (selfClosed ? 2 /* void */ : tag.type) {
1744
+ case 2 /* void */:
1745
+ case 3 /* statement */: {
1746
+ if (tag.beginMixedMode)
1747
+ this.endingMixedModeAtEOL = true;
1748
+ this.activeTag = tag.parentTag;
1749
+ break;
1775
1750
  }
1751
+ case 1 /* text */:
1752
+ if (this.isConcise) {
1753
+ this.enterState(states_exports.CONCISE_HTML_CONTENT);
1754
+ } else {
1755
+ this.enterState(states_exports.PARSED_TEXT_CONTENT);
1756
+ }
1757
+ break;
1776
1758
  }
1777
1759
  },
1778
1760
  eol(_, tag) {
@@ -1871,7 +1853,7 @@ var OPEN_TAG = {
1871
1853
  this.exitState();
1872
1854
  return;
1873
1855
  } else if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 62 /* CLOSE_ANGLE_BRACKET */) {
1874
- tag.ending |= 1 /* self */;
1856
+ tag.selfClosed = true;
1875
1857
  this.pos += 2;
1876
1858
  this.exitState();
1877
1859
  return;
@@ -1937,7 +1919,7 @@ var OPEN_TAG = {
1937
1919
  if (child.start === child.end) {
1938
1920
  return this.emitError(child, "MISSING_TAG_VARIABLE", "A slash was found that was not followed by a variable name or lhs expression");
1939
1921
  }
1940
- (_b = (_a = this.handlers).onTagVar) == null ? void 0 : _b.call(_a, {
1922
+ (_b = (_a = this.options).onTagVar) == null ? void 0 : _b.call(_a, {
1941
1923
  start: child.start - 1,
1942
1924
  end: child.end,
1943
1925
  value: {
@@ -1962,7 +1944,7 @@ var OPEN_TAG = {
1962
1944
  this.pos--;
1963
1945
  } else {
1964
1946
  tag.hasArgs = true;
1965
- (_d = (_c = this.handlers).onTagArgs) == null ? void 0 : _d.call(_c, {
1947
+ (_d = (_c = this.options).onTagArgs) == null ? void 0 : _d.call(_c, {
1966
1948
  start,
1967
1949
  end,
1968
1950
  value
@@ -1972,7 +1954,7 @@ var OPEN_TAG = {
1972
1954
  }
1973
1955
  case 3 /* PARAMS */: {
1974
1956
  const end = ++this.pos;
1975
- (_f = (_e = this.handlers).onTagParams) == null ? void 0 : _f.call(_e, {
1957
+ (_f = (_e = this.options).onTagParams) == null ? void 0 : _f.call(_e, {
1976
1958
  start: child.start - 1,
1977
1959
  end,
1978
1960
  value: {
@@ -2008,6 +1990,6 @@ function createParser(handlers) {
2008
1990
  };
2009
1991
  }
2010
1992
  export {
2011
- OpenTagEnding,
1993
+ TagType,
2012
1994
  createParser
2013
1995
  };
@@ -1,4 +1,4 @@
1
- import { StateDefinition, BODY_MODE, OpenTagEnding, Ranges, Meta } from "../internal";
1
+ import { StateDefinition, Ranges, Meta, TagType } from "../internal";
2
2
  declare const enum TAG_STAGE {
3
3
  UNKNOWN = 0,
4
4
  VAR = 1,
@@ -7,7 +7,7 @@ declare const enum TAG_STAGE {
7
7
  ATTR_GROUP = 4
8
8
  }
9
9
  export interface OpenTagMeta extends Meta {
10
- bodyMode: BODY_MODE;
10
+ type: TagType;
11
11
  stage: TAG_STAGE;
12
12
  concise: boolean;
13
13
  beginMixedMode?: boolean;
@@ -16,7 +16,7 @@ export interface OpenTagMeta extends Meta {
16
16
  hasArgs: boolean;
17
17
  hasAttrs: boolean;
18
18
  hasShorthandId: boolean;
19
- ending: OpenTagEnding;
19
+ selfClosed: boolean;
20
20
  indent: string;
21
21
  nestedIndent: string | undefined;
22
22
  parentTag: OpenTagMeta | undefined;
@@ -37,10 +37,6 @@ export declare const enum CODE {
37
37
  SPACE = 32,
38
38
  TAB = 9
39
39
  }
40
- export declare const enum BODY_MODE {
41
- HTML = 0,
42
- PARSED_TEXT = 1
43
- }
44
40
  export interface Position {
45
41
  /**
46
42
  * Line position in a document (zero-based).
@@ -94,19 +90,19 @@ export declare namespace Ranges {
94
90
  params: Value;
95
91
  }
96
92
  interface OpenTagEnd extends Range {
97
- ending: OpenTagEnding;
93
+ selfClosed: boolean;
98
94
  }
99
95
  interface CloseTag extends Range {
100
96
  value: Range | undefined;
101
97
  }
102
98
  }
103
- export declare const enum OpenTagEnding {
104
- tag = 0,
105
- self = 1,
99
+ export declare const enum TagType {
100
+ html = 0,
101
+ text = 1,
106
102
  void = 2,
107
- code = 4
103
+ statement = 3
108
104
  }
109
- export interface Handlers {
105
+ export interface ParserOptions {
110
106
  onError?(data: Ranges.Error): void;
111
107
  onText?(data: Range): void;
112
108
  onComment?(data: Ranges.Value): void;
@@ -115,7 +111,7 @@ export interface Handlers {
115
111
  onDoctype?(data: Ranges.Value): void;
116
112
  onScriptlet?(data: Ranges.Scriptlet): void;
117
113
  onPlaceholder?(data: Ranges.Placeholder): void;
118
- onTagName?(data: Ranges.TagName): void;
114
+ onTagName?(data: Ranges.TagName): TagType | void;
119
115
  onTagShorthandId?(data: Ranges.Template): void;
120
116
  onTagShorthandClass?(data: Ranges.Template): void;
121
117
  onTagVar?(data: Ranges.Value): void;
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.0.0",
4
+ "version": "3.2.1",
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 .",