htmljs-parser 5.2.4 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -272,6 +272,8 @@ var Parser = class {
272
272
  cur++;
273
273
  if (this.lookAheadFor(str, cur)) {
274
274
  this.pos = cur;
275
+ if (this.forward > 1)
276
+ this.forward = 1;
275
277
  return true;
276
278
  }
277
279
  return false;
@@ -420,7 +422,7 @@ var OPEN_TAG = {
420
422
  hasArgs: false,
421
423
  hasAttrs: false,
422
424
  hasParams: false,
423
- types: void 0,
425
+ typeParams: void 0,
424
426
  selfClosed: false,
425
427
  shorthandEnd: -1,
426
428
  tagName: void 0,
@@ -458,7 +460,7 @@ var OPEN_TAG = {
458
460
  }
459
461
  },
460
462
  eol(_, tag) {
461
- if (this.isConcise && tag.stage !== 5 /* ATTR_GROUP */) {
463
+ if (this.isConcise && tag.stage !== 5 /* ATTR_GROUP */ && !this.consumeWhitespaceIfBefore(",")) {
462
464
  this.exitState();
463
465
  }
464
466
  },
@@ -668,7 +670,7 @@ var OPEN_TAG = {
668
670
  }
669
671
  },
670
672
  return(child, tag) {
671
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
673
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
672
674
  if (child.state !== states_exports.EXPRESSION)
673
675
  return;
674
676
  switch (tag.stage) {
@@ -691,7 +693,7 @@ var OPEN_TAG = {
691
693
  break;
692
694
  }
693
695
  case 2 /* ARGUMENT */: {
694
- const { types } = tag;
696
+ const { typeParams } = tag;
695
697
  const start = child.start - 1;
696
698
  const end = ++this.pos;
697
699
  const value = {
@@ -700,9 +702,9 @@ var OPEN_TAG = {
700
702
  };
701
703
  if (this.consumeWhitespaceIfBefore("{")) {
702
704
  const attr = this.enterState(states_exports.ATTRIBUTE);
703
- if (types) {
704
- attr.start = types.start;
705
- attr.typeParams = types;
705
+ if (typeParams) {
706
+ attr.start = typeParams.start;
707
+ attr.typeParams = typeParams;
706
708
  } else {
707
709
  attr.start = start;
708
710
  }
@@ -710,10 +712,15 @@ var OPEN_TAG = {
710
712
  this.forward = 0;
711
713
  tag.hasAttrs = true;
712
714
  } else {
713
- if (types) {
714
- (_d = (_c = this.options).onTagTypeArgs) == null ? void 0 : _d.call(_c, types);
715
+ if (typeParams) {
716
+ this.emitError(
717
+ child,
718
+ 27 /* INVALID_TAG_TYPES */,
719
+ "Unexpected types. Type arguments must directly follow a tag name and type paremeters must precede a method or tag parameters."
720
+ );
721
+ break;
715
722
  }
716
- (_f = (_e = this.options).onTagArgs) == null ? void 0 : _f.call(_e, {
723
+ (_d = (_c = this.options).onTagArgs) == null ? void 0 : _d.call(_c, {
717
724
  start,
718
725
  end,
719
726
  value
@@ -722,9 +729,9 @@ var OPEN_TAG = {
722
729
  break;
723
730
  }
724
731
  case 3 /* TYPES */: {
725
- const { types, hasParams, hasArgs } = tag;
732
+ const { typeParams, hasParams, hasArgs } = tag;
726
733
  const end = ++this.pos;
727
- const typeArgs = {
734
+ const types = {
728
735
  start: child.start - 1,
729
736
  end,
730
737
  value: {
@@ -732,33 +739,28 @@ var OPEN_TAG = {
732
739
  end: child.end
733
740
  }
734
741
  };
742
+ if (tag.tagName.end === types.start) {
743
+ (_f = (_e = this.options).onTagTypeArgs) == null ? void 0 : _f.call(_e, types);
744
+ break;
745
+ }
735
746
  this.consumeWhitespace();
736
747
  const nextCode = this.lookAtCharCodeAhead(0);
737
- if (!hasParams && nextCode === 124 /* PIPE */) {
738
- if (types) {
739
- (_h = (_g = this.options).onTagTypeArgs) == null ? void 0 : _h.call(_g, types);
740
- }
741
- (_j = (_i = this.options).onTagTypeParams) == null ? void 0 : _j.call(_i, typeArgs);
742
- } else if (!hasArgs && nextCode === 40 /* OPEN_PAREN */) {
743
- if (types) {
744
- (_l = (_k = this.options).onTagTypeArgs) == null ? void 0 : _l.call(_k, types);
745
- }
746
- tag.types = typeArgs;
747
- } else if (!(types || hasParams || hasArgs)) {
748
- (_n = (_m = this.options).onTagTypeArgs) == null ? void 0 : _n.call(_m, typeArgs);
749
- tag.types = typeArgs;
748
+ if (nextCode === 124 /* PIPE */ && !hasParams) {
749
+ (_h = (_g = this.options).onTagTypeParams) == null ? void 0 : _h.call(_g, types);
750
+ } else if (nextCode === 40 /* OPEN_PAREN */ && !(typeParams || hasParams || hasArgs)) {
751
+ tag.typeParams = types;
750
752
  } else {
751
753
  this.emitError(
752
754
  child,
753
755
  27 /* INVALID_TAG_TYPES */,
754
- "Unexpected types. Type arguments must follow a tag name and type paremeters must precede a method or tag parameters."
756
+ "Unexpected types. Type arguments must directly follow a tag name and type paremeters must precede a method or tag parameters."
755
757
  );
756
758
  }
757
759
  break;
758
760
  }
759
761
  case 4 /* PARAMS */: {
760
762
  const end = ++this.pos;
761
- (_p = (_o = this.options).onTagParams) == null ? void 0 : _p.call(_o, {
763
+ (_j = (_i = this.options).onTagParams) == null ? void 0 : _j.call(_i, {
762
764
  start: child.start - 1,
763
765
  end,
764
766
  value: {
@@ -1781,11 +1783,14 @@ function lookBehindForOperator(data, pos) {
1781
1783
  case 60 /* OPEN_ANGLE_BRACKET */:
1782
1784
  case 62 /* CLOSE_ANGLE_BRACKET */:
1783
1785
  case 37 /* PERCENT */:
1784
- case 46 /* PERIOD */:
1785
1786
  case 124 /* PIPE */:
1786
1787
  case 63 /* QUESTION */:
1787
1788
  case 126 /* TILDE */:
1788
1789
  return curPos;
1790
+ case 46 /* PERIOD */: {
1791
+ const nextPos = lookAheadWhile(isWhitespaceCode, data, pos);
1792
+ return isWordCode(data.charCodeAt(nextPos)) ? nextPos : -1;
1793
+ }
1789
1794
  case 43 /* PLUS */:
1790
1795
  case 45 /* HYPHEN */: {
1791
1796
  if (data.charCodeAt(curPos - 1) === code) {
@@ -1828,8 +1833,10 @@ function lookAheadForOperator(data, pos) {
1828
1833
  case 123 /* OPEN_CURLY_BRACE */:
1829
1834
  case 40 /* OPEN_PAREN */:
1830
1835
  return pos;
1831
- case 46 /* PERIOD */:
1832
- return data.charCodeAt(pos + 1) === 46 /* PERIOD */ ? -1 : pos + 1;
1836
+ case 46 /* PERIOD */: {
1837
+ const nextPos = lookAheadWhile(isWhitespaceCode, data, pos + 1);
1838
+ return isWordCode(data.charCodeAt(nextPos)) ? nextPos : -1;
1839
+ }
1833
1840
  default: {
1834
1841
  for (const keyword of binaryKeywords) {
1835
1842
  let nextPos = lookAheadFor(data, pos, keyword);
@@ -1867,7 +1874,7 @@ function canFollowDivision(code) {
1867
1874
  return isWordCode(code) || code === 37 /* PERCENT */ || code === 41 /* CLOSE_PAREN */ || code === 46 /* PERIOD */ || code === 60 /* OPEN_ANGLE_BRACKET */ || code === 93 /* CLOSE_SQUARE_BRACKET */ || code === 125 /* CLOSE_CURLY_BRACE */;
1868
1875
  }
1869
1876
  function isWordCode(code) {
1870
- return code >= 65 /* UPPER_A */ && code <= 90 /* UPPER_Z */ || code >= 97 /* LOWER_A */ && code <= 122 /* LOWER_Z */ || code >= 48 /* NUMBER_0 */ && code <= 57 /* NUMBER_9 */ || code === 95 /* UNDERSCORE */;
1877
+ return code >= 65 /* UPPER_A */ && code <= 90 /* UPPER_Z */ || code >= 97 /* LOWER_A */ && code <= 122 /* LOWER_Z */ || code >= 48 /* NUMBER_0 */ && code <= 57 /* NUMBER_9 */ || code == 36 /* DOLLAR */ || code === 95 /* UNDERSCORE */;
1871
1878
  }
1872
1879
  function isIndentCode(code) {
1873
1880
  return code === 9 /* TAB */ || code === 32 /* SPACE */;
@@ -2521,7 +2528,7 @@ var TAG_NAME = {
2521
2528
  this.pos += 2;
2522
2529
  this.forward = 0;
2523
2530
  this.enterState(states_exports.EXPRESSION).shouldTerminate = matchesCloseCurlyBrace;
2524
- } else if (isWhitespaceCode(code) || code === 61 /* EQUAL */ || code === 58 /* COLON */ && this.lookAtCharCodeAhead(1) === 61 /* EQUAL */ || code === 40 /* OPEN_PAREN */ || code === 47 /* FORWARD_SLASH */ || code === 124 /* PIPE */ || code === 60 /* OPEN_ANGLE_BRACKET */ || (this.isConcise ? code === 59 /* SEMICOLON */ : code === 62 /* CLOSE_ANGLE_BRACKET */)) {
2531
+ } else if (isWhitespaceCode(code) || code === 61 /* EQUAL */ || code === 58 /* COLON */ && this.lookAtCharCodeAhead(1) === 61 /* EQUAL */ || code === 40 /* OPEN_PAREN */ || code === 47 /* FORWARD_SLASH */ || code === 124 /* PIPE */ || code === 60 /* OPEN_ANGLE_BRACKET */ || code === 44 /* COMMA */ || (this.isConcise ? code === 59 /* SEMICOLON */ : code === 62 /* CLOSE_ANGLE_BRACKET */)) {
2525
2532
  this.activeTag.shorthandEnd = this.pos;
2526
2533
  this.exitState();
2527
2534
  } else if (code === 46 /* PERIOD */ || code === 35 /* NUMBER_SIGN */) {
package/dist/index.mjs CHANGED
@@ -247,6 +247,8 @@ var Parser = class {
247
247
  cur++;
248
248
  if (this.lookAheadFor(str, cur)) {
249
249
  this.pos = cur;
250
+ if (this.forward > 1)
251
+ this.forward = 1;
250
252
  return true;
251
253
  }
252
254
  return false;
@@ -395,7 +397,7 @@ var OPEN_TAG = {
395
397
  hasArgs: false,
396
398
  hasAttrs: false,
397
399
  hasParams: false,
398
- types: void 0,
400
+ typeParams: void 0,
399
401
  selfClosed: false,
400
402
  shorthandEnd: -1,
401
403
  tagName: void 0,
@@ -433,7 +435,7 @@ var OPEN_TAG = {
433
435
  }
434
436
  },
435
437
  eol(_, tag) {
436
- if (this.isConcise && tag.stage !== 5 /* ATTR_GROUP */) {
438
+ if (this.isConcise && tag.stage !== 5 /* ATTR_GROUP */ && !this.consumeWhitespaceIfBefore(",")) {
437
439
  this.exitState();
438
440
  }
439
441
  },
@@ -643,7 +645,7 @@ var OPEN_TAG = {
643
645
  }
644
646
  },
645
647
  return(child, tag) {
646
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
648
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
647
649
  if (child.state !== states_exports.EXPRESSION)
648
650
  return;
649
651
  switch (tag.stage) {
@@ -666,7 +668,7 @@ var OPEN_TAG = {
666
668
  break;
667
669
  }
668
670
  case 2 /* ARGUMENT */: {
669
- const { types } = tag;
671
+ const { typeParams } = tag;
670
672
  const start = child.start - 1;
671
673
  const end = ++this.pos;
672
674
  const value = {
@@ -675,9 +677,9 @@ var OPEN_TAG = {
675
677
  };
676
678
  if (this.consumeWhitespaceIfBefore("{")) {
677
679
  const attr = this.enterState(states_exports.ATTRIBUTE);
678
- if (types) {
679
- attr.start = types.start;
680
- attr.typeParams = types;
680
+ if (typeParams) {
681
+ attr.start = typeParams.start;
682
+ attr.typeParams = typeParams;
681
683
  } else {
682
684
  attr.start = start;
683
685
  }
@@ -685,10 +687,15 @@ var OPEN_TAG = {
685
687
  this.forward = 0;
686
688
  tag.hasAttrs = true;
687
689
  } else {
688
- if (types) {
689
- (_d = (_c = this.options).onTagTypeArgs) == null ? void 0 : _d.call(_c, types);
690
+ if (typeParams) {
691
+ this.emitError(
692
+ child,
693
+ 27 /* INVALID_TAG_TYPES */,
694
+ "Unexpected types. Type arguments must directly follow a tag name and type paremeters must precede a method or tag parameters."
695
+ );
696
+ break;
690
697
  }
691
- (_f = (_e = this.options).onTagArgs) == null ? void 0 : _f.call(_e, {
698
+ (_d = (_c = this.options).onTagArgs) == null ? void 0 : _d.call(_c, {
692
699
  start,
693
700
  end,
694
701
  value
@@ -697,9 +704,9 @@ var OPEN_TAG = {
697
704
  break;
698
705
  }
699
706
  case 3 /* TYPES */: {
700
- const { types, hasParams, hasArgs } = tag;
707
+ const { typeParams, hasParams, hasArgs } = tag;
701
708
  const end = ++this.pos;
702
- const typeArgs = {
709
+ const types = {
703
710
  start: child.start - 1,
704
711
  end,
705
712
  value: {
@@ -707,33 +714,28 @@ var OPEN_TAG = {
707
714
  end: child.end
708
715
  }
709
716
  };
717
+ if (tag.tagName.end === types.start) {
718
+ (_f = (_e = this.options).onTagTypeArgs) == null ? void 0 : _f.call(_e, types);
719
+ break;
720
+ }
710
721
  this.consumeWhitespace();
711
722
  const nextCode = this.lookAtCharCodeAhead(0);
712
- if (!hasParams && nextCode === 124 /* PIPE */) {
713
- if (types) {
714
- (_h = (_g = this.options).onTagTypeArgs) == null ? void 0 : _h.call(_g, types);
715
- }
716
- (_j = (_i = this.options).onTagTypeParams) == null ? void 0 : _j.call(_i, typeArgs);
717
- } else if (!hasArgs && nextCode === 40 /* OPEN_PAREN */) {
718
- if (types) {
719
- (_l = (_k = this.options).onTagTypeArgs) == null ? void 0 : _l.call(_k, types);
720
- }
721
- tag.types = typeArgs;
722
- } else if (!(types || hasParams || hasArgs)) {
723
- (_n = (_m = this.options).onTagTypeArgs) == null ? void 0 : _n.call(_m, typeArgs);
724
- tag.types = typeArgs;
723
+ if (nextCode === 124 /* PIPE */ && !hasParams) {
724
+ (_h = (_g = this.options).onTagTypeParams) == null ? void 0 : _h.call(_g, types);
725
+ } else if (nextCode === 40 /* OPEN_PAREN */ && !(typeParams || hasParams || hasArgs)) {
726
+ tag.typeParams = types;
725
727
  } else {
726
728
  this.emitError(
727
729
  child,
728
730
  27 /* INVALID_TAG_TYPES */,
729
- "Unexpected types. Type arguments must follow a tag name and type paremeters must precede a method or tag parameters."
731
+ "Unexpected types. Type arguments must directly follow a tag name and type paremeters must precede a method or tag parameters."
730
732
  );
731
733
  }
732
734
  break;
733
735
  }
734
736
  case 4 /* PARAMS */: {
735
737
  const end = ++this.pos;
736
- (_p = (_o = this.options).onTagParams) == null ? void 0 : _p.call(_o, {
738
+ (_j = (_i = this.options).onTagParams) == null ? void 0 : _j.call(_i, {
737
739
  start: child.start - 1,
738
740
  end,
739
741
  value: {
@@ -1756,11 +1758,14 @@ function lookBehindForOperator(data, pos) {
1756
1758
  case 60 /* OPEN_ANGLE_BRACKET */:
1757
1759
  case 62 /* CLOSE_ANGLE_BRACKET */:
1758
1760
  case 37 /* PERCENT */:
1759
- case 46 /* PERIOD */:
1760
1761
  case 124 /* PIPE */:
1761
1762
  case 63 /* QUESTION */:
1762
1763
  case 126 /* TILDE */:
1763
1764
  return curPos;
1765
+ case 46 /* PERIOD */: {
1766
+ const nextPos = lookAheadWhile(isWhitespaceCode, data, pos);
1767
+ return isWordCode(data.charCodeAt(nextPos)) ? nextPos : -1;
1768
+ }
1764
1769
  case 43 /* PLUS */:
1765
1770
  case 45 /* HYPHEN */: {
1766
1771
  if (data.charCodeAt(curPos - 1) === code) {
@@ -1803,8 +1808,10 @@ function lookAheadForOperator(data, pos) {
1803
1808
  case 123 /* OPEN_CURLY_BRACE */:
1804
1809
  case 40 /* OPEN_PAREN */:
1805
1810
  return pos;
1806
- case 46 /* PERIOD */:
1807
- return data.charCodeAt(pos + 1) === 46 /* PERIOD */ ? -1 : pos + 1;
1811
+ case 46 /* PERIOD */: {
1812
+ const nextPos = lookAheadWhile(isWhitespaceCode, data, pos + 1);
1813
+ return isWordCode(data.charCodeAt(nextPos)) ? nextPos : -1;
1814
+ }
1808
1815
  default: {
1809
1816
  for (const keyword of binaryKeywords) {
1810
1817
  let nextPos = lookAheadFor(data, pos, keyword);
@@ -1842,7 +1849,7 @@ function canFollowDivision(code) {
1842
1849
  return isWordCode(code) || code === 37 /* PERCENT */ || code === 41 /* CLOSE_PAREN */ || code === 46 /* PERIOD */ || code === 60 /* OPEN_ANGLE_BRACKET */ || code === 93 /* CLOSE_SQUARE_BRACKET */ || code === 125 /* CLOSE_CURLY_BRACE */;
1843
1850
  }
1844
1851
  function isWordCode(code) {
1845
- return code >= 65 /* UPPER_A */ && code <= 90 /* UPPER_Z */ || code >= 97 /* LOWER_A */ && code <= 122 /* LOWER_Z */ || code >= 48 /* NUMBER_0 */ && code <= 57 /* NUMBER_9 */ || code === 95 /* UNDERSCORE */;
1852
+ return code >= 65 /* UPPER_A */ && code <= 90 /* UPPER_Z */ || code >= 97 /* LOWER_A */ && code <= 122 /* LOWER_Z */ || code >= 48 /* NUMBER_0 */ && code <= 57 /* NUMBER_9 */ || code == 36 /* DOLLAR */ || code === 95 /* UNDERSCORE */;
1846
1853
  }
1847
1854
  function isIndentCode(code) {
1848
1855
  return code === 9 /* TAB */ || code === 32 /* SPACE */;
@@ -2496,7 +2503,7 @@ var TAG_NAME = {
2496
2503
  this.pos += 2;
2497
2504
  this.forward = 0;
2498
2505
  this.enterState(states_exports.EXPRESSION).shouldTerminate = matchesCloseCurlyBrace;
2499
- } else if (isWhitespaceCode(code) || code === 61 /* EQUAL */ || code === 58 /* COLON */ && this.lookAtCharCodeAhead(1) === 61 /* EQUAL */ || code === 40 /* OPEN_PAREN */ || code === 47 /* FORWARD_SLASH */ || code === 124 /* PIPE */ || code === 60 /* OPEN_ANGLE_BRACKET */ || (this.isConcise ? code === 59 /* SEMICOLON */ : code === 62 /* CLOSE_ANGLE_BRACKET */)) {
2506
+ } else if (isWhitespaceCode(code) || code === 61 /* EQUAL */ || code === 58 /* COLON */ && this.lookAtCharCodeAhead(1) === 61 /* EQUAL */ || code === 40 /* OPEN_PAREN */ || code === 47 /* FORWARD_SLASH */ || code === 124 /* PIPE */ || code === 60 /* OPEN_ANGLE_BRACKET */ || code === 44 /* COMMA */ || (this.isConcise ? code === 59 /* SEMICOLON */ : code === 62 /* CLOSE_ANGLE_BRACKET */)) {
2500
2507
  this.activeTag.shorthandEnd = this.pos;
2501
2508
  this.exitState();
2502
2509
  } else if (code === 46 /* PERIOD */ || code === 35 /* NUMBER_SIGN */) {
@@ -17,7 +17,7 @@ export interface OpenTagMeta extends Meta {
17
17
  hasArgs: boolean;
18
18
  hasAttrs: boolean;
19
19
  hasParams: boolean;
20
- types: undefined | Ranges.Value;
20
+ typeParams: undefined | Ranges.Value;
21
21
  hasShorthandId: boolean;
22
22
  selfClosed: boolean;
23
23
  indent: string;
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": "5.2.4",
4
+ "version": "5.4.0",
5
5
  "devDependencies": {
6
6
  "@changesets/changelog-github": "^0.4.7",
7
7
  "@changesets/cli": "^2.25.2",