htmljs-parser 5.0.0 → 5.0.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
@@ -727,6 +727,7 @@ var CLOSE_TAG = {
727
727
  }
728
728
  };
729
729
  function checkForClosingTag(parser) {
730
+ var _a, _b;
730
731
  const curPos = parser.pos + 1;
731
732
  let match = !!parser.lookAheadFor("/>");
732
733
  let skip = 3;
@@ -743,6 +744,10 @@ function checkForClosingTag(parser) {
743
744
  }
744
745
  if (match) {
745
746
  parser.endText();
747
+ (_b = (_a = parser.options).onCloseTagStart) == null ? void 0 : _b.call(_a, {
748
+ start: curPos - 1,
749
+ end: curPos + 1
750
+ });
746
751
  if (ensureExpectedCloseTag(parser, {
747
752
  start: parser.pos,
748
753
  end: parser.pos += skip
@@ -1037,7 +1042,10 @@ var EXPRESSION = {
1037
1042
  this.pos++;
1038
1043
  break;
1039
1044
  default: {
1040
- if (!canCharCodeBeFollowedByDivision(this.getPreviousNonWhitespaceCharCode())) {
1045
+ if (canCharCodeBeFollowedByDivision(this.getPreviousNonWhitespaceCharCode())) {
1046
+ this.pos++;
1047
+ this.consumeWhitespace();
1048
+ } else {
1041
1049
  this.enterState(states_exports.REGULAR_EXPRESSION);
1042
1050
  }
1043
1051
  break;
@@ -1098,9 +1106,9 @@ var EXPRESSION = {
1098
1106
  };
1099
1107
  function buildPattern(type) {
1100
1108
  const space = type === 1 /* CONCISE_ATTRS */ ? "[ \\t]" : "\\s";
1101
- 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]+[^=/,;:>])`;
1102
1110
  const unary = "\\b(?<![.]\\s*)(?:a(?:sync|wait)|keyof|class|function|new|typeof|void)\\b";
1103
- const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(])`;
1111
+ const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(]|/[^>])`;
1104
1112
  const lookBehindPattern = `(?<=${unary}|${binary})`;
1105
1113
  return new RegExp(`${lookAheadPattern}|${lookBehindPattern}`, "ym");
1106
1114
  }
@@ -1244,6 +1252,22 @@ var HTML_CONTENT = {
1244
1252
  this.endText();
1245
1253
  this.enterState(states_exports.INLINE_SCRIPT);
1246
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
+ }
1247
1271
  } else if (!states_exports.checkForPlaceholder(this, code)) {
1248
1272
  this.startText();
1249
1273
  }
@@ -1262,7 +1286,31 @@ var HTML_CONTENT = {
1262
1286
  }
1263
1287
  },
1264
1288
  eof: htmlEOF,
1265
- 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
+ }
1266
1314
  }
1267
1315
  };
1268
1316
  function isBeginningOfLine(parser) {
@@ -1928,10 +1976,17 @@ var OPEN_TAG = {
1928
1976
  if (code === 60 /* OPEN_ANGLE_BRACKET */) {
1929
1977
  return this.emitError(this.pos, 2 /* INVALID_ATTRIBUTE_NAME */, 'Invalid attribute name. Attribute name cannot begin with the "<" character.');
1930
1978
  }
1931
- if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 42 /* ASTERISK */) {
1932
- this.enterState(states_exports.JS_COMMENT_BLOCK);
1933
- this.pos++;
1934
- return;
1979
+ if (code === 47 /* FORWARD_SLASH */) {
1980
+ switch (this.lookAtCharCodeAhead(1)) {
1981
+ case 47 /* FORWARD_SLASH */:
1982
+ this.enterState(states_exports.JS_COMMENT_LINE);
1983
+ this.pos++;
1984
+ return;
1985
+ case 42 /* ASTERISK */:
1986
+ this.enterState(states_exports.JS_COMMENT_BLOCK);
1987
+ this.pos++;
1988
+ return;
1989
+ }
1935
1990
  }
1936
1991
  if (isWhitespaceCode(code)) {
1937
1992
  } else if (code === 44 /* COMMA */) {
package/dist/index.mjs CHANGED
@@ -706,6 +706,7 @@ var CLOSE_TAG = {
706
706
  }
707
707
  };
708
708
  function checkForClosingTag(parser) {
709
+ var _a, _b;
709
710
  const curPos = parser.pos + 1;
710
711
  let match = !!parser.lookAheadFor("/>");
711
712
  let skip = 3;
@@ -722,6 +723,10 @@ function checkForClosingTag(parser) {
722
723
  }
723
724
  if (match) {
724
725
  parser.endText();
726
+ (_b = (_a = parser.options).onCloseTagStart) == null ? void 0 : _b.call(_a, {
727
+ start: curPos - 1,
728
+ end: curPos + 1
729
+ });
725
730
  if (ensureExpectedCloseTag(parser, {
726
731
  start: parser.pos,
727
732
  end: parser.pos += skip
@@ -1016,7 +1021,10 @@ var EXPRESSION = {
1016
1021
  this.pos++;
1017
1022
  break;
1018
1023
  default: {
1019
- if (!canCharCodeBeFollowedByDivision(this.getPreviousNonWhitespaceCharCode())) {
1024
+ if (canCharCodeBeFollowedByDivision(this.getPreviousNonWhitespaceCharCode())) {
1025
+ this.pos++;
1026
+ this.consumeWhitespace();
1027
+ } else {
1020
1028
  this.enterState(states_exports.REGULAR_EXPRESSION);
1021
1029
  }
1022
1030
  break;
@@ -1077,9 +1085,9 @@ var EXPRESSION = {
1077
1085
  };
1078
1086
  function buildPattern(type) {
1079
1087
  const space = type === 1 /* CONCISE_ATTRS */ ? "[ \\t]" : "\\s";
1080
- 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]+[^=/,;:>])`;
1081
1089
  const unary = "\\b(?<![.]\\s*)(?:a(?:sync|wait)|keyof|class|function|new|typeof|void)\\b";
1082
- const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(])`;
1090
+ const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(]|/[^>])`;
1083
1091
  const lookBehindPattern = `(?<=${unary}|${binary})`;
1084
1092
  return new RegExp(`${lookAheadPattern}|${lookBehindPattern}`, "ym");
1085
1093
  }
@@ -1223,6 +1231,22 @@ var HTML_CONTENT = {
1223
1231
  this.endText();
1224
1232
  this.enterState(states_exports.INLINE_SCRIPT);
1225
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
+ }
1226
1250
  } else if (!states_exports.checkForPlaceholder(this, code)) {
1227
1251
  this.startText();
1228
1252
  }
@@ -1241,7 +1265,31 @@ var HTML_CONTENT = {
1241
1265
  }
1242
1266
  },
1243
1267
  eof: htmlEOF,
1244
- 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
+ }
1245
1293
  }
1246
1294
  };
1247
1295
  function isBeginningOfLine(parser) {
@@ -1907,10 +1955,17 @@ var OPEN_TAG = {
1907
1955
  if (code === 60 /* OPEN_ANGLE_BRACKET */) {
1908
1956
  return this.emitError(this.pos, 2 /* INVALID_ATTRIBUTE_NAME */, 'Invalid attribute name. Attribute name cannot begin with the "<" character.');
1909
1957
  }
1910
- if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 42 /* ASTERISK */) {
1911
- this.enterState(states_exports.JS_COMMENT_BLOCK);
1912
- this.pos++;
1913
- return;
1958
+ if (code === 47 /* FORWARD_SLASH */) {
1959
+ switch (this.lookAtCharCodeAhead(1)) {
1960
+ case 47 /* FORWARD_SLASH */:
1961
+ this.enterState(states_exports.JS_COMMENT_LINE);
1962
+ this.pos++;
1963
+ return;
1964
+ case 42 /* ASTERISK */:
1965
+ this.enterState(states_exports.JS_COMMENT_BLOCK);
1966
+ this.pos++;
1967
+ return;
1968
+ }
1914
1969
  }
1915
1970
  if (isWhitespaceCode(code)) {
1916
1971
  } 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.0",
4
+ "version": "5.0.3",
5
5
  "devDependencies": {
6
6
  "@changesets/changelog-github": "^0.4.4",
7
7
  "@changesets/cli": "^2.22.0",