htmljs-parser 5.5.3 → 5.6.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.
@@ -32,8 +32,8 @@ export declare class Parser {
32
32
  lines: undefined | number[];
33
33
  constructor(options: Options);
34
34
  read(range: Range): string;
35
- positionAt(offset: number): import("../internal").Position;
36
- locationAt(range: Range): import("../internal").Location;
35
+ positionAt(offset: number): import("..").Position;
36
+ locationAt(range: Range): import("..").Location;
37
37
  enterState<P extends Meta>(state: StateDefinition<P>): P;
38
38
  exitState(): void;
39
39
  /**
package/dist/index.js CHANGED
@@ -74,6 +74,9 @@ var TagType = /* @__PURE__ */ ((TagType2) => {
74
74
  function isWhitespaceCode(code) {
75
75
  return code <= 32 /* SPACE */;
76
76
  }
77
+ function isIndentCode(code) {
78
+ return code === 9 /* TAB */ || code === 32 /* SPACE */;
79
+ }
77
80
  function getLocation(lines, startOffset, endOffset) {
78
81
  const start = getPosition(lines, startOffset);
79
82
  const end = startOffset === endOffset ? start : getPosAfterLine(lines, start.line, endOffset);
@@ -558,8 +561,7 @@ var OPEN_TAG = {
558
561
  ;
559
562
  const indentStart = ++curPos;
560
563
  while (curPos < maxPos) {
561
- const nextCode = this.data.charCodeAt(curPos);
562
- if (nextCode === 32 /* SPACE */ || nextCode === 9 /* TAB */) {
564
+ if (isIndentCode(this.data.charCodeAt(curPos))) {
563
565
  curPos++;
564
566
  } else {
565
567
  break;
@@ -1644,8 +1646,10 @@ var EXPRESSION = {
1644
1646
  groupStack: [],
1645
1647
  shouldTerminate,
1646
1648
  operators: false,
1649
+ wasComment: false,
1647
1650
  terminatedByEOL: false,
1648
- terminatedByWhitespace: false
1651
+ terminatedByWhitespace: false,
1652
+ consumeIndentedContent: false
1649
1653
  };
1650
1654
  },
1651
1655
  exit() {
@@ -1739,10 +1743,11 @@ var EXPRESSION = {
1739
1743
  }
1740
1744
  }
1741
1745
  },
1742
- eol(_, expression) {
1743
- if (!expression.groupStack.length && (expression.terminatedByEOL || expression.terminatedByWhitespace) && !checkForOperators(this, expression, true)) {
1746
+ eol(len, expression) {
1747
+ if (!expression.groupStack.length && (expression.terminatedByEOL || expression.terminatedByWhitespace) && (expression.wasComment || !checkForOperators(this, expression, true)) && !(expression.consumeIndentedContent && isIndentCode(this.lookAtCharCodeAhead(len + 1)))) {
1744
1748
  this.exitState();
1745
1749
  }
1750
+ expression.wasComment = false;
1746
1751
  },
1747
1752
  eof(expression) {
1748
1753
  if (!expression.groupStack.length && (this.isConcise || expression.terminatedByEOL)) {
@@ -1785,7 +1790,10 @@ var EXPRESSION = {
1785
1790
  );
1786
1791
  }
1787
1792
  },
1788
- return() {
1793
+ return(child, expression) {
1794
+ if (child.state === states_exports.JS_COMMENT_LINE) {
1795
+ expression.wasComment = true;
1796
+ }
1789
1797
  }
1790
1798
  };
1791
1799
  function checkForOperators(parser, expression, eol) {
@@ -1941,9 +1949,6 @@ function canFollowDivision(code) {
1941
1949
  function isWordCode(code) {
1942
1950
  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 */;
1943
1951
  }
1944
- function isIndentCode(code) {
1945
- return code === 9 /* TAB */ || code === 32 /* SPACE */;
1946
- }
1947
1952
  function lookAheadWhile(match, data, pos) {
1948
1953
  const max = data.length;
1949
1954
  for (let i = pos; i < max; i++) {
@@ -2594,6 +2599,7 @@ var TAG_NAME = {
2594
2599
  const expr = this.enterState(states_exports.EXPRESSION);
2595
2600
  expr.operators = true;
2596
2601
  expr.terminatedByEOL = true;
2602
+ expr.consumeIndentedContent = true;
2597
2603
  }
2598
2604
  }
2599
2605
  break;
package/dist/index.mjs CHANGED
@@ -49,6 +49,9 @@ var TagType = /* @__PURE__ */ ((TagType2) => {
49
49
  function isWhitespaceCode(code) {
50
50
  return code <= 32 /* SPACE */;
51
51
  }
52
+ function isIndentCode(code) {
53
+ return code === 9 /* TAB */ || code === 32 /* SPACE */;
54
+ }
52
55
  function getLocation(lines, startOffset, endOffset) {
53
56
  const start = getPosition(lines, startOffset);
54
57
  const end = startOffset === endOffset ? start : getPosAfterLine(lines, start.line, endOffset);
@@ -533,8 +536,7 @@ var OPEN_TAG = {
533
536
  ;
534
537
  const indentStart = ++curPos;
535
538
  while (curPos < maxPos) {
536
- const nextCode = this.data.charCodeAt(curPos);
537
- if (nextCode === 32 /* SPACE */ || nextCode === 9 /* TAB */) {
539
+ if (isIndentCode(this.data.charCodeAt(curPos))) {
538
540
  curPos++;
539
541
  } else {
540
542
  break;
@@ -1619,8 +1621,10 @@ var EXPRESSION = {
1619
1621
  groupStack: [],
1620
1622
  shouldTerminate,
1621
1623
  operators: false,
1624
+ wasComment: false,
1622
1625
  terminatedByEOL: false,
1623
- terminatedByWhitespace: false
1626
+ terminatedByWhitespace: false,
1627
+ consumeIndentedContent: false
1624
1628
  };
1625
1629
  },
1626
1630
  exit() {
@@ -1714,10 +1718,11 @@ var EXPRESSION = {
1714
1718
  }
1715
1719
  }
1716
1720
  },
1717
- eol(_, expression) {
1718
- if (!expression.groupStack.length && (expression.terminatedByEOL || expression.terminatedByWhitespace) && !checkForOperators(this, expression, true)) {
1721
+ eol(len, expression) {
1722
+ if (!expression.groupStack.length && (expression.terminatedByEOL || expression.terminatedByWhitespace) && (expression.wasComment || !checkForOperators(this, expression, true)) && !(expression.consumeIndentedContent && isIndentCode(this.lookAtCharCodeAhead(len + 1)))) {
1719
1723
  this.exitState();
1720
1724
  }
1725
+ expression.wasComment = false;
1721
1726
  },
1722
1727
  eof(expression) {
1723
1728
  if (!expression.groupStack.length && (this.isConcise || expression.terminatedByEOL)) {
@@ -1760,7 +1765,10 @@ var EXPRESSION = {
1760
1765
  );
1761
1766
  }
1762
1767
  },
1763
- return() {
1768
+ return(child, expression) {
1769
+ if (child.state === states_exports.JS_COMMENT_LINE) {
1770
+ expression.wasComment = true;
1771
+ }
1764
1772
  }
1765
1773
  };
1766
1774
  function checkForOperators(parser, expression, eol) {
@@ -1916,9 +1924,6 @@ function canFollowDivision(code) {
1916
1924
  function isWordCode(code) {
1917
1925
  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 */;
1918
1926
  }
1919
- function isIndentCode(code) {
1920
- return code === 9 /* TAB */ || code === 32 /* SPACE */;
1921
- }
1922
1927
  function lookAheadWhile(match, data, pos) {
1923
1928
  const max = data.length;
1924
1929
  for (let i = pos; i < max; i++) {
@@ -2569,6 +2574,7 @@ var TAG_NAME = {
2569
2574
  const expr = this.enterState(states_exports.EXPRESSION);
2570
2575
  expr.operators = true;
2571
2576
  expr.terminatedByEOL = true;
2577
+ expr.consumeIndentedContent = true;
2572
2578
  }
2573
2579
  }
2574
2580
  break;
@@ -2,8 +2,10 @@ import { type StateDefinition, type Meta } from "../internal";
2
2
  export interface ExpressionMeta extends Meta {
3
3
  groupStack: number[];
4
4
  operators: boolean;
5
+ wasComment: boolean;
5
6
  terminatedByEOL: boolean;
6
7
  terminatedByWhitespace: boolean;
8
+ consumeIndentedContent: boolean;
7
9
  shouldTerminate(code: number, data: string, pos: number): boolean;
8
10
  }
9
11
  export declare const EXPRESSION: StateDefinition<ExpressionMeta>;
@@ -1,6 +1,7 @@
1
- import { type Parser } from "../internal";
1
+ import { CODE, type Parser } from "../internal";
2
2
  import { type Location, type Position } from "./constants";
3
3
  export declare function isWhitespaceCode(code: number): boolean;
4
+ export declare function isIndentCode(code: number): code is CODE.SPACE | CODE.TAB;
4
5
  /**
5
6
  * Given a source code line offsets, a start offset and an end offset, returns a Location object with line & character information for the start and end offsets.
6
7
  */
@@ -15,7 +16,7 @@ export declare function getPosition(lines: number[], offset: number): Position;
15
16
  */
16
17
  export declare function getLines(src: string): number[];
17
18
  export declare function htmlEOF(this: Parser): void;
18
- export declare function matchesCloseAngleBracket(code: number): boolean;
19
- export declare function matchesCloseParen(code: number): boolean;
20
- export declare function matchesCloseCurlyBrace(code: number): boolean;
21
- export declare function matchesPipe(code: number): boolean;
19
+ export declare function matchesCloseAngleBracket(code: number): code is CODE.CLOSE_ANGLE_BRACKET;
20
+ export declare function matchesCloseParen(code: number): code is CODE.CLOSE_PAREN;
21
+ export declare function matchesCloseCurlyBrace(code: number): code is CODE.CLOSE_CURLY_BRACE;
22
+ export declare function matchesPipe(code: number): code is CODE.PIPE;
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.5.3",
4
+ "version": "5.6.0",
5
5
  "devDependencies": {
6
6
  "@changesets/changelog-github": "^0.5.0",
7
7
  "@changesets/cli": "^2.27.1",
@@ -26,7 +26,7 @@
26
26
  "mocha-snap": "^5.0.0",
27
27
  "nyc": "^15.1.0",
28
28
  "prettier": "^3.2.5",
29
- "tsx": "^4.7.0",
29
+ "tsx": "^4.19.2",
30
30
  "typescript": "^5.3.3"
31
31
  },
32
32
  "exports": {