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