htmljs-parser 5.4.1 → 5.4.3

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
@@ -382,6 +382,7 @@ __export(states_exports, {
382
382
  JS_COMMENT_BLOCK: () => JS_COMMENT_BLOCK,
383
383
  JS_COMMENT_LINE: () => JS_COMMENT_LINE,
384
384
  OPEN_TAG: () => OPEN_TAG,
385
+ PARSED_STRING: () => PARSED_STRING,
385
386
  PARSED_TEXT_CONTENT: () => PARSED_TEXT_CONTENT,
386
387
  PLACEHOLDER: () => PLACEHOLDER,
387
388
  REGULAR_EXPRESSION: () => REGULAR_EXPRESSION,
@@ -1623,8 +1624,21 @@ var EXPRESSION = {
1623
1624
  return;
1624
1625
  }
1625
1626
  if (expression.shouldTerminate(code, this.data, this.pos)) {
1626
- this.exitState();
1627
- return;
1627
+ let wasExpression = false;
1628
+ if (expression.operators) {
1629
+ const prevNonWhitespacePos = lookBehindWhile(
1630
+ isWhitespaceCode,
1631
+ this.data,
1632
+ this.pos - 1
1633
+ );
1634
+ if (prevNonWhitespacePos > expression.start) {
1635
+ wasExpression = lookBehindForOperator(this.data, prevNonWhitespacePos) !== -1;
1636
+ }
1637
+ }
1638
+ if (!wasExpression) {
1639
+ this.exitState();
1640
+ return;
1641
+ }
1628
1642
  }
1629
1643
  }
1630
1644
  switch (code) {
@@ -2259,6 +2273,11 @@ var PARSED_TEXT_CONTENT = {
2259
2273
  this.startText();
2260
2274
  this.enterState(states_exports.TEMPLATE_STRING);
2261
2275
  break;
2276
+ case 34 /* DOUBLE_QUOTE */:
2277
+ case 39 /* SINGLE_QUOTE */:
2278
+ this.startText();
2279
+ this.enterState(states_exports.PARSED_STRING).quoteCharCode = code;
2280
+ break;
2262
2281
  default:
2263
2282
  if (!states_exports.checkForPlaceholder(this, code))
2264
2283
  this.startText();
@@ -2624,6 +2643,42 @@ var TEMPLATE_STRING = {
2624
2643
  }
2625
2644
  };
2626
2645
 
2646
+ // src/states/PARSED_STRING.ts
2647
+ var PARSED_STRING = {
2648
+ name: "PARSED_STRING",
2649
+ enter(parent, start) {
2650
+ return {
2651
+ state: PARSED_STRING,
2652
+ parent,
2653
+ start,
2654
+ end: start,
2655
+ quoteCharCode: 34 /* DOUBLE_QUOTE */
2656
+ };
2657
+ },
2658
+ exit() {
2659
+ },
2660
+ char(code, str) {
2661
+ if (code === str.quoteCharCode) {
2662
+ this.startText();
2663
+ this.pos++;
2664
+ this.exitState();
2665
+ } else if (!states_exports.checkForPlaceholder(this, code)) {
2666
+ this.startText();
2667
+ }
2668
+ },
2669
+ eof(str) {
2670
+ this.emitError(
2671
+ str,
2672
+ 13 /* INVALID_TEMPLATE_STRING */,
2673
+ "EOF reached while parsing string expression"
2674
+ );
2675
+ },
2676
+ eol() {
2677
+ },
2678
+ return() {
2679
+ }
2680
+ };
2681
+
2627
2682
  // src/index.ts
2628
2683
  function createParser(handlers) {
2629
2684
  const parser = new Parser(handlers);
package/dist/index.mjs CHANGED
@@ -357,6 +357,7 @@ __export(states_exports, {
357
357
  JS_COMMENT_BLOCK: () => JS_COMMENT_BLOCK,
358
358
  JS_COMMENT_LINE: () => JS_COMMENT_LINE,
359
359
  OPEN_TAG: () => OPEN_TAG,
360
+ PARSED_STRING: () => PARSED_STRING,
360
361
  PARSED_TEXT_CONTENT: () => PARSED_TEXT_CONTENT,
361
362
  PLACEHOLDER: () => PLACEHOLDER,
362
363
  REGULAR_EXPRESSION: () => REGULAR_EXPRESSION,
@@ -1598,8 +1599,21 @@ var EXPRESSION = {
1598
1599
  return;
1599
1600
  }
1600
1601
  if (expression.shouldTerminate(code, this.data, this.pos)) {
1601
- this.exitState();
1602
- return;
1602
+ let wasExpression = false;
1603
+ if (expression.operators) {
1604
+ const prevNonWhitespacePos = lookBehindWhile(
1605
+ isWhitespaceCode,
1606
+ this.data,
1607
+ this.pos - 1
1608
+ );
1609
+ if (prevNonWhitespacePos > expression.start) {
1610
+ wasExpression = lookBehindForOperator(this.data, prevNonWhitespacePos) !== -1;
1611
+ }
1612
+ }
1613
+ if (!wasExpression) {
1614
+ this.exitState();
1615
+ return;
1616
+ }
1603
1617
  }
1604
1618
  }
1605
1619
  switch (code) {
@@ -2234,6 +2248,11 @@ var PARSED_TEXT_CONTENT = {
2234
2248
  this.startText();
2235
2249
  this.enterState(states_exports.TEMPLATE_STRING);
2236
2250
  break;
2251
+ case 34 /* DOUBLE_QUOTE */:
2252
+ case 39 /* SINGLE_QUOTE */:
2253
+ this.startText();
2254
+ this.enterState(states_exports.PARSED_STRING).quoteCharCode = code;
2255
+ break;
2237
2256
  default:
2238
2257
  if (!states_exports.checkForPlaceholder(this, code))
2239
2258
  this.startText();
@@ -2599,6 +2618,42 @@ var TEMPLATE_STRING = {
2599
2618
  }
2600
2619
  };
2601
2620
 
2621
+ // src/states/PARSED_STRING.ts
2622
+ var PARSED_STRING = {
2623
+ name: "PARSED_STRING",
2624
+ enter(parent, start) {
2625
+ return {
2626
+ state: PARSED_STRING,
2627
+ parent,
2628
+ start,
2629
+ end: start,
2630
+ quoteCharCode: 34 /* DOUBLE_QUOTE */
2631
+ };
2632
+ },
2633
+ exit() {
2634
+ },
2635
+ char(code, str) {
2636
+ if (code === str.quoteCharCode) {
2637
+ this.startText();
2638
+ this.pos++;
2639
+ this.exitState();
2640
+ } else if (!states_exports.checkForPlaceholder(this, code)) {
2641
+ this.startText();
2642
+ }
2643
+ },
2644
+ eof(str) {
2645
+ this.emitError(
2646
+ str,
2647
+ 13 /* INVALID_TEMPLATE_STRING */,
2648
+ "EOF reached while parsing string expression"
2649
+ );
2650
+ },
2651
+ eol() {
2652
+ },
2653
+ return() {
2654
+ }
2655
+ };
2656
+
2602
2657
  // src/index.ts
2603
2658
  function createParser(handlers) {
2604
2659
  const parser = new Parser(handlers);
@@ -0,0 +1,6 @@
1
+ import { StateDefinition, Meta } from "../internal";
2
+ interface ParsedStringMeta extends Meta {
3
+ quoteCharCode: number;
4
+ }
5
+ export declare const PARSED_STRING: StateDefinition<ParsedStringMeta>;
6
+ export {};
@@ -17,4 +17,5 @@ export * from "./REGULAR_EXPRESSION";
17
17
  export * from "./STRING";
18
18
  export * from "./TAG_NAME";
19
19
  export * from "./TEMPLATE_STRING";
20
+ export * from "./PARSED_STRING";
20
21
  export * from "./OPEN_TAG";
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.4.1",
4
+ "version": "5.4.3",
5
5
  "devDependencies": {
6
6
  "@changesets/changelog-github": "^0.4.7",
7
7
  "@changesets/cli": "^2.25.2",