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