htmljs-parser 5.8.2 → 5.9.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.
package/dist/index.js CHANGED
@@ -98,7 +98,18 @@ function getLines(src) {
98
98
  return lines;
99
99
  }
100
100
  function htmlEOF() {
101
- this.endText();
101
+ if (!this.activeTag || this.activeTag.concise) {
102
+ const pos = this.pos;
103
+ let cur = this.pos;
104
+ while (cur && isWhitespaceCode(this.data.charCodeAt(cur - 1))) {
105
+ cur--;
106
+ }
107
+ this.pos = cur;
108
+ this.endText();
109
+ this.pos = pos;
110
+ } else {
111
+ this.endText();
112
+ }
102
113
  while (this.activeTag) {
103
114
  if (this.activeTag.concise) {
104
115
  this.closeTagEnd(this.pos, this.pos, void 0);
@@ -239,7 +250,9 @@ var Parser = class {
239
250
  var _a, _b;
240
251
  const start = this.textPos;
241
252
  if (start !== -1) {
242
- (_b = (_a = this.options).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
253
+ if (start !== this.pos) {
254
+ (_b = (_a = this.options).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
255
+ }
243
256
  this.textPos = -1;
244
257
  }
245
258
  }
@@ -1179,7 +1192,7 @@ var BEGIN_DELIMITED_HTML_BLOCK = {
1179
1192
  },
1180
1193
  eol(len, block) {
1181
1194
  this.beginHtmlBlock(block.delimiter, false);
1182
- handleDelimitedBlockEOL(this, len, block);
1195
+ handleDelimitedBlockEOL(this, true, len, block);
1183
1196
  },
1184
1197
  eof: htmlEOF,
1185
1198
  return() {
@@ -1193,21 +1206,20 @@ function handleDelimitedEOL(parser, newLineLength, content) {
1193
1206
  return true;
1194
1207
  }
1195
1208
  if (content.delimiter) {
1196
- handleDelimitedBlockEOL(parser, newLineLength, content);
1209
+ handleDelimitedBlockEOL(parser, false, newLineLength, content);
1197
1210
  return true;
1198
1211
  }
1199
1212
  return false;
1200
1213
  }
1201
- function handleDelimitedBlockEOL(parser, newLineLength, {
1214
+ function handleDelimitedBlockEOL(parser, first, newLineLength, {
1202
1215
  indent,
1203
1216
  delimiter
1204
1217
  }) {
1205
1218
  const endHtmlBlockLookahead = indent + delimiter;
1206
1219
  if (parser.lookAheadFor(endHtmlBlockLookahead, parser.pos + newLineLength)) {
1207
- parser.startText();
1208
- parser.pos += newLineLength;
1209
1220
  parser.endText();
1210
- parser.pos += endHtmlBlockLookahead.length;
1221
+ parser.pos += newLineLength + endHtmlBlockLookahead.length;
1222
+ parser.forward = 0;
1211
1223
  if (parser.consumeWhitespaceOnLine(0)) {
1212
1224
  parser.exitState();
1213
1225
  parser.exitState();
@@ -1219,14 +1231,24 @@ function handleDelimitedBlockEOL(parser, newLineLength, {
1219
1231
  );
1220
1232
  }
1221
1233
  } else if (parser.lookAheadFor(indent, parser.pos + newLineLength)) {
1222
- parser.startText();
1234
+ if (!first)
1235
+ parser.startText();
1236
+ parser.pos += newLineLength;
1237
+ parser.endText();
1223
1238
  parser.pos += indent.length;
1239
+ parser.forward = 0;
1240
+ parser.startText();
1224
1241
  } else if (indent && !parser.onlyWhitespaceRemainsOnLine(newLineLength)) {
1242
+ const pos = parser.pos;
1243
+ let cur = parser.pos;
1244
+ while (cur && isWhitespaceCode(parser.data.charCodeAt(cur - 1))) {
1245
+ cur--;
1246
+ }
1247
+ parser.pos = cur;
1225
1248
  parser.endText();
1249
+ parser.pos = pos;
1226
1250
  parser.exitState();
1227
1251
  parser.exitState();
1228
- } else if (parser.pos + newLineLength !== parser.maxPos) {
1229
- parser.startText();
1230
1252
  }
1231
1253
  }
1232
1254
 
package/dist/index.mjs CHANGED
@@ -70,7 +70,18 @@ function getLines(src) {
70
70
  return lines;
71
71
  }
72
72
  function htmlEOF() {
73
- this.endText();
73
+ if (!this.activeTag || this.activeTag.concise) {
74
+ const pos = this.pos;
75
+ let cur = this.pos;
76
+ while (cur && isWhitespaceCode(this.data.charCodeAt(cur - 1))) {
77
+ cur--;
78
+ }
79
+ this.pos = cur;
80
+ this.endText();
81
+ this.pos = pos;
82
+ } else {
83
+ this.endText();
84
+ }
74
85
  while (this.activeTag) {
75
86
  if (this.activeTag.concise) {
76
87
  this.closeTagEnd(this.pos, this.pos, void 0);
@@ -211,7 +222,9 @@ var Parser = class {
211
222
  var _a, _b;
212
223
  const start = this.textPos;
213
224
  if (start !== -1) {
214
- (_b = (_a = this.options).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
225
+ if (start !== this.pos) {
226
+ (_b = (_a = this.options).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
227
+ }
215
228
  this.textPos = -1;
216
229
  }
217
230
  }
@@ -1151,7 +1164,7 @@ var BEGIN_DELIMITED_HTML_BLOCK = {
1151
1164
  },
1152
1165
  eol(len, block) {
1153
1166
  this.beginHtmlBlock(block.delimiter, false);
1154
- handleDelimitedBlockEOL(this, len, block);
1167
+ handleDelimitedBlockEOL(this, true, len, block);
1155
1168
  },
1156
1169
  eof: htmlEOF,
1157
1170
  return() {
@@ -1165,21 +1178,20 @@ function handleDelimitedEOL(parser, newLineLength, content) {
1165
1178
  return true;
1166
1179
  }
1167
1180
  if (content.delimiter) {
1168
- handleDelimitedBlockEOL(parser, newLineLength, content);
1181
+ handleDelimitedBlockEOL(parser, false, newLineLength, content);
1169
1182
  return true;
1170
1183
  }
1171
1184
  return false;
1172
1185
  }
1173
- function handleDelimitedBlockEOL(parser, newLineLength, {
1186
+ function handleDelimitedBlockEOL(parser, first, newLineLength, {
1174
1187
  indent,
1175
1188
  delimiter
1176
1189
  }) {
1177
1190
  const endHtmlBlockLookahead = indent + delimiter;
1178
1191
  if (parser.lookAheadFor(endHtmlBlockLookahead, parser.pos + newLineLength)) {
1179
- parser.startText();
1180
- parser.pos += newLineLength;
1181
1192
  parser.endText();
1182
- parser.pos += endHtmlBlockLookahead.length;
1193
+ parser.pos += newLineLength + endHtmlBlockLookahead.length;
1194
+ parser.forward = 0;
1183
1195
  if (parser.consumeWhitespaceOnLine(0)) {
1184
1196
  parser.exitState();
1185
1197
  parser.exitState();
@@ -1191,14 +1203,24 @@ function handleDelimitedBlockEOL(parser, newLineLength, {
1191
1203
  );
1192
1204
  }
1193
1205
  } else if (parser.lookAheadFor(indent, parser.pos + newLineLength)) {
1194
- parser.startText();
1206
+ if (!first)
1207
+ parser.startText();
1208
+ parser.pos += newLineLength;
1209
+ parser.endText();
1195
1210
  parser.pos += indent.length;
1211
+ parser.forward = 0;
1212
+ parser.startText();
1196
1213
  } else if (indent && !parser.onlyWhitespaceRemainsOnLine(newLineLength)) {
1214
+ const pos = parser.pos;
1215
+ let cur = parser.pos;
1216
+ while (cur && isWhitespaceCode(parser.data.charCodeAt(cur - 1))) {
1217
+ cur--;
1218
+ }
1219
+ parser.pos = cur;
1197
1220
  parser.endText();
1221
+ parser.pos = pos;
1198
1222
  parser.exitState();
1199
1223
  parser.exitState();
1200
- } else if (parser.pos + newLineLength !== parser.maxPos) {
1201
- parser.startText();
1202
1224
  }
1203
1225
  }
1204
1226
 
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.8.2",
4
+ "version": "5.9.0",
5
5
  "devDependencies": {
6
6
  "@changesets/changelog-github": "^0.5.0",
7
7
  "@changesets/cli": "^2.27.1",