htmljs-parser 5.8.0 → 5.8.2

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,6 +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
+ export { isValidStatement, isValidAttrValue, Validity, } from "./util/validators";
4
4
  /**
5
5
  * Creates a new Marko parser.
6
6
  */
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  ErrorCode: () => ErrorCode,
24
24
  TagType: () => TagType,
25
+ Validity: () => Validity,
25
26
  createParser: () => createParser,
26
27
  getLines: () => getLines,
27
28
  getLocation: () => getLocation,
@@ -2862,6 +2863,12 @@ var ROOT_RANGE = {
2862
2863
  start: 0,
2863
2864
  end: 0
2864
2865
  };
2866
+ var Validity = /* @__PURE__ */ ((Validity2) => {
2867
+ Validity2[Validity2["invalid"] = 0] = "invalid";
2868
+ Validity2[Validity2["valid"] = 1] = "valid";
2869
+ Validity2[Validity2["enclosed"] = 2] = "enclosed";
2870
+ return Validity2;
2871
+ })(Validity || {});
2865
2872
  function isValidStatement(code) {
2866
2873
  return isValid(code, true, prepareStatement);
2867
2874
  }
@@ -2892,13 +2899,18 @@ function isValid(data, concise, prepare) {
2892
2899
  parser.activeState = ROOT_STATE;
2893
2900
  parser.activeRange = ROOT_RANGE;
2894
2901
  const expr = parser.enterState(states_exports.EXPRESSION);
2902
+ let isEnclosed = true;
2895
2903
  prepare(expr, concise);
2896
2904
  while (parser.pos < maxPos) {
2897
2905
  const code = data.charCodeAt(parser.pos);
2898
2906
  if (code === 10 /* NEWLINE */) {
2907
+ if (isEnclosed && !expr.groupStack.length)
2908
+ isEnclosed = false;
2899
2909
  parser.forward = 1;
2900
2910
  parser.activeState.eol.call(parser, 1, parser.activeRange);
2901
2911
  } else if (code === 13 /* CARRIAGE_RETURN */ && data.charCodeAt(parser.pos + 1) === 10 /* NEWLINE */) {
2912
+ if (isEnclosed && !expr.groupStack.length)
2913
+ isEnclosed = false;
2902
2914
  parser.forward = 2;
2903
2915
  parser.activeState.eol.call(parser, 2, parser.activeRange);
2904
2916
  } else {
@@ -2906,11 +2918,14 @@ function isValid(data, concise, prepare) {
2906
2918
  parser.activeState.char.call(parser, code, parser.activeRange);
2907
2919
  }
2908
2920
  if (parser.activeRange === ROOT_RANGE) {
2909
- return false;
2921
+ return 0 /* invalid */;
2910
2922
  }
2911
2923
  parser.pos += parser.forward;
2912
2924
  }
2913
- return parser.pos === maxPos && parser.activeRange === expr && !expr.groupStack.length;
2925
+ if (parser.pos === maxPos && parser.activeRange === expr && !expr.groupStack.length) {
2926
+ return isEnclosed ? 2 /* enclosed */ : 1 /* valid */;
2927
+ }
2928
+ return 0 /* invalid */;
2914
2929
  }
2915
2930
 
2916
2931
  // src/index.ts
@@ -2947,6 +2962,7 @@ function createParser(handlers) {
2947
2962
  0 && (module.exports = {
2948
2963
  ErrorCode,
2949
2964
  TagType,
2965
+ Validity,
2950
2966
  createParser,
2951
2967
  getLines,
2952
2968
  getLocation,
package/dist/index.mjs CHANGED
@@ -2835,6 +2835,12 @@ var ROOT_RANGE = {
2835
2835
  start: 0,
2836
2836
  end: 0
2837
2837
  };
2838
+ var Validity = /* @__PURE__ */ ((Validity2) => {
2839
+ Validity2[Validity2["invalid"] = 0] = "invalid";
2840
+ Validity2[Validity2["valid"] = 1] = "valid";
2841
+ Validity2[Validity2["enclosed"] = 2] = "enclosed";
2842
+ return Validity2;
2843
+ })(Validity || {});
2838
2844
  function isValidStatement(code) {
2839
2845
  return isValid(code, true, prepareStatement);
2840
2846
  }
@@ -2865,13 +2871,18 @@ function isValid(data, concise, prepare) {
2865
2871
  parser.activeState = ROOT_STATE;
2866
2872
  parser.activeRange = ROOT_RANGE;
2867
2873
  const expr = parser.enterState(states_exports.EXPRESSION);
2874
+ let isEnclosed = true;
2868
2875
  prepare(expr, concise);
2869
2876
  while (parser.pos < maxPos) {
2870
2877
  const code = data.charCodeAt(parser.pos);
2871
2878
  if (code === 10 /* NEWLINE */) {
2879
+ if (isEnclosed && !expr.groupStack.length)
2880
+ isEnclosed = false;
2872
2881
  parser.forward = 1;
2873
2882
  parser.activeState.eol.call(parser, 1, parser.activeRange);
2874
2883
  } else if (code === 13 /* CARRIAGE_RETURN */ && data.charCodeAt(parser.pos + 1) === 10 /* NEWLINE */) {
2884
+ if (isEnclosed && !expr.groupStack.length)
2885
+ isEnclosed = false;
2875
2886
  parser.forward = 2;
2876
2887
  parser.activeState.eol.call(parser, 2, parser.activeRange);
2877
2888
  } else {
@@ -2879,11 +2890,14 @@ function isValid(data, concise, prepare) {
2879
2890
  parser.activeState.char.call(parser, code, parser.activeRange);
2880
2891
  }
2881
2892
  if (parser.activeRange === ROOT_RANGE) {
2882
- return false;
2893
+ return 0 /* invalid */;
2883
2894
  }
2884
2895
  parser.pos += parser.forward;
2885
2896
  }
2886
- return parser.pos === maxPos && parser.activeRange === expr && !expr.groupStack.length;
2897
+ if (parser.pos === maxPos && parser.activeRange === expr && !expr.groupStack.length) {
2898
+ return isEnclosed ? 2 /* enclosed */ : 1 /* valid */;
2899
+ }
2900
+ return 0 /* invalid */;
2887
2901
  }
2888
2902
 
2889
2903
  // src/index.ts
@@ -2919,6 +2933,7 @@ function createParser(handlers) {
2919
2933
  export {
2920
2934
  ErrorCode,
2921
2935
  TagType,
2936
+ Validity,
2922
2937
  createParser,
2923
2938
  getLines,
2924
2939
  getLocation,
@@ -126,7 +126,7 @@ export declare enum ErrorCode {
126
126
  INVALID_TAG_TYPES = 27,
127
127
  INVALID_ATTR_TYPE_PARAMS = 28
128
128
  }
129
- export declare const enum TagType {
129
+ export declare enum TagType {
130
130
  html = 0,
131
131
  text = 1,
132
132
  void = 2,
@@ -1,2 +1,7 @@
1
- export declare function isValidStatement(code: string): boolean;
2
- export declare function isValidAttrValue(code: string, concise: boolean): boolean;
1
+ export declare enum Validity {
2
+ invalid = 0,
3
+ valid = 1,
4
+ enclosed = 2
5
+ }
6
+ export declare function isValidStatement(code: string): Validity;
7
+ export declare function isValidAttrValue(code: string, concise: boolean): Validity;
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.8.0",
4
+ "version": "5.8.2",
5
5
  "devDependencies": {
6
6
  "@changesets/changelog-github": "^0.5.0",
7
7
  "@changesets/cli": "^2.27.1",