htmljs-parser 5.7.3 → 5.8.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.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type ParserOptions, type Range } from "./internal";
2
2
  export { TagType, ErrorCode, getLines, getLocation, getPosition, type ParserOptions as Handlers, type Position, type Location, type Ranges, type Range, } from "./internal";
3
+ export { isValidStatement, isValidAttrValue } from "./util/validators";
3
4
  /**
4
5
  * Creates a new Marko parser.
5
6
  */
package/dist/index.js CHANGED
@@ -25,7 +25,9 @@ __export(src_exports, {
25
25
  createParser: () => createParser,
26
26
  getLines: () => getLines,
27
27
  getLocation: () => getLocation,
28
- getPosition: () => getPosition
28
+ getPosition: () => getPosition,
29
+ isValidAttrValue: () => isValidAttrValue,
30
+ isValidStatement: () => isValidStatement
29
31
  });
30
32
  module.exports = __toCommonJS(src_exports);
31
33
 
@@ -411,7 +413,9 @@ __export(states_exports, {
411
413
  checkForCDATA: () => checkForCDATA,
412
414
  checkForClosingTag: () => checkForClosingTag,
413
415
  checkForPlaceholder: () => checkForPlaceholder,
414
- handleDelimitedEOL: () => handleDelimitedEOL
416
+ handleDelimitedEOL: () => handleDelimitedEOL,
417
+ shouldTerminateConciseAttrValue: () => shouldTerminateConciseAttrValue,
418
+ shouldTerminateHtmlAttrValue: () => shouldTerminateHtmlAttrValue
415
419
  });
416
420
 
417
421
  // src/states/OPEN_TAG.ts
@@ -1792,7 +1796,12 @@ var EXPRESSION = {
1792
1796
  case 41 /* CLOSE_PAREN */:
1793
1797
  case 93 /* CLOSE_SQUARE_BRACKET */:
1794
1798
  case 125 /* CLOSE_CURLY_BRACE */:
1795
- case (expression.inType && 62 /* CLOSE_ANGLE_BRACKET */): {
1799
+ case 62 /* CLOSE_ANGLE_BRACKET */: {
1800
+ if (code === 62 /* CLOSE_ANGLE_BRACKET */) {
1801
+ if (!expression.inType || this.lookAtCharCodeAhead(-1) === 61 /* EQUAL */) {
1802
+ break;
1803
+ }
1804
+ }
1796
1805
  if (!expression.groupStack.length) {
1797
1806
  return this.emitError(
1798
1807
  expression,
@@ -2830,6 +2839,80 @@ var PARSED_STRING = {
2830
2839
  }
2831
2840
  };
2832
2841
 
2842
+ // src/util/validators.ts
2843
+ var ROOT_STATE = {
2844
+ name: "ROOT",
2845
+ enter() {
2846
+ return ROOT_RANGE;
2847
+ },
2848
+ exit() {
2849
+ },
2850
+ char() {
2851
+ },
2852
+ eol() {
2853
+ },
2854
+ eof() {
2855
+ },
2856
+ return() {
2857
+ }
2858
+ };
2859
+ var ROOT_RANGE = {
2860
+ state: ROOT_STATE,
2861
+ parent: void 0,
2862
+ start: 0,
2863
+ end: 0
2864
+ };
2865
+ function isValidStatement(code) {
2866
+ return isValid(code, true, prepareStatement);
2867
+ }
2868
+ function prepareStatement(expr) {
2869
+ expr.operators = true;
2870
+ expr.terminatedByEOL = true;
2871
+ expr.consumeIndentedContent = true;
2872
+ }
2873
+ function isValidAttrValue(code, concise) {
2874
+ return isValid(code, concise, prepareAttrValue);
2875
+ }
2876
+ function prepareAttrValue(expr, concise) {
2877
+ expr.operators = true;
2878
+ expr.terminatedByWhitespace = true;
2879
+ expr.shouldTerminate = concise ? shouldTerminateConciseAttrValue : shouldTerminateHtmlAttrValue;
2880
+ }
2881
+ function isValid(data, concise, prepare) {
2882
+ const parser = new Parser({});
2883
+ const maxPos = parser.maxPos = data.length;
2884
+ parser.pos = 0;
2885
+ parser.data = data;
2886
+ parser.indent = "";
2887
+ parser.forward = 1;
2888
+ parser.textPos = -1;
2889
+ parser.isConcise = concise;
2890
+ parser.beginMixedMode = parser.endingMixedModeAtEOL = false;
2891
+ parser.lines = parser.activeTag = parser.activeAttr = void 0;
2892
+ parser.activeState = ROOT_STATE;
2893
+ parser.activeRange = ROOT_RANGE;
2894
+ const expr = parser.enterState(states_exports.EXPRESSION);
2895
+ prepare(expr, concise);
2896
+ while (parser.pos < maxPos) {
2897
+ const code = data.charCodeAt(parser.pos);
2898
+ if (code === 10 /* NEWLINE */) {
2899
+ parser.forward = 1;
2900
+ parser.activeState.eol.call(parser, 1, parser.activeRange);
2901
+ } else if (code === 13 /* CARRIAGE_RETURN */ && data.charCodeAt(parser.pos + 1) === 10 /* NEWLINE */) {
2902
+ parser.forward = 2;
2903
+ parser.activeState.eol.call(parser, 2, parser.activeRange);
2904
+ } else {
2905
+ parser.forward = 1;
2906
+ parser.activeState.char.call(parser, code, parser.activeRange);
2907
+ }
2908
+ if (parser.activeRange === ROOT_RANGE) {
2909
+ return false;
2910
+ }
2911
+ parser.pos += parser.forward;
2912
+ }
2913
+ return parser.pos === maxPos && parser.activeRange === expr && !expr.groupStack.length;
2914
+ }
2915
+
2833
2916
  // src/index.ts
2834
2917
  function createParser(handlers) {
2835
2918
  const parser = new Parser(handlers);
@@ -2867,5 +2950,7 @@ function createParser(handlers) {
2867
2950
  createParser,
2868
2951
  getLines,
2869
2952
  getLocation,
2870
- getPosition
2953
+ getPosition,
2954
+ isValidAttrValue,
2955
+ isValidStatement
2871
2956
  });
package/dist/index.mjs CHANGED
@@ -386,7 +386,9 @@ __export(states_exports, {
386
386
  checkForCDATA: () => checkForCDATA,
387
387
  checkForClosingTag: () => checkForClosingTag,
388
388
  checkForPlaceholder: () => checkForPlaceholder,
389
- handleDelimitedEOL: () => handleDelimitedEOL
389
+ handleDelimitedEOL: () => handleDelimitedEOL,
390
+ shouldTerminateConciseAttrValue: () => shouldTerminateConciseAttrValue,
391
+ shouldTerminateHtmlAttrValue: () => shouldTerminateHtmlAttrValue
390
392
  });
391
393
 
392
394
  // src/states/OPEN_TAG.ts
@@ -1767,7 +1769,12 @@ var EXPRESSION = {
1767
1769
  case 41 /* CLOSE_PAREN */:
1768
1770
  case 93 /* CLOSE_SQUARE_BRACKET */:
1769
1771
  case 125 /* CLOSE_CURLY_BRACE */:
1770
- case (expression.inType && 62 /* CLOSE_ANGLE_BRACKET */): {
1772
+ case 62 /* CLOSE_ANGLE_BRACKET */: {
1773
+ if (code === 62 /* CLOSE_ANGLE_BRACKET */) {
1774
+ if (!expression.inType || this.lookAtCharCodeAhead(-1) === 61 /* EQUAL */) {
1775
+ break;
1776
+ }
1777
+ }
1771
1778
  if (!expression.groupStack.length) {
1772
1779
  return this.emitError(
1773
1780
  expression,
@@ -2805,6 +2812,80 @@ var PARSED_STRING = {
2805
2812
  }
2806
2813
  };
2807
2814
 
2815
+ // src/util/validators.ts
2816
+ var ROOT_STATE = {
2817
+ name: "ROOT",
2818
+ enter() {
2819
+ return ROOT_RANGE;
2820
+ },
2821
+ exit() {
2822
+ },
2823
+ char() {
2824
+ },
2825
+ eol() {
2826
+ },
2827
+ eof() {
2828
+ },
2829
+ return() {
2830
+ }
2831
+ };
2832
+ var ROOT_RANGE = {
2833
+ state: ROOT_STATE,
2834
+ parent: void 0,
2835
+ start: 0,
2836
+ end: 0
2837
+ };
2838
+ function isValidStatement(code) {
2839
+ return isValid(code, true, prepareStatement);
2840
+ }
2841
+ function prepareStatement(expr) {
2842
+ expr.operators = true;
2843
+ expr.terminatedByEOL = true;
2844
+ expr.consumeIndentedContent = true;
2845
+ }
2846
+ function isValidAttrValue(code, concise) {
2847
+ return isValid(code, concise, prepareAttrValue);
2848
+ }
2849
+ function prepareAttrValue(expr, concise) {
2850
+ expr.operators = true;
2851
+ expr.terminatedByWhitespace = true;
2852
+ expr.shouldTerminate = concise ? shouldTerminateConciseAttrValue : shouldTerminateHtmlAttrValue;
2853
+ }
2854
+ function isValid(data, concise, prepare) {
2855
+ const parser = new Parser({});
2856
+ const maxPos = parser.maxPos = data.length;
2857
+ parser.pos = 0;
2858
+ parser.data = data;
2859
+ parser.indent = "";
2860
+ parser.forward = 1;
2861
+ parser.textPos = -1;
2862
+ parser.isConcise = concise;
2863
+ parser.beginMixedMode = parser.endingMixedModeAtEOL = false;
2864
+ parser.lines = parser.activeTag = parser.activeAttr = void 0;
2865
+ parser.activeState = ROOT_STATE;
2866
+ parser.activeRange = ROOT_RANGE;
2867
+ const expr = parser.enterState(states_exports.EXPRESSION);
2868
+ prepare(expr, concise);
2869
+ while (parser.pos < maxPos) {
2870
+ const code = data.charCodeAt(parser.pos);
2871
+ if (code === 10 /* NEWLINE */) {
2872
+ parser.forward = 1;
2873
+ parser.activeState.eol.call(parser, 1, parser.activeRange);
2874
+ } else if (code === 13 /* CARRIAGE_RETURN */ && data.charCodeAt(parser.pos + 1) === 10 /* NEWLINE */) {
2875
+ parser.forward = 2;
2876
+ parser.activeState.eol.call(parser, 2, parser.activeRange);
2877
+ } else {
2878
+ parser.forward = 1;
2879
+ parser.activeState.char.call(parser, code, parser.activeRange);
2880
+ }
2881
+ if (parser.activeRange === ROOT_RANGE) {
2882
+ return false;
2883
+ }
2884
+ parser.pos += parser.forward;
2885
+ }
2886
+ return parser.pos === maxPos && parser.activeRange === expr && !expr.groupStack.length;
2887
+ }
2888
+
2808
2889
  // src/index.ts
2809
2890
  function createParser(handlers) {
2810
2891
  const parser = new Parser(handlers);
@@ -2841,5 +2922,7 @@ export {
2841
2922
  createParser,
2842
2923
  getLines,
2843
2924
  getLocation,
2844
- getPosition
2925
+ getPosition,
2926
+ isValidAttrValue,
2927
+ isValidStatement
2845
2928
  };
@@ -1,4 +1,4 @@
1
- import { type StateDefinition, type Range, type Ranges, type Meta } from "../internal";
1
+ import { STATE, type StateDefinition, type Range, type Ranges, type Meta } from "../internal";
2
2
  declare const enum ATTR_STAGE {
3
3
  UNKNOWN = 0,
4
4
  NAME = 1,
@@ -17,4 +17,6 @@ export interface AttrMeta extends Meta {
17
17
  bound: boolean;
18
18
  }
19
19
  export declare const ATTRIBUTE: StateDefinition<AttrMeta>;
20
+ export declare function shouldTerminateHtmlAttrValue(this: STATE.ExpressionMeta, code: number, data: string, pos: number): boolean;
21
+ export declare function shouldTerminateConciseAttrValue(code: number, data: string, pos: number): boolean;
20
22
  export {};
@@ -0,0 +1,2 @@
1
+ export declare function isValidStatement(code: string): boolean;
2
+ export declare function isValidAttrValue(code: string, concise: boolean): boolean;
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.7.3",
4
+ "version": "5.8.0",
5
5
  "devDependencies": {
6
6
  "@changesets/changelog-github": "^0.5.0",
7
7
  "@changesets/cli": "^2.27.1",