htmljs-parser 5.4.0 → 5.4.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.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,
@@ -1805,7 +1806,8 @@ function lookBehindForOperator(data, pos) {
1805
1806
  for (const keyword of unaryKeywords) {
1806
1807
  const keywordPos = lookBehindFor(data, curPos, keyword);
1807
1808
  if (keywordPos !== -1) {
1808
- return data.charCodeAt(keywordPos - 1) === 46 /* PERIOD */ ? -1 : keywordPos;
1809
+ const prevCode = data.charCodeAt(keywordPos - 1);
1810
+ return prevCode === 46 /* PERIOD */ || isWordCode(prevCode) ? -1 : keywordPos;
1809
1811
  }
1810
1812
  }
1811
1813
  return -1;
@@ -2258,6 +2260,11 @@ var PARSED_TEXT_CONTENT = {
2258
2260
  this.startText();
2259
2261
  this.enterState(states_exports.TEMPLATE_STRING);
2260
2262
  break;
2263
+ case 34 /* DOUBLE_QUOTE */:
2264
+ case 39 /* SINGLE_QUOTE */:
2265
+ this.startText();
2266
+ this.enterState(states_exports.PARSED_STRING).quoteCharCode = code;
2267
+ break;
2261
2268
  default:
2262
2269
  if (!states_exports.checkForPlaceholder(this, code))
2263
2270
  this.startText();
@@ -2623,6 +2630,41 @@ var TEMPLATE_STRING = {
2623
2630
  }
2624
2631
  };
2625
2632
 
2633
+ // src/states/PARSED_STRING.ts
2634
+ var PARSED_STRING = {
2635
+ name: "PARSED_STRING",
2636
+ enter(parent, start) {
2637
+ return {
2638
+ state: PARSED_STRING,
2639
+ parent,
2640
+ start,
2641
+ end: start,
2642
+ quoteCharCode: 34 /* DOUBLE_QUOTE */
2643
+ };
2644
+ },
2645
+ exit() {
2646
+ },
2647
+ char(code, str) {
2648
+ if (code === str.quoteCharCode) {
2649
+ this.pos++;
2650
+ this.exitState();
2651
+ } else if (!states_exports.checkForPlaceholder(this, code)) {
2652
+ this.startText();
2653
+ }
2654
+ },
2655
+ eof(str) {
2656
+ this.emitError(
2657
+ str,
2658
+ 13 /* INVALID_TEMPLATE_STRING */,
2659
+ "EOF reached while parsing string expression"
2660
+ );
2661
+ },
2662
+ eol() {
2663
+ },
2664
+ return() {
2665
+ }
2666
+ };
2667
+
2626
2668
  // src/index.ts
2627
2669
  function createParser(handlers) {
2628
2670
  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,
@@ -1780,7 +1781,8 @@ function lookBehindForOperator(data, pos) {
1780
1781
  for (const keyword of unaryKeywords) {
1781
1782
  const keywordPos = lookBehindFor(data, curPos, keyword);
1782
1783
  if (keywordPos !== -1) {
1783
- return data.charCodeAt(keywordPos - 1) === 46 /* PERIOD */ ? -1 : keywordPos;
1784
+ const prevCode = data.charCodeAt(keywordPos - 1);
1785
+ return prevCode === 46 /* PERIOD */ || isWordCode(prevCode) ? -1 : keywordPos;
1784
1786
  }
1785
1787
  }
1786
1788
  return -1;
@@ -2233,6 +2235,11 @@ var PARSED_TEXT_CONTENT = {
2233
2235
  this.startText();
2234
2236
  this.enterState(states_exports.TEMPLATE_STRING);
2235
2237
  break;
2238
+ case 34 /* DOUBLE_QUOTE */:
2239
+ case 39 /* SINGLE_QUOTE */:
2240
+ this.startText();
2241
+ this.enterState(states_exports.PARSED_STRING).quoteCharCode = code;
2242
+ break;
2236
2243
  default:
2237
2244
  if (!states_exports.checkForPlaceholder(this, code))
2238
2245
  this.startText();
@@ -2598,6 +2605,41 @@ var TEMPLATE_STRING = {
2598
2605
  }
2599
2606
  };
2600
2607
 
2608
+ // src/states/PARSED_STRING.ts
2609
+ var PARSED_STRING = {
2610
+ name: "PARSED_STRING",
2611
+ enter(parent, start) {
2612
+ return {
2613
+ state: PARSED_STRING,
2614
+ parent,
2615
+ start,
2616
+ end: start,
2617
+ quoteCharCode: 34 /* DOUBLE_QUOTE */
2618
+ };
2619
+ },
2620
+ exit() {
2621
+ },
2622
+ char(code, str) {
2623
+ if (code === str.quoteCharCode) {
2624
+ this.pos++;
2625
+ this.exitState();
2626
+ } else if (!states_exports.checkForPlaceholder(this, code)) {
2627
+ this.startText();
2628
+ }
2629
+ },
2630
+ eof(str) {
2631
+ this.emitError(
2632
+ str,
2633
+ 13 /* INVALID_TEMPLATE_STRING */,
2634
+ "EOF reached while parsing string expression"
2635
+ );
2636
+ },
2637
+ eol() {
2638
+ },
2639
+ return() {
2640
+ }
2641
+ };
2642
+
2601
2643
  // src/index.ts
2602
2644
  function createParser(handlers) {
2603
2645
  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.0",
4
+ "version": "5.4.2",
5
5
  "devDependencies": {
6
6
  "@changesets/changelog-github": "^0.4.7",
7
7
  "@changesets/cli": "^2.25.2",