@herb-tools/formatter 0.8.3 → 0.8.5

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.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.3/templates/javascript/packages/core/src/errors.ts.erb
246
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.5/templates/javascript/packages/core/src/errors.ts.erb
247
247
  class HerbError {
248
248
  type;
249
249
  message;
@@ -746,6 +746,40 @@ class MissingERBEndTagError extends HerbError {
746
746
  return output;
747
747
  }
748
748
  }
749
+ class ERBMultipleBlocksInTagError extends HerbError {
750
+ static from(data) {
751
+ return new ERBMultipleBlocksInTagError({
752
+ type: data.type,
753
+ message: data.message,
754
+ location: Location.from(data.location),
755
+ });
756
+ }
757
+ constructor(props) {
758
+ super(props.type, props.message, props.location);
759
+ }
760
+ toJSON() {
761
+ return {
762
+ ...super.toJSON(),
763
+ type: "ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR",
764
+ };
765
+ }
766
+ toMonacoDiagnostic() {
767
+ return {
768
+ line: this.location.start.line,
769
+ column: this.location.start.column,
770
+ endLine: this.location.end.line,
771
+ endColumn: this.location.end.column,
772
+ message: this.message,
773
+ severity: 'error'
774
+ };
775
+ }
776
+ treeInspect() {
777
+ let output = "";
778
+ output += `@ ERBMultipleBlocksInTagError ${this.location.treeInspectWithLabel()}\n`;
779
+ output += `└── message: "${this.message}"\n`;
780
+ return output;
781
+ }
782
+ }
749
783
  function fromSerializedError(error) {
750
784
  switch (error.type) {
751
785
  case "UNEXPECTED_ERROR": return UnexpectedError.from(error);
@@ -759,6 +793,7 @@ function fromSerializedError(error) {
759
793
  case "RUBY_PARSE_ERROR": return RubyParseError.from(error);
760
794
  case "ERB_CONTROL_FLOW_SCOPE_ERROR": return ERBControlFlowScopeError.from(error);
761
795
  case "MISSINGERB_END_TAG_ERROR": return MissingERBEndTagError.from(error);
796
+ case "ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR": return ERBMultipleBlocksInTagError.from(error);
762
797
  default:
763
798
  throw new Error(`Unknown node type: ${error.type}`);
764
799
  }
@@ -773,7 +808,7 @@ function convertToUTF8(string) {
773
808
  }
774
809
 
775
810
  // 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.3/templates/javascript/packages/core/src/nodes.ts.erb
811
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.5/templates/javascript/packages/core/src/nodes.ts.erb
777
812
  class Node {
778
813
  type;
779
814
  location;
@@ -3007,7 +3042,7 @@ class ParseResult extends Result {
3007
3042
  }
3008
3043
 
3009
3044
  // 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.3/templates/javascript/packages/core/src/node-type-guards.ts.erb
3045
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.5/templates/javascript/packages/core/src/node-type-guards.ts.erb
3011
3046
  /**
3012
3047
  * Type guard functions for AST nodes.
3013
3048
  * These functions provide type checking by combining both instanceof
@@ -3504,7 +3539,7 @@ function getNodesAfterPosition(nodes, position, inclusive = true) {
3504
3539
  }
3505
3540
 
3506
3541
  // NOTE: This file is generated by the templates/template.rb script and should not
3507
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.3/templates/javascript/packages/core/src/visitor.ts.erb
3542
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.5/templates/javascript/packages/core/src/visitor.ts.erb
3508
3543
  class Visitor {
3509
3544
  visit(node) {
3510
3545
  if (!node)
@@ -4987,13 +5022,30 @@ class FormatPrinter extends Printer {
4987
5022
  * Render multiline attributes for a tag
4988
5023
  */
4989
5024
  renderMultilineAttributes(tagName, allChildren = [], isSelfClosing = false) {
4990
- this.pushWithIndent(`<${tagName}`);
5025
+ const herbDisableComments = allChildren.filter(child => isNode(child, ERBContentNode) && isHerbDisableComment(child));
5026
+ let openingLine = `<${tagName}`;
5027
+ if (herbDisableComments.length > 0) {
5028
+ const commentLines = this.capture(() => {
5029
+ herbDisableComments.forEach(comment => {
5030
+ const wasInlineMode = this.inlineMode;
5031
+ this.inlineMode = true;
5032
+ this.lines.push(" ");
5033
+ this.visit(comment);
5034
+ this.inlineMode = wasInlineMode;
5035
+ });
5036
+ });
5037
+ openingLine += commentLines.join("");
5038
+ }
5039
+ this.pushWithIndent(openingLine);
4991
5040
  this.withIndent(() => {
4992
5041
  allChildren.forEach(child => {
4993
5042
  if (isNode(child, HTMLAttributeNode)) {
4994
5043
  this.pushWithIndent(this.renderAttribute(child));
4995
5044
  }
4996
5045
  else if (!isNode(child, WhitespaceNode)) {
5046
+ if (isNode(child, ERBContentNode) && isHerbDisableComment(child)) {
5047
+ return;
5048
+ }
4997
5049
  this.visit(child);
4998
5050
  }
4999
5051
  });