htmljs-parser 5.0.1 → 5.0.4

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
@@ -1042,7 +1042,10 @@ var EXPRESSION = {
1042
1042
  this.pos++;
1043
1043
  break;
1044
1044
  default: {
1045
- if (!canCharCodeBeFollowedByDivision(this.getPreviousNonWhitespaceCharCode())) {
1045
+ if (canCharCodeBeFollowedByDivision(this.getPreviousNonWhitespaceCharCode())) {
1046
+ this.pos++;
1047
+ this.consumeWhitespace();
1048
+ } else {
1046
1049
  this.enterState(states_exports.REGULAR_EXPRESSION);
1047
1050
  }
1048
1051
  break;
@@ -1103,9 +1106,9 @@ var EXPRESSION = {
1103
1106
  };
1104
1107
  function buildPattern(type) {
1105
1108
  const space = type === 1 /* CONCISE_ATTRS */ ? "[ \\t]" : "\\s";
1106
- const binary = `(?:[!~*%&^|?<]+=*)+|:+(?!=)|[>/+=-]+=|=>|(?<!\\+)[ \\t]*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)-${type === 1 /* CONCISE_ATTRS */ ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<![/*])/(?![/*${type === 0 /* HTML_ATTRS */ ? ">" : ""}])|(?<!\\.)\\.(?!\\.)|>${type === 0 /* HTML_ATTRS */ ? "{2,}" : "+"}|[ \\t]+(?:in(?:stanceof)?|as|extends)(?=[ \\t]+[^=/,;:>])`;
1109
+ const binary = `(?:[!~*%&^|?<]+=*)+|:+(?!=)|[>/+=-]+=|=>|(?<!\\+)[ \\t]*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)-${type === 1 /* CONCISE_ATTRS */ ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<!\\.)\\.(?!\\.)|>${type === 0 /* HTML_ATTRS */ ? "{2,}" : "+"}|[ \\t]+(?:in(?:stanceof)?|as|extends)(?=[ \\t]+[^=/,;:>])`;
1107
1110
  const unary = "\\b(?<![.]\\s*)(?:a(?:sync|wait)|keyof|class|function|new|typeof|void)\\b";
1108
- const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(])`;
1111
+ const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(]|/[^>])`;
1109
1112
  const lookBehindPattern = `(?<=${unary}|${binary})`;
1110
1113
  return new RegExp(`${lookAheadPattern}|${lookBehindPattern}`, "ym");
1111
1114
  }
@@ -1249,6 +1252,22 @@ var HTML_CONTENT = {
1249
1252
  this.endText();
1250
1253
  this.enterState(states_exports.INLINE_SCRIPT);
1251
1254
  this.pos++;
1255
+ } else if (code === 47 /* FORWARD_SLASH */) {
1256
+ switch (this.lookAtCharCodeAhead(1)) {
1257
+ case 47 /* FORWARD_SLASH */:
1258
+ this.endText();
1259
+ this.enterState(states_exports.JS_COMMENT_LINE);
1260
+ this.pos++;
1261
+ break;
1262
+ case 42 /* ASTERISK */:
1263
+ this.endText();
1264
+ this.enterState(states_exports.JS_COMMENT_BLOCK);
1265
+ this.pos++;
1266
+ break;
1267
+ default:
1268
+ this.startText();
1269
+ break;
1270
+ }
1252
1271
  } else if (!states_exports.checkForPlaceholder(this, code)) {
1253
1272
  this.startText();
1254
1273
  }
@@ -1267,7 +1286,31 @@ var HTML_CONTENT = {
1267
1286
  }
1268
1287
  },
1269
1288
  eof: htmlEOF,
1270
- return() {
1289
+ return(child) {
1290
+ var _a, _b, _c, _d;
1291
+ switch (child.state) {
1292
+ case states_exports.JS_COMMENT_LINE:
1293
+ (_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
1294
+ start: child.start,
1295
+ end: child.end,
1296
+ value: {
1297
+ start: child.start + 2,
1298
+ end: child.end
1299
+ }
1300
+ });
1301
+ break;
1302
+ case states_exports.JS_COMMENT_BLOCK: {
1303
+ (_d = (_c = this.options).onComment) == null ? void 0 : _d.call(_c, {
1304
+ start: child.start,
1305
+ end: child.end,
1306
+ value: {
1307
+ start: child.start + 2,
1308
+ end: child.end - 2
1309
+ }
1310
+ });
1311
+ break;
1312
+ }
1313
+ }
1271
1314
  }
1272
1315
  };
1273
1316
  function isBeginningOfLine(parser) {
@@ -1767,6 +1810,7 @@ var CONCISE_TAG_VAR_TERMINATORS = [
1767
1810
  40 /* OPEN_PAREN */,
1768
1811
  124 /* PIPE */,
1769
1812
  61 /* EQUAL */,
1813
+ 44 /* COMMA */,
1770
1814
  [58 /* COLON */, 61 /* EQUAL */]
1771
1815
  ];
1772
1816
  var HTML_TAG_VAR_TERMINATORS = [
@@ -1774,6 +1818,7 @@ var HTML_TAG_VAR_TERMINATORS = [
1774
1818
  40 /* OPEN_PAREN */,
1775
1819
  124 /* PIPE */,
1776
1820
  61 /* EQUAL */,
1821
+ 44 /* COMMA */,
1777
1822
  [58 /* COLON */, 61 /* EQUAL */],
1778
1823
  [47 /* FORWARD_SLASH */, 62 /* CLOSE_ANGLE_BRACKET */]
1779
1824
  ];
@@ -1933,10 +1978,17 @@ var OPEN_TAG = {
1933
1978
  if (code === 60 /* OPEN_ANGLE_BRACKET */) {
1934
1979
  return this.emitError(this.pos, 2 /* INVALID_ATTRIBUTE_NAME */, 'Invalid attribute name. Attribute name cannot begin with the "<" character.');
1935
1980
  }
1936
- if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 42 /* ASTERISK */) {
1937
- this.enterState(states_exports.JS_COMMENT_BLOCK);
1938
- this.pos++;
1939
- return;
1981
+ if (code === 47 /* FORWARD_SLASH */) {
1982
+ switch (this.lookAtCharCodeAhead(1)) {
1983
+ case 47 /* FORWARD_SLASH */:
1984
+ this.enterState(states_exports.JS_COMMENT_LINE);
1985
+ this.pos++;
1986
+ return;
1987
+ case 42 /* ASTERISK */:
1988
+ this.enterState(states_exports.JS_COMMENT_BLOCK);
1989
+ this.pos++;
1990
+ return;
1991
+ }
1940
1992
  }
1941
1993
  if (isWhitespaceCode(code)) {
1942
1994
  } else if (code === 44 /* COMMA */) {
package/dist/index.mjs CHANGED
@@ -1021,7 +1021,10 @@ var EXPRESSION = {
1021
1021
  this.pos++;
1022
1022
  break;
1023
1023
  default: {
1024
- if (!canCharCodeBeFollowedByDivision(this.getPreviousNonWhitespaceCharCode())) {
1024
+ if (canCharCodeBeFollowedByDivision(this.getPreviousNonWhitespaceCharCode())) {
1025
+ this.pos++;
1026
+ this.consumeWhitespace();
1027
+ } else {
1025
1028
  this.enterState(states_exports.REGULAR_EXPRESSION);
1026
1029
  }
1027
1030
  break;
@@ -1082,9 +1085,9 @@ var EXPRESSION = {
1082
1085
  };
1083
1086
  function buildPattern(type) {
1084
1087
  const space = type === 1 /* CONCISE_ATTRS */ ? "[ \\t]" : "\\s";
1085
- const binary = `(?:[!~*%&^|?<]+=*)+|:+(?!=)|[>/+=-]+=|=>|(?<!\\+)[ \\t]*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)-${type === 1 /* CONCISE_ATTRS */ ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<![/*])/(?![/*${type === 0 /* HTML_ATTRS */ ? ">" : ""}])|(?<!\\.)\\.(?!\\.)|>${type === 0 /* HTML_ATTRS */ ? "{2,}" : "+"}|[ \\t]+(?:in(?:stanceof)?|as|extends)(?=[ \\t]+[^=/,;:>])`;
1088
+ const binary = `(?:[!~*%&^|?<]+=*)+|:+(?!=)|[>/+=-]+=|=>|(?<!\\+)[ \\t]*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)-${type === 1 /* CONCISE_ATTRS */ ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<!\\.)\\.(?!\\.)|>${type === 0 /* HTML_ATTRS */ ? "{2,}" : "+"}|[ \\t]+(?:in(?:stanceof)?|as|extends)(?=[ \\t]+[^=/,;:>])`;
1086
1089
  const unary = "\\b(?<![.]\\s*)(?:a(?:sync|wait)|keyof|class|function|new|typeof|void)\\b";
1087
- const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(])`;
1090
+ const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(]|/[^>])`;
1088
1091
  const lookBehindPattern = `(?<=${unary}|${binary})`;
1089
1092
  return new RegExp(`${lookAheadPattern}|${lookBehindPattern}`, "ym");
1090
1093
  }
@@ -1228,6 +1231,22 @@ var HTML_CONTENT = {
1228
1231
  this.endText();
1229
1232
  this.enterState(states_exports.INLINE_SCRIPT);
1230
1233
  this.pos++;
1234
+ } else if (code === 47 /* FORWARD_SLASH */) {
1235
+ switch (this.lookAtCharCodeAhead(1)) {
1236
+ case 47 /* FORWARD_SLASH */:
1237
+ this.endText();
1238
+ this.enterState(states_exports.JS_COMMENT_LINE);
1239
+ this.pos++;
1240
+ break;
1241
+ case 42 /* ASTERISK */:
1242
+ this.endText();
1243
+ this.enterState(states_exports.JS_COMMENT_BLOCK);
1244
+ this.pos++;
1245
+ break;
1246
+ default:
1247
+ this.startText();
1248
+ break;
1249
+ }
1231
1250
  } else if (!states_exports.checkForPlaceholder(this, code)) {
1232
1251
  this.startText();
1233
1252
  }
@@ -1246,7 +1265,31 @@ var HTML_CONTENT = {
1246
1265
  }
1247
1266
  },
1248
1267
  eof: htmlEOF,
1249
- return() {
1268
+ return(child) {
1269
+ var _a, _b, _c, _d;
1270
+ switch (child.state) {
1271
+ case states_exports.JS_COMMENT_LINE:
1272
+ (_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
1273
+ start: child.start,
1274
+ end: child.end,
1275
+ value: {
1276
+ start: child.start + 2,
1277
+ end: child.end
1278
+ }
1279
+ });
1280
+ break;
1281
+ case states_exports.JS_COMMENT_BLOCK: {
1282
+ (_d = (_c = this.options).onComment) == null ? void 0 : _d.call(_c, {
1283
+ start: child.start,
1284
+ end: child.end,
1285
+ value: {
1286
+ start: child.start + 2,
1287
+ end: child.end - 2
1288
+ }
1289
+ });
1290
+ break;
1291
+ }
1292
+ }
1250
1293
  }
1251
1294
  };
1252
1295
  function isBeginningOfLine(parser) {
@@ -1746,6 +1789,7 @@ var CONCISE_TAG_VAR_TERMINATORS = [
1746
1789
  40 /* OPEN_PAREN */,
1747
1790
  124 /* PIPE */,
1748
1791
  61 /* EQUAL */,
1792
+ 44 /* COMMA */,
1749
1793
  [58 /* COLON */, 61 /* EQUAL */]
1750
1794
  ];
1751
1795
  var HTML_TAG_VAR_TERMINATORS = [
@@ -1753,6 +1797,7 @@ var HTML_TAG_VAR_TERMINATORS = [
1753
1797
  40 /* OPEN_PAREN */,
1754
1798
  124 /* PIPE */,
1755
1799
  61 /* EQUAL */,
1800
+ 44 /* COMMA */,
1756
1801
  [58 /* COLON */, 61 /* EQUAL */],
1757
1802
  [47 /* FORWARD_SLASH */, 62 /* CLOSE_ANGLE_BRACKET */]
1758
1803
  ];
@@ -1912,10 +1957,17 @@ var OPEN_TAG = {
1912
1957
  if (code === 60 /* OPEN_ANGLE_BRACKET */) {
1913
1958
  return this.emitError(this.pos, 2 /* INVALID_ATTRIBUTE_NAME */, 'Invalid attribute name. Attribute name cannot begin with the "<" character.');
1914
1959
  }
1915
- if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 42 /* ASTERISK */) {
1916
- this.enterState(states_exports.JS_COMMENT_BLOCK);
1917
- this.pos++;
1918
- return;
1960
+ if (code === 47 /* FORWARD_SLASH */) {
1961
+ switch (this.lookAtCharCodeAhead(1)) {
1962
+ case 47 /* FORWARD_SLASH */:
1963
+ this.enterState(states_exports.JS_COMMENT_LINE);
1964
+ this.pos++;
1965
+ return;
1966
+ case 42 /* ASTERISK */:
1967
+ this.enterState(states_exports.JS_COMMENT_BLOCK);
1968
+ this.pos++;
1969
+ return;
1970
+ }
1919
1971
  }
1920
1972
  if (isWhitespaceCode(code)) {
1921
1973
  } else if (code === 44 /* COMMA */) {
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.0.1",
4
+ "version": "5.0.4",
5
5
  "devDependencies": {
6
6
  "@changesets/changelog-github": "^0.4.4",
7
7
  "@changesets/cli": "^2.22.0",