@herb-tools/formatter 0.8.0 → 0.8.1
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/herb-format.js +26 -21
- package/dist/herb-format.js.map +1 -1
- package/dist/index.cjs +14 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +14 -9
- package/dist/index.esm.js.map +1 -1
- package/package.json +5 -5
- package/src/format-helpers.ts +3 -1
- package/src/format-printer.ts +7 -4
package/dist/index.cjs
CHANGED
|
@@ -243,7 +243,7 @@ class Token {
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
246
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.
|
|
246
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.1/templates/javascript/packages/core/src/errors.ts.erb
|
|
247
247
|
class HerbError {
|
|
248
248
|
type;
|
|
249
249
|
message;
|
|
@@ -773,7 +773,7 @@ function convertToUTF8(string) {
|
|
|
773
773
|
}
|
|
774
774
|
|
|
775
775
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
776
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.
|
|
776
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.1/templates/javascript/packages/core/src/nodes.ts.erb
|
|
777
777
|
class Node {
|
|
778
778
|
type;
|
|
779
779
|
location;
|
|
@@ -3007,7 +3007,7 @@ class ParseResult extends Result {
|
|
|
3007
3007
|
}
|
|
3008
3008
|
|
|
3009
3009
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
3010
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.
|
|
3010
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.1/templates/javascript/packages/core/src/node-type-guards.ts.erb
|
|
3011
3011
|
/**
|
|
3012
3012
|
* Type guard functions for AST nodes.
|
|
3013
3013
|
* These functions provide type checking by combining both instanceof
|
|
@@ -3494,7 +3494,7 @@ function getNodesAfterPosition(nodes, position, inclusive = true) {
|
|
|
3494
3494
|
}
|
|
3495
3495
|
|
|
3496
3496
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
3497
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.
|
|
3497
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.1/templates/javascript/packages/core/src/visitor.ts.erb
|
|
3498
3498
|
class Visitor {
|
|
3499
3499
|
visit(node) {
|
|
3500
3500
|
if (!node)
|
|
@@ -4232,7 +4232,8 @@ function lineEndsWithOpeningPunctuation(line) {
|
|
|
4232
4232
|
* Check if a string ends with an ERB tag
|
|
4233
4233
|
*/
|
|
4234
4234
|
function endsWithERBTag(text) {
|
|
4235
|
-
|
|
4235
|
+
const trimmed = text.trim();
|
|
4236
|
+
return /%>$/.test(trimmed) || /%>\S+$/.test(trimmed);
|
|
4236
4237
|
}
|
|
4237
4238
|
/**
|
|
4238
4239
|
* Check if a string starts with an ERB tag
|
|
@@ -5898,7 +5899,7 @@ class FormatPrinter extends Printer {
|
|
|
5898
5899
|
return false;
|
|
5899
5900
|
const firstWord = words[0];
|
|
5900
5901
|
const firstChar = firstWord[0];
|
|
5901
|
-
if (
|
|
5902
|
+
if (/\s/.test(firstChar)) {
|
|
5902
5903
|
return false;
|
|
5903
5904
|
}
|
|
5904
5905
|
lastUnit.unit.content += firstWord;
|
|
@@ -5912,6 +5913,12 @@ class FormatPrinter extends Printer {
|
|
|
5912
5913
|
node: textNode
|
|
5913
5914
|
});
|
|
5914
5915
|
}
|
|
5916
|
+
else if (endsWithWhitespace(textNode.content)) {
|
|
5917
|
+
result.push({
|
|
5918
|
+
unit: { content: ' ', type: 'text', isAtomic: false, breaksFlow: false },
|
|
5919
|
+
node: textNode
|
|
5920
|
+
});
|
|
5921
|
+
}
|
|
5915
5922
|
return true;
|
|
5916
5923
|
}
|
|
5917
5924
|
/**
|
|
@@ -5972,9 +5979,7 @@ class FormatPrinter extends Printer {
|
|
|
5972
5979
|
const hasWhitespace = this.hasWhitespaceBeforeNode(children, lastProcessedIndex, index, child);
|
|
5973
5980
|
const lastUnit = result[result.length - 1];
|
|
5974
5981
|
const lastIsAtomic = lastUnit.unit.isAtomic && (lastUnit.unit.type === 'erb' || lastUnit.unit.type === 'inline');
|
|
5975
|
-
|
|
5976
|
-
const startsWithClosingPunct = trimmed.length > 0 && /^[.!?:;]/.test(trimmed);
|
|
5977
|
-
if (lastIsAtomic && (!hasWhitespace || startsWithClosingPunct) && this.tryMergeTextAfterAtomic(result, child)) {
|
|
5982
|
+
if (lastIsAtomic && !hasWhitespace && this.tryMergeTextAfterAtomic(result, child)) {
|
|
5978
5983
|
return;
|
|
5979
5984
|
}
|
|
5980
5985
|
}
|