@herb-tools/formatter 0.8.9 → 0.8.10

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
@@ -253,7 +253,7 @@ class Token {
253
253
  }
254
254
 
255
255
  // NOTE: This file is generated by the templates/template.rb script and should not
256
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.9/templates/javascript/packages/core/src/errors.ts.erb
256
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.10/templates/javascript/packages/core/src/errors.ts.erb
257
257
  class HerbError {
258
258
  type;
259
259
  message;
@@ -790,6 +790,40 @@ class ERBMultipleBlocksInTagError extends HerbError {
790
790
  return output;
791
791
  }
792
792
  }
793
+ class ERBCaseWithConditionsError extends HerbError {
794
+ static from(data) {
795
+ return new ERBCaseWithConditionsError({
796
+ type: data.type,
797
+ message: data.message,
798
+ location: Location.from(data.location),
799
+ });
800
+ }
801
+ constructor(props) {
802
+ super(props.type, props.message, props.location);
803
+ }
804
+ toJSON() {
805
+ return {
806
+ ...super.toJSON(),
807
+ type: "ERB_CASE_WITH_CONDITIONS_ERROR",
808
+ };
809
+ }
810
+ toMonacoDiagnostic() {
811
+ return {
812
+ line: this.location.start.line,
813
+ column: this.location.start.column,
814
+ endLine: this.location.end.line,
815
+ endColumn: this.location.end.column,
816
+ message: this.message,
817
+ severity: 'error'
818
+ };
819
+ }
820
+ treeInspect() {
821
+ let output = "";
822
+ output += `@ ERBCaseWithConditionsError ${this.location.treeInspectWithLabel()}\n`;
823
+ output += `└── message: "${this.message}"\n`;
824
+ return output;
825
+ }
826
+ }
793
827
  function fromSerializedError(error) {
794
828
  switch (error.type) {
795
829
  case "UNEXPECTED_ERROR": return UnexpectedError.from(error);
@@ -804,6 +838,7 @@ function fromSerializedError(error) {
804
838
  case "ERB_CONTROL_FLOW_SCOPE_ERROR": return ERBControlFlowScopeError.from(error);
805
839
  case "MISSINGERB_END_TAG_ERROR": return MissingERBEndTagError.from(error);
806
840
  case "ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR": return ERBMultipleBlocksInTagError.from(error);
841
+ case "ERB_CASE_WITH_CONDITIONS_ERROR": return ERBCaseWithConditionsError.from(error);
807
842
  default:
808
843
  throw new Error(`Unknown node type: ${error.type}`);
809
844
  }
@@ -818,7 +853,7 @@ function convertToUTF8(string) {
818
853
  }
819
854
 
820
855
  // NOTE: This file is generated by the templates/template.rb script and should not
821
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.9/templates/javascript/packages/core/src/nodes.ts.erb
856
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.10/templates/javascript/packages/core/src/nodes.ts.erb
822
857
  class Node {
823
858
  type;
824
859
  location;
@@ -3072,7 +3107,7 @@ class ParseResult extends Result {
3072
3107
  }
3073
3108
 
3074
3109
  // NOTE: This file is generated by the templates/template.rb script and should not
3075
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.9/templates/javascript/packages/core/src/node-type-guards.ts.erb
3110
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.10/templates/javascript/packages/core/src/node-type-guards.ts.erb
3076
3111
  /**
3077
3112
  * Type guard functions for AST nodes.
3078
3113
  * These functions provide type checking by combining both instanceof
@@ -3569,7 +3604,7 @@ function getNodesAfterPosition(nodes, position, inclusive = true) {
3569
3604
  }
3570
3605
 
3571
3606
  // NOTE: This file is generated by the templates/template.rb script and should not
3572
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.9/templates/javascript/packages/core/src/visitor.ts.erb
3607
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.10/templates/javascript/packages/core/src/visitor.ts.erb
3573
3608
  class Visitor {
3574
3609
  visit(node) {
3575
3610
  if (!node)
@@ -4719,10 +4754,15 @@ class FormatPrinter extends Printer {
4719
4754
  }
4720
4755
  /**
4721
4756
  * Format ERB content with proper spacing around the inner content.
4722
- * Returns empty string if content is empty, otherwise wraps content with single spaces.
4757
+ * Returns empty string if content is empty, otherwise adds a leading space
4758
+ * and a trailing space (or newline for heredoc content starting with "<<").
4723
4759
  */
4724
4760
  formatERBContent(content) {
4725
- return content.trim() ? ` ${content.trim()} ` : "";
4761
+ let trimmedContent = content.trim();
4762
+ // See: https://github.com/marcoroth/herb/issues/476
4763
+ // TODO: revisit once we have access to Prism nodes
4764
+ let suffix = trimmedContent.startsWith("<<") ? "\n" : " ";
4765
+ return trimmedContent ? ` ${trimmedContent}${suffix}` : "";
4726
4766
  }
4727
4767
  /**
4728
4768
  * Count total attributes including those inside ERB conditionals