bbcode-compiler 0.1.8 → 0.1.10

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,25 +1,13 @@
1
1
  (function(global, factory) {
2
2
  typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.BbcodeCompiler = {}));
3
- })(this, function(exports2) {
4
- "use strict";var __defProp = Object.defineProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
-
3
+ })(this, (function(exports2) {
4
+ "use strict";
8
5
  function nodeIsType(node, nodeType) {
9
6
  return node.nodeType === nodeType;
10
7
  }
11
- var AstNodeType = /* @__PURE__ */ ((AstNodeType2) => {
12
- AstNodeType2["RootNode"] = "RootNode";
13
- AstNodeType2["TextNode"] = "TextNode";
14
- AstNodeType2["LinebreakNode"] = "LinebreakNode";
15
- AstNodeType2["TagNode"] = "TagNode";
16
- AstNodeType2["StartTagNode"] = "StartTagNode";
17
- AstNodeType2["EndTagNode"] = "EndTagNode";
18
- AstNodeType2["AttrNode"] = "AttrNode";
19
- return AstNodeType2;
20
- })(AstNodeType || {});
21
8
  class AstNode {
22
- constructor(children = []) {
9
+ children;
10
+ constructor(children = new Array()) {
23
11
  this.children = children;
24
12
  }
25
13
  addChild(node) {
@@ -56,10 +44,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
56
44
  }
57
45
  }
58
46
  class RootNode extends AstNode {
59
- constructor() {
60
- super(...arguments);
61
- __publicField(this, "nodeType", "RootNode");
62
- }
47
+ nodeType = "RootNode";
63
48
  isValid() {
64
49
  for (const child of this.children) {
65
50
  if (child.nodeType !== "TagNode" && child.nodeType !== "TextNode" && child.nodeType !== "LinebreakNode") {
@@ -70,10 +55,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
70
55
  }
71
56
  }
72
57
  class TextNode extends AstNode {
58
+ nodeType = "TextNode";
59
+ str;
73
60
  constructor(str) {
74
61
  super();
75
- __publicField(this, "nodeType", "TextNode");
76
- __publicField(this, "str");
77
62
  this.str = str;
78
63
  }
79
64
  isValid() {
@@ -91,30 +76,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
91
76
  }
92
77
  }
93
78
  class LinebreakNode extends AstNode {
94
- constructor() {
95
- super(...arguments);
96
- __publicField(this, "nodeType", "LinebreakNode");
97
- }
79
+ nodeType = "LinebreakNode";
98
80
  toShortString() {
99
81
  return `${super.toShortString()} "\\n"`;
100
82
  }
101
83
  }
102
- const _AttrNode = class _AttrNode extends AstNode {
103
- constructor() {
104
- super(...arguments);
105
- __publicField(this, "nodeType", "AttrNode");
106
- }
84
+ class AttrNode extends AstNode {
85
+ nodeType = "AttrNode";
86
+ static DEFAULT_KEY = "default";
107
87
  get key() {
108
88
  switch (this.children.length) {
109
89
  case 1: {
110
- return _AttrNode.DEFAULT_KEY;
90
+ return AttrNode.DEFAULT_KEY;
111
91
  }
112
92
  case 2: {
113
- if (!nodeIsType(
114
- this.children[0],
115
- "TextNode"
116
- /* TextNode */
117
- )) {
93
+ if (!nodeIsType(this.children[0], "TextNode")) {
118
94
  throw new Error("Invalid TextNode");
119
95
  }
120
96
  return this.children[0].str.trim();
@@ -125,21 +101,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
125
101
  get val() {
126
102
  switch (this.children.length) {
127
103
  case 1: {
128
- if (!nodeIsType(
129
- this.children[0],
130
- "TextNode"
131
- /* TextNode */
132
- )) {
104
+ if (!nodeIsType(this.children[0], "TextNode")) {
133
105
  throw new Error("Invalid TextNode");
134
106
  }
135
107
  return this.children[0].str.trim();
136
108
  }
137
109
  case 2: {
138
- if (!nodeIsType(
139
- this.children[1],
140
- "TextNode"
141
- /* TextNode */
142
- )) {
110
+ if (!nodeIsType(this.children[1], "TextNode")) {
143
111
  throw new Error("Invalid TextNode");
144
112
  }
145
113
  return this.children[1].str.trim();
@@ -185,15 +153,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
185
153
  }
186
154
  return json;
187
155
  }
188
- };
189
- __publicField(_AttrNode, "DEFAULT_KEY", "default");
190
- let AttrNode = _AttrNode;
156
+ }
191
157
  class StartTagNode extends AstNode {
158
+ nodeType = "StartTagNode";
159
+ tagName;
160
+ ogTag;
192
161
  constructor(tagName, ogTag, attrNodes = []) {
193
162
  super(attrNodes);
194
- __publicField(this, "nodeType", "StartTagNode");
195
- __publicField(this, "tagName");
196
- __publicField(this, "ogTag");
197
163
  this.tagName = tagName.toLowerCase();
198
164
  this.ogTag = ogTag;
199
165
  }
@@ -217,11 +183,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
217
183
  }
218
184
  }
219
185
  class EndTagNode extends AstNode {
186
+ nodeType = "EndTagNode";
187
+ tagName;
188
+ ogTag;
220
189
  constructor(tagName, ogTag) {
221
190
  super();
222
- __publicField(this, "nodeType", "EndTagNode");
223
- __publicField(this, "tagName");
224
- __publicField(this, "ogTag");
225
191
  this.tagName = tagName;
226
192
  this.ogTag = ogTag;
227
193
  }
@@ -240,11 +206,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
240
206
  }
241
207
  }
242
208
  class TagNode extends AstNode {
209
+ nodeType = "TagNode";
210
+ _startTag;
211
+ _endTag;
243
212
  constructor(startTag, endTag) {
244
213
  super();
245
- __publicField(this, "nodeType", "TagNode");
246
- __publicField(this, "_startTag");
247
- __publicField(this, "_endTag");
248
214
  this._startTag = startTag;
249
215
  this._endTag = endTag;
250
216
  }
@@ -261,23 +227,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
261
227
  if (!this._endTag) {
262
228
  return "";
263
229
  }
264
- if (nodeIsType(
265
- this._endTag,
266
- "LinebreakNode"
267
- /* LinebreakNode */
268
- )) {
230
+ if (nodeIsType(this._endTag, "LinebreakNode")) {
269
231
  return "\n";
270
232
  } else {
271
233
  return this._endTag.ogTag;
272
234
  }
273
235
  }
274
236
  isValid() {
275
- var _a;
276
- if (this._endTag && nodeIsType(
277
- this._endTag,
278
- "EndTagNode"
279
- /* EndTagNode */
280
- ) && this._startTag.tagName !== this._endTag.tagName) {
237
+ if (this._endTag && nodeIsType(this._endTag, "EndTagNode") && this._startTag.tagName !== this._endTag.tagName) {
281
238
  return false;
282
239
  }
283
240
  if (this.children.length === 1 && this.children[0].nodeType !== "RootNode") {
@@ -286,7 +243,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
286
243
  if (this.children.length > 2) {
287
244
  return false;
288
245
  }
289
- return super.isValid() && this._startTag.isValid() && (((_a = this._endTag) == null ? void 0 : _a.isValid()) ?? true);
246
+ return super.isValid() && this._startTag.isValid() && (this._endTag?.isValid() ?? true);
290
247
  }
291
248
  toString(depth = 0) {
292
249
  let s = " ".repeat(depth * 2) + this.toShortString() + ` [${this.tagName}]`;
@@ -321,14 +278,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
321
278
  return void 0;
322
279
  }
323
280
  const child = tagNode.children[0];
324
- if (!nodeIsType(child, AstNodeType.RootNode)) {
281
+ if (!nodeIsType(child, "RootNode")) {
325
282
  return void 0;
326
283
  }
327
284
  if (child.children.length !== 1) {
328
285
  return void 0;
329
286
  }
330
287
  const textNode = child.children[0];
331
- if (!nodeIsType(textNode, AstNodeType.TextNode)) {
288
+ if (!nodeIsType(textNode, "TextNode")) {
332
289
  return void 0;
333
290
  }
334
291
  return textNode.str;
@@ -568,22 +525,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
568
525
  }
569
526
  ];
570
527
  class Generator {
528
+ transforms;
571
529
  constructor(transforms = htmlTransforms) {
572
- __publicField(this, "transforms");
573
530
  this.transforms = new Map(transforms.map((transform) => [transform.name, transform]));
574
531
  }
575
532
  generate(root) {
576
533
  const stringify = (node) => {
577
- var _a;
578
534
  let output = "";
579
- if (nodeIsType(node, AstNodeType.TagNode)) {
535
+ if (nodeIsType(node, "TagNode")) {
580
536
  const tagName = node.tagName;
581
537
  const transform = this.transforms.get(tagName);
582
538
  if (!transform) {
583
539
  throw new Error(`Unrecognized bbcode ${node.tagName}`);
584
540
  }
585
541
  const renderedStartTag = transform.start(node);
586
- const renderedEndTag = ((_a = transform.end) == null ? void 0 : _a.call(transform, node)) ?? "";
542
+ const renderedEndTag = transform.end?.(node) ?? "";
587
543
  const isInvalidTag = renderedStartTag === false;
588
544
  if (isInvalidTag) {
589
545
  output += node.ogStartTag;
@@ -600,9 +556,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
600
556
  } else {
601
557
  output += renderedEndTag;
602
558
  }
603
- } else if (nodeIsType(node, AstNodeType.TextNode)) {
559
+ } else if (nodeIsType(node, "TextNode")) {
604
560
  output += node.str;
605
- } else if (nodeIsType(node, AstNodeType.LinebreakNode)) {
561
+ } else if (nodeIsType(node, "LinebreakNode")) {
606
562
  output += "\n";
607
563
  } else {
608
564
  for (const child of node.children) {
@@ -614,71 +570,56 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
614
570
  return stringify(root);
615
571
  }
616
572
  }
617
- var TokenType = /* @__PURE__ */ ((TokenType2) => {
618
- TokenType2[TokenType2["STR"] = 0] = "STR";
619
- TokenType2[TokenType2["LINEBREAK"] = 1] = "LINEBREAK";
620
- TokenType2[TokenType2["L_BRACKET"] = 2] = "L_BRACKET";
621
- TokenType2[TokenType2["R_BRACKET"] = 3] = "R_BRACKET";
622
- TokenType2[TokenType2["BACKSLASH"] = 4] = "BACKSLASH";
623
- TokenType2[TokenType2["EQUALS"] = 5] = "EQUALS";
624
- TokenType2[TokenType2["XSS_AMP"] = 6] = "XSS_AMP";
625
- TokenType2[TokenType2["XSS_LT"] = 7] = "XSS_LT";
626
- TokenType2[TokenType2["XSS_GT"] = 8] = "XSS_GT";
627
- TokenType2[TokenType2["XSS_D_QUOTE"] = 9] = "XSS_D_QUOTE";
628
- TokenType2[TokenType2["XSS_S_QUOTE"] = 10] = "XSS_S_QUOTE";
629
- return TokenType2;
630
- })(TokenType || {});
631
573
  function tokenTypeToString(tokenType) {
632
574
  switch (tokenType) {
633
- case 0:
575
+ case "STR":
634
576
  return "STR";
635
- case 1:
577
+ case "LINEBREAK":
636
578
  return "LINEBREAK";
637
- case 2:
579
+ case "L_BRACKET":
638
580
  return "L_BRACKET";
639
- case 3:
581
+ case "R_BRACKET":
640
582
  return "R_BRACKET";
641
- case 4:
583
+ case "BACKSLASH":
642
584
  return "BACKSLASH";
643
- case 5:
585
+ case "EQUALS":
644
586
  return "EQUALS";
645
- case 6:
587
+ case "XSS_AMP":
646
588
  return "XSS_AMP";
647
- case 7:
589
+ case "XSS_LT":
648
590
  return "XSS_LT";
649
- case 8:
591
+ case "XSS_GT":
650
592
  return "XSS_GT";
651
- case 9:
593
+ case "XSS_D_QUOTE":
652
594
  return "XSS_D_QUOTE";
653
- case 10:
595
+ case "XSS_S_QUOTE":
654
596
  return "XSS_S_QUOTE";
655
597
  }
656
598
  }
657
599
  function isStringToken(tokenType) {
658
600
  switch (tokenType) {
659
- case 6:
660
- case 7:
661
- case 8:
662
- case 9:
663
- case 10:
664
- case 0: {
601
+ case "XSS_AMP":
602
+ case "XSS_LT":
603
+ case "XSS_GT":
604
+ case "XSS_D_QUOTE":
605
+ case "XSS_S_QUOTE":
606
+ case "STR": {
665
607
  return true;
666
608
  }
667
609
  }
668
610
  return false;
669
611
  }
670
612
  const symbolTable = {
671
- "\n": 1,
672
- "[": 2,
673
- "]": 3,
674
- "/": 4,
675
- "=": 5,
676
- "&": 6,
677
- "<": 7,
678
- ">": 8,
679
- '"': 9,
680
- "'": 10
681
- /* XSS_S_QUOTE */
613
+ "\n": "LINEBREAK",
614
+ "[": "L_BRACKET",
615
+ "]": "R_BRACKET",
616
+ "/": "BACKSLASH",
617
+ "=": "EQUALS",
618
+ "&": "XSS_AMP",
619
+ "<": "XSS_LT",
620
+ ">": "XSS_GT",
621
+ '"': "XSS_D_QUOTE",
622
+ "'": "XSS_S_QUOTE"
682
623
  };
683
624
  class Lexer {
684
625
  tokenize(input) {
@@ -693,7 +634,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
693
634
  const length2 = match.index - offset;
694
635
  if (length2 > 0) {
695
636
  tokens.push({
696
- type: TokenType.STR,
637
+ type: "STR",
697
638
  offset,
698
639
  length: length2
699
640
  });
@@ -701,34 +642,34 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
701
642
  offset = match.index;
702
643
  if (match[0] === "[/") {
703
644
  tokens.push({
704
- type: TokenType.L_BRACKET,
645
+ type: "L_BRACKET",
705
646
  offset,
706
647
  length: 1
707
648
  });
708
649
  offset += 1;
709
650
  tokens.push({
710
- type: TokenType.BACKSLASH,
651
+ type: "BACKSLASH",
711
652
  offset,
712
653
  length: 1
713
654
  });
714
655
  offset += 1;
715
656
  } else if (match[0].startsWith("[")) {
716
657
  tokens.push({
717
- type: TokenType.L_BRACKET,
658
+ type: "L_BRACKET",
718
659
  offset,
719
660
  length: 1
720
661
  });
721
662
  offset += 1;
722
663
  const length3 = match[0].length - 1;
723
664
  tokens.push({
724
- type: TokenType.STR,
665
+ type: "STR",
725
666
  offset,
726
667
  length: length3
727
668
  });
728
669
  offset += length3;
729
670
  } else {
730
671
  tokens.push({
731
- type: symbolTable[match[0]] ?? TokenType.STR,
672
+ type: symbolTable[match[0]] ?? "STR",
732
673
  offset,
733
674
  length: 1
734
675
  });
@@ -738,7 +679,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
738
679
  const length = input.length - offset;
739
680
  if (length > 0) {
740
681
  tokens.push({
741
- type: TokenType.STR,
682
+ type: "STR",
742
683
  offset,
743
684
  length
744
685
  });
@@ -750,47 +691,47 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
750
691
  let s = "";
751
692
  for (const token of tokens) {
752
693
  switch (token.type) {
753
- case TokenType.STR: {
694
+ case "STR": {
754
695
  s += ogText.substring(token.offset, token.offset + token.length);
755
696
  break;
756
697
  }
757
- case TokenType.LINEBREAK: {
698
+ case "LINEBREAK": {
758
699
  s += "\n";
759
700
  break;
760
701
  }
761
- case TokenType.L_BRACKET: {
702
+ case "L_BRACKET": {
762
703
  s += "[";
763
704
  break;
764
705
  }
765
- case TokenType.R_BRACKET: {
706
+ case "R_BRACKET": {
766
707
  s += "]";
767
708
  break;
768
709
  }
769
- case TokenType.BACKSLASH: {
710
+ case "BACKSLASH": {
770
711
  s += "/";
771
712
  break;
772
713
  }
773
- case TokenType.EQUALS: {
714
+ case "EQUALS": {
774
715
  s += "=";
775
716
  break;
776
717
  }
777
- case TokenType.XSS_AMP: {
718
+ case "XSS_AMP": {
778
719
  s += "&amp;";
779
720
  break;
780
721
  }
781
- case TokenType.XSS_LT: {
722
+ case "XSS_LT": {
782
723
  s += "&lt;";
783
724
  break;
784
725
  }
785
- case TokenType.XSS_GT: {
726
+ case "XSS_GT": {
786
727
  s += "&gt;";
787
728
  break;
788
729
  }
789
- case TokenType.XSS_D_QUOTE: {
730
+ case "XSS_D_QUOTE": {
790
731
  s += "&quot;";
791
732
  break;
792
733
  }
793
- case TokenType.XSS_S_QUOTE: {
734
+ case "XSS_S_QUOTE": {
794
735
  s += "&#x27;";
795
736
  break;
796
737
  }
@@ -799,10 +740,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
799
740
  return s;
800
741
  }
801
742
  class Parser {
743
+ tags;
744
+ linebreakTerminatedTags;
745
+ standaloneTags;
802
746
  constructor(transforms = htmlTransforms) {
803
- __publicField(this, "tags");
804
- __publicField(this, "linebreakTerminatedTags");
805
- __publicField(this, "standaloneTags");
806
747
  this.tags = new Set(transforms.map((transform) => transform.name));
807
748
  this.linebreakTerminatedTags = new Set(transforms.filter((transform) => transform.isLinebreakTerminated).map((transform) => transform.name.toLowerCase()));
808
749
  this.standaloneTags = new Set(transforms.filter((transform) => transform.isStandalone).map((transform) => transform.name.toLowerCase()));
@@ -821,7 +762,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
821
762
  if (!isStringToken(tokens[idx].type)) {
822
763
  break;
823
764
  }
824
- if (endOnQuotes && (tokens[idx].type === TokenType.XSS_S_QUOTE || tokens[idx].type === TokenType.XSS_D_QUOTE)) {
765
+ if (endOnQuotes && (tokens[idx].type === "XSS_S_QUOTE" || tokens[idx].type === "XSS_D_QUOTE")) {
825
766
  break;
826
767
  }
827
768
  if (endOnSpace && !endOnQuotes) {
@@ -829,12 +770,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
829
770
  const spaceIdx = origStr.indexOf(" ");
830
771
  if (spaceIdx >= 0) {
831
772
  const oldToken = {
832
- type: TokenType.STR,
773
+ type: "STR",
833
774
  offset: tokens[idx].offset,
834
775
  length: spaceIdx
835
776
  };
836
777
  const newToken = {
837
- type: TokenType.STR,
778
+ type: "STR",
838
779
  offset: tokens[idx].offset + spaceIdx,
839
780
  length: tokens[idx].length - spaceIdx
840
781
  };
@@ -855,37 +796,37 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
855
796
  return null;
856
797
  }
857
798
  const attrNode = new AttrNode();
858
- if (tokens[idx].type === TokenType.EQUALS && isStringToken(tokens[idx + 1].type)) {
799
+ if (tokens[idx].type === "EQUALS" && isStringToken(tokens[idx + 1].type)) {
859
800
  idx += 1;
860
- const openedWithQuotes = tokens[idx].type === TokenType.XSS_S_QUOTE || tokens[idx].type === TokenType.XSS_D_QUOTE;
801
+ const openedWithQuotes = tokens[idx].type === "XSS_S_QUOTE" || tokens[idx].type === "XSS_D_QUOTE";
861
802
  if (openedWithQuotes) {
862
803
  idx += 1;
863
804
  }
864
805
  const valNode = parseText(openedWithQuotes, true);
865
806
  attrNode.addChild(valNode);
866
807
  if (openedWithQuotes) {
867
- if (tokens[idx].type !== TokenType.XSS_S_QUOTE && tokens[idx].type !== TokenType.XSS_D_QUOTE) {
808
+ if (tokens[idx].type !== "XSS_S_QUOTE" && tokens[idx].type !== "XSS_D_QUOTE") {
868
809
  return null;
869
810
  }
870
811
  idx += 1;
871
812
  }
872
- } else if (isStringToken(tokens[idx].type) && tokens[idx + 1].type === TokenType.EQUALS && (idx + 2 < tokens.length && isStringToken(tokens[idx + 2].type))) {
813
+ } else if (isStringToken(tokens[idx].type) && tokens[idx + 1].type === "EQUALS" && (idx + 2 < tokens.length && isStringToken(tokens[idx + 2].type))) {
873
814
  const keyNode = parseText();
874
815
  attrNode.addChild(keyNode);
875
816
  idx += 1;
876
- const openedWithQuotes = tokens[idx].type === TokenType.XSS_S_QUOTE || tokens[idx].type === TokenType.XSS_D_QUOTE;
817
+ const openedWithQuotes = tokens[idx].type === "XSS_S_QUOTE" || tokens[idx].type === "XSS_D_QUOTE";
877
818
  if (openedWithQuotes) {
878
819
  idx += 1;
879
820
  }
880
821
  const valNode = parseText(openedWithQuotes, true);
881
822
  if (openedWithQuotes) {
882
- if (tokens[idx].type !== TokenType.XSS_S_QUOTE && tokens[idx].type !== TokenType.XSS_D_QUOTE) {
823
+ if (tokens[idx].type !== "XSS_S_QUOTE" && tokens[idx].type !== "XSS_D_QUOTE") {
883
824
  return null;
884
825
  }
885
826
  idx += 1;
886
827
  }
887
828
  attrNode.addChild(valNode);
888
- } else if (isStringToken(tokens[idx].type) && tokens[idx + 1].type !== TokenType.EQUALS) {
829
+ } else if (isStringToken(tokens[idx].type) && tokens[idx + 1].type !== "EQUALS") {
889
830
  const valNode = parseText();
890
831
  attrNode.addChild(valNode);
891
832
  } else {
@@ -897,7 +838,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
897
838
  if (idx + 1 >= tokens.length) {
898
839
  return null;
899
840
  }
900
- if (tokens[idx].type !== TokenType.L_BRACKET) {
841
+ if (tokens[idx].type !== "L_BRACKET") {
901
842
  return null;
902
843
  }
903
844
  if (isStringToken(tokens[idx + 1].type)) {
@@ -915,7 +856,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
915
856
  }
916
857
  attrNodes.push(attrNode);
917
858
  }
918
- if (tokens[idx].type !== TokenType.R_BRACKET) {
859
+ if (tokens[idx].type !== "R_BRACKET") {
919
860
  return null;
920
861
  }
921
862
  idx += 1;
@@ -924,7 +865,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
924
865
  const startTagNode = new StartTagNode(labelText, ogTag, attrNodes);
925
866
  return startTagNode;
926
867
  }
927
- if (tokens[idx + 1].type === TokenType.BACKSLASH) {
868
+ if (tokens[idx + 1].type === "BACKSLASH") {
928
869
  const startIdx = idx;
929
870
  idx += 1;
930
871
  idx += 1;
@@ -932,7 +873,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
932
873
  if (!this.tags.has(labelText)) {
933
874
  return null;
934
875
  }
935
- if (tokens[idx].type !== TokenType.R_BRACKET) {
876
+ if (tokens[idx].type !== "R_BRACKET") {
936
877
  return null;
937
878
  }
938
879
  idx += 1;
@@ -946,7 +887,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
946
887
  const parseRoot = () => {
947
888
  const root2 = new RootNode();
948
889
  while (idx < tokens.length) {
949
- if (tokens[idx].type === TokenType.L_BRACKET) {
890
+ if (tokens[idx].type === "L_BRACKET") {
950
891
  const startIdx = idx;
951
892
  const tagNode = parseTag();
952
893
  if (tagNode !== null) {
@@ -957,12 +898,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
957
898
  const textNode = new TextNode(str);
958
899
  root2.addChild(textNode);
959
900
  }
960
- } else if (tokens[idx].type === TokenType.LINEBREAK) {
901
+ } else if (tokens[idx].type === "LINEBREAK") {
961
902
  idx += 1;
962
903
  root2.addChild(new LinebreakNode());
963
904
  } else {
964
905
  const startIdx = idx;
965
- while (idx < tokens.length && tokens[idx].type !== TokenType.L_BRACKET && tokens[idx].type !== TokenType.LINEBREAK) {
906
+ while (idx < tokens.length && tokens[idx].type !== "L_BRACKET" && tokens[idx].type !== "LINEBREAK") {
966
907
  idx += 1;
967
908
  }
968
909
  const slice = tokens.slice(startIdx, idx);
@@ -983,11 +924,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
983
924
  const transformedRoot = new RootNode();
984
925
  for (let i = 0; i < rootNode.children.length; i++) {
985
926
  const child = rootNode.children[i];
986
- if (nodeIsType(child, AstNodeType.StartTagNode)) {
927
+ if (nodeIsType(child, "StartTagNode")) {
987
928
  const endTag = this.findMatchingEndTag(rootNode.children, i, child.tagName);
988
929
  const isStandalone = this.standaloneTags.has(child.tagName);
989
930
  if (endTag || isStandalone) {
990
- const tagNode = new TagNode(child, endTag == null ? void 0 : endTag.node);
931
+ const tagNode = new TagNode(child, endTag?.node);
991
932
  transformedRoot.addChild(tagNode);
992
933
  if (endTag) {
993
934
  const subRoot = new RootNode(rootNode.children.slice(i + 1, endTag.idx));
@@ -998,11 +939,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
998
939
  } else {
999
940
  transformedRoot.addChild(new TextNode(child.ogTag));
1000
941
  }
1001
- } else if (nodeIsType(child, AstNodeType.EndTagNode)) {
942
+ } else if (nodeIsType(child, "EndTagNode")) {
1002
943
  transformedRoot.addChild(new TextNode(child.ogTag));
1003
- } else if (nodeIsType(child, AstNodeType.TextNode)) {
944
+ } else if (nodeIsType(child, "TextNode")) {
1004
945
  transformedRoot.addChild(child);
1005
- } else if (nodeIsType(child, AstNodeType.LinebreakNode)) {
946
+ } else if (nodeIsType(child, "LinebreakNode")) {
1006
947
  transformedRoot.addChild(child);
1007
948
  } else {
1008
949
  throw new Error("Unexpected child of RootNode");
@@ -1016,7 +957,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1016
957
  }
1017
958
  for (let i = startIdx; i < siblings.length; i++) {
1018
959
  const sibling = siblings[i];
1019
- const isEndTag = nodeIsType(sibling, AstNodeType.LinebreakNode) && this.linebreakTerminatedTags.has(tagName) || nodeIsType(sibling, AstNodeType.EndTagNode) && sibling.tagName === tagName;
960
+ const isEndTag = nodeIsType(sibling, "LinebreakNode") && this.linebreakTerminatedTags.has(tagName) || nodeIsType(sibling, "EndTagNode") && sibling.tagName === tagName;
1020
961
  if (isEndTag) {
1021
962
  return {
1022
963
  idx: i,
@@ -1036,7 +977,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1036
977
  return generator.generate(root);
1037
978
  }
1038
979
  exports2.AstNode = AstNode;
1039
- exports2.AstNodeType = AstNodeType;
1040
980
  exports2.AttrNode = AttrNode;
1041
981
  exports2.EndTagNode = EndTagNode;
1042
982
  exports2.Generator = Generator;
@@ -1047,7 +987,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1047
987
  exports2.StartTagNode = StartTagNode;
1048
988
  exports2.TagNode = TagNode;
1049
989
  exports2.TextNode = TextNode;
1050
- exports2.TokenType = TokenType;
1051
990
  exports2.generateHtml = generateHtml;
1052
991
  exports2.getTagImmediateAttrVal = getTagImmediateAttrVal;
1053
992
  exports2.getTagImmediateText = getTagImmediateText;
@@ -1061,5 +1000,5 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1061
1000
  exports2.symbolTable = symbolTable;
1062
1001
  exports2.tokenTypeToString = tokenTypeToString;
1063
1002
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
1064
- });
1003
+ }));
1065
1004
  //# sourceMappingURL=index.umd.cjs.map