htmljs-parser 5.2.3 → 5.3.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
@@ -420,7 +420,7 @@ var OPEN_TAG = {
420
420
  hasArgs: false,
421
421
  hasAttrs: false,
422
422
  hasParams: false,
423
- types: void 0,
423
+ typeParams: void 0,
424
424
  selfClosed: false,
425
425
  shorthandEnd: -1,
426
426
  tagName: void 0,
@@ -668,7 +668,7 @@ var OPEN_TAG = {
668
668
  }
669
669
  },
670
670
  return(child, tag) {
671
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
671
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
672
672
  if (child.state !== states_exports.EXPRESSION)
673
673
  return;
674
674
  switch (tag.stage) {
@@ -691,7 +691,7 @@ var OPEN_TAG = {
691
691
  break;
692
692
  }
693
693
  case 2 /* ARGUMENT */: {
694
- const { types } = tag;
694
+ const { typeParams } = tag;
695
695
  const start = child.start - 1;
696
696
  const end = ++this.pos;
697
697
  const value = {
@@ -700,9 +700,9 @@ var OPEN_TAG = {
700
700
  };
701
701
  if (this.consumeWhitespaceIfBefore("{")) {
702
702
  const attr = this.enterState(states_exports.ATTRIBUTE);
703
- if (types) {
704
- attr.start = types.start;
705
- attr.typeParams = types;
703
+ if (typeParams) {
704
+ attr.start = typeParams.start;
705
+ attr.typeParams = typeParams;
706
706
  } else {
707
707
  attr.start = start;
708
708
  }
@@ -710,10 +710,15 @@ var OPEN_TAG = {
710
710
  this.forward = 0;
711
711
  tag.hasAttrs = true;
712
712
  } else {
713
- if (types) {
714
- (_d = (_c = this.options).onTagTypeArgs) == null ? void 0 : _d.call(_c, types);
713
+ if (typeParams) {
714
+ this.emitError(
715
+ child,
716
+ 27 /* INVALID_TAG_TYPES */,
717
+ "Unexpected types. Type arguments must directly follow a tag name and type paremeters must precede a method or tag parameters."
718
+ );
719
+ break;
715
720
  }
716
- (_f = (_e = this.options).onTagArgs) == null ? void 0 : _f.call(_e, {
721
+ (_d = (_c = this.options).onTagArgs) == null ? void 0 : _d.call(_c, {
717
722
  start,
718
723
  end,
719
724
  value
@@ -722,9 +727,9 @@ var OPEN_TAG = {
722
727
  break;
723
728
  }
724
729
  case 3 /* TYPES */: {
725
- const { types, hasParams, hasArgs } = tag;
730
+ const { typeParams, hasParams, hasArgs } = tag;
726
731
  const end = ++this.pos;
727
- const typeArgs = {
732
+ const types = {
728
733
  start: child.start - 1,
729
734
  end,
730
735
  value: {
@@ -732,33 +737,28 @@ var OPEN_TAG = {
732
737
  end: child.end
733
738
  }
734
739
  };
740
+ if (tag.tagName.end === types.start) {
741
+ (_f = (_e = this.options).onTagTypeArgs) == null ? void 0 : _f.call(_e, types);
742
+ break;
743
+ }
735
744
  this.consumeWhitespace();
736
745
  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;
746
+ if (nextCode === 124 /* PIPE */ && !hasParams) {
747
+ (_h = (_g = this.options).onTagTypeParams) == null ? void 0 : _h.call(_g, types);
748
+ } else if (nextCode === 40 /* OPEN_PAREN */ && !(typeParams || hasParams || hasArgs)) {
749
+ tag.typeParams = types;
750
750
  } else {
751
751
  this.emitError(
752
752
  child,
753
753
  27 /* INVALID_TAG_TYPES */,
754
- "Unexpected types. Type arguments must follow a tag name and type paremeters must precede a method or tag parameters."
754
+ "Unexpected types. Type arguments must directly follow a tag name and type paremeters must precede a method or tag parameters."
755
755
  );
756
756
  }
757
757
  break;
758
758
  }
759
759
  case 4 /* PARAMS */: {
760
760
  const end = ++this.pos;
761
- (_p = (_o = this.options).onTagParams) == null ? void 0 : _p.call(_o, {
761
+ (_j = (_i = this.options).onTagParams) == null ? void 0 : _j.call(_i, {
762
762
  start: child.start - 1,
763
763
  end,
764
764
  value: {
@@ -780,6 +780,8 @@ function shouldTerminateConciseTagVar(code, data, pos) {
780
780
  case 59 /* SEMICOLON */:
781
781
  case 60 /* OPEN_ANGLE_BRACKET */:
782
782
  return true;
783
+ case 45 /* HYPHEN */:
784
+ return data.charCodeAt(pos + 1) === 45 /* HYPHEN */;
783
785
  case 58 /* COLON */:
784
786
  return data.charCodeAt(pos + 1) === 61 /* EQUAL */;
785
787
  default:
package/dist/index.mjs CHANGED
@@ -395,7 +395,7 @@ var OPEN_TAG = {
395
395
  hasArgs: false,
396
396
  hasAttrs: false,
397
397
  hasParams: false,
398
- types: void 0,
398
+ typeParams: void 0,
399
399
  selfClosed: false,
400
400
  shorthandEnd: -1,
401
401
  tagName: void 0,
@@ -643,7 +643,7 @@ var OPEN_TAG = {
643
643
  }
644
644
  },
645
645
  return(child, tag) {
646
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
646
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
647
647
  if (child.state !== states_exports.EXPRESSION)
648
648
  return;
649
649
  switch (tag.stage) {
@@ -666,7 +666,7 @@ var OPEN_TAG = {
666
666
  break;
667
667
  }
668
668
  case 2 /* ARGUMENT */: {
669
- const { types } = tag;
669
+ const { typeParams } = tag;
670
670
  const start = child.start - 1;
671
671
  const end = ++this.pos;
672
672
  const value = {
@@ -675,9 +675,9 @@ var OPEN_TAG = {
675
675
  };
676
676
  if (this.consumeWhitespaceIfBefore("{")) {
677
677
  const attr = this.enterState(states_exports.ATTRIBUTE);
678
- if (types) {
679
- attr.start = types.start;
680
- attr.typeParams = types;
678
+ if (typeParams) {
679
+ attr.start = typeParams.start;
680
+ attr.typeParams = typeParams;
681
681
  } else {
682
682
  attr.start = start;
683
683
  }
@@ -685,10 +685,15 @@ var OPEN_TAG = {
685
685
  this.forward = 0;
686
686
  tag.hasAttrs = true;
687
687
  } else {
688
- if (types) {
689
- (_d = (_c = this.options).onTagTypeArgs) == null ? void 0 : _d.call(_c, types);
688
+ if (typeParams) {
689
+ this.emitError(
690
+ child,
691
+ 27 /* INVALID_TAG_TYPES */,
692
+ "Unexpected types. Type arguments must directly follow a tag name and type paremeters must precede a method or tag parameters."
693
+ );
694
+ break;
690
695
  }
691
- (_f = (_e = this.options).onTagArgs) == null ? void 0 : _f.call(_e, {
696
+ (_d = (_c = this.options).onTagArgs) == null ? void 0 : _d.call(_c, {
692
697
  start,
693
698
  end,
694
699
  value
@@ -697,9 +702,9 @@ var OPEN_TAG = {
697
702
  break;
698
703
  }
699
704
  case 3 /* TYPES */: {
700
- const { types, hasParams, hasArgs } = tag;
705
+ const { typeParams, hasParams, hasArgs } = tag;
701
706
  const end = ++this.pos;
702
- const typeArgs = {
707
+ const types = {
703
708
  start: child.start - 1,
704
709
  end,
705
710
  value: {
@@ -707,33 +712,28 @@ var OPEN_TAG = {
707
712
  end: child.end
708
713
  }
709
714
  };
715
+ if (tag.tagName.end === types.start) {
716
+ (_f = (_e = this.options).onTagTypeArgs) == null ? void 0 : _f.call(_e, types);
717
+ break;
718
+ }
710
719
  this.consumeWhitespace();
711
720
  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;
721
+ if (nextCode === 124 /* PIPE */ && !hasParams) {
722
+ (_h = (_g = this.options).onTagTypeParams) == null ? void 0 : _h.call(_g, types);
723
+ } else if (nextCode === 40 /* OPEN_PAREN */ && !(typeParams || hasParams || hasArgs)) {
724
+ tag.typeParams = types;
725
725
  } else {
726
726
  this.emitError(
727
727
  child,
728
728
  27 /* INVALID_TAG_TYPES */,
729
- "Unexpected types. Type arguments must follow a tag name and type paremeters must precede a method or tag parameters."
729
+ "Unexpected types. Type arguments must directly follow a tag name and type paremeters must precede a method or tag parameters."
730
730
  );
731
731
  }
732
732
  break;
733
733
  }
734
734
  case 4 /* PARAMS */: {
735
735
  const end = ++this.pos;
736
- (_p = (_o = this.options).onTagParams) == null ? void 0 : _p.call(_o, {
736
+ (_j = (_i = this.options).onTagParams) == null ? void 0 : _j.call(_i, {
737
737
  start: child.start - 1,
738
738
  end,
739
739
  value: {
@@ -755,6 +755,8 @@ function shouldTerminateConciseTagVar(code, data, pos) {
755
755
  case 59 /* SEMICOLON */:
756
756
  case 60 /* OPEN_ANGLE_BRACKET */:
757
757
  return true;
758
+ case 45 /* HYPHEN */:
759
+ return data.charCodeAt(pos + 1) === 45 /* HYPHEN */;
758
760
  case 58 /* COLON */:
759
761
  return data.charCodeAt(pos + 1) === 61 /* EQUAL */;
760
762
  default:
@@ -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.3",
4
+ "version": "5.3.0",
5
5
  "devDependencies": {
6
6
  "@changesets/changelog-github": "^0.4.7",
7
7
  "@changesets/cli": "^2.25.2",