Skip to content

Commit

Permalink
fix: tweaks to the line length calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
revelt committed Jun 7, 2021
1 parent b7293b0 commit 4ec1fe2
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 222 deletions.
2 changes: 1 addition & 1 deletion packages/html-crush/coverage/coverage-summary.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"total":{"lines":{"total":352,"covered":328,"skipped":0,"pct":93.18},"statements":{"total":358,"covered":334,"skipped":0,"pct":93.3},"functions":{"total":10,"covered":10,"skipped":0,"pct":100},"branches":{"total":636,"covered":589,"skipped":0,"pct":92.61}}}
{"total":{"lines":{"total":352,"covered":329,"skipped":0,"pct":93.47},"statements":{"total":358,"covered":335,"skipped":0,"pct":93.58},"functions":{"total":10,"covered":10,"skipped":0,"pct":100},"branches":{"total":634,"covered":588,"skipped":0,"pct":92.74}}}
5 changes: 2 additions & 3 deletions packages/html-crush/dist/html-crush.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ function crush(str, originalOpts) {
}
cpl++;
if (!doNothing && withinStyleTag && str[i] === "}" && str[i - 1] === "}") {
if (countCharactersPerLine >= opts.lineLengthLimit) {
if (countCharactersPerLine + 1 >= opts.lineLengthLimit) {
finalIndexesToDelete.push(i, i, lineEnding);
countCharactersPerLine = 0;
} else {
stageFrom = i;
stageTo = i;
Expand Down Expand Up @@ -427,8 +428,6 @@ function crush(str, originalOpts) {
finalIndexesToDelete.push(stageFrom, stageTo, _whatToAdd);
lastLinebreak = null;
}
} else {
countCharactersPerLine -= lastLinebreak || 0;
}
}
if (str[i].trim() && (CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i]) || str[~-i] && CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[~-i])) && isStr(leftTagName) && (!tagName || !opts.mindTheInlineTags.includes(tagName)) && !(str[i] === "<" && stringMatchLeftRight.matchRight(str, i, opts.mindTheInlineTags, {
Expand Down
12 changes: 2 additions & 10 deletions packages/html-crush/dist/html-crush.dev.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3097,8 +3097,9 @@ function crush(str, originalOpts) {
withinStyleTag &&
str[i] === "}" &&
str[i - 1] === "}") {
if (countCharactersPerLine >= opts.lineLengthLimit) {
if (countCharactersPerLine + 1 >= opts.lineLengthLimit) {
finalIndexesToDelete.push(i, i, lineEnding);
countCharactersPerLine = 0;
}
else {
stageFrom = i;
Expand Down Expand Up @@ -3677,9 +3678,6 @@ function crush(str, originalOpts) {
// );
// }
}
else {
countCharactersPerLine -= lastLinebreak || 0;
}
}
// 2. put this current place into stage
// =============================================================
Expand Down Expand Up @@ -3722,12 +3720,6 @@ function crush(str, originalOpts) {
stageFrom = null;
stageTo = null;
stageAdd = null;
// if (str[i] === "\n" || str[i] === "\r") {
// countCharactersPerLine -= lastLinebreak;
// console.log(
// `1449 SET countCharactersPerLine = ${countCharactersPerLine}`
// );
// }
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions packages/html-crush/dist/html-crush.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ function crush(str, originalOpts) {
}
cpl++;
if (!doNothing && withinStyleTag && str[i] === "}" && str[i - 1] === "}") {
if (countCharactersPerLine >= opts.lineLengthLimit) {
if (countCharactersPerLine + 1 >= opts.lineLengthLimit) {
finalIndexesToDelete.push(i, i, lineEnding);
countCharactersPerLine = 0;
} else {
stageFrom = i;
stageTo = i;
Expand Down Expand Up @@ -404,8 +405,6 @@ function crush(str, originalOpts) {
finalIndexesToDelete.push(stageFrom, stageTo, whatToAdd);
lastLinebreak = null;
}
} else {
countCharactersPerLine -= lastLinebreak || 0;
}
}
if (str[i].trim() && (CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i]) || str[~-i] && CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[~-i])) && isStr(leftTagName) && (!tagName || !opts.mindTheInlineTags.includes(tagName)) && !(str[i] === "<" && matchRight(str, i, opts.mindTheInlineTags, {
Expand Down
Loading

0 comments on commit 4ec1fe2

Please sign in to comment.