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