@herb-tools/formatter 0.6.1 → 0.7.0
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 +59 -19
- package/dist/herb-format.js.map +1 -1
- package/dist/index.cjs +19 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +19 -8
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/cli.ts +4 -2
- package/src/format-printer.ts +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -196,7 +196,7 @@ class Token {
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
199
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.
|
|
199
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/errors.ts.erb
|
|
200
200
|
class HerbError {
|
|
201
201
|
type;
|
|
202
202
|
message;
|
|
@@ -646,7 +646,7 @@ function convertToUTF8(string) {
|
|
|
646
646
|
}
|
|
647
647
|
|
|
648
648
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
649
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.
|
|
649
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/nodes.ts.erb
|
|
650
650
|
class Node {
|
|
651
651
|
type;
|
|
652
652
|
location;
|
|
@@ -686,7 +686,7 @@ class Node {
|
|
|
686
686
|
return "∅\n";
|
|
687
687
|
if (array.length === 0)
|
|
688
688
|
return "[]\n";
|
|
689
|
-
let output = `(${array.length} item${array.length
|
|
689
|
+
let output = `(${array.length} item${array.length === 1 ? "" : "s"})\n`;
|
|
690
690
|
array.forEach((item, index) => {
|
|
691
691
|
const isLast = index === array.length - 1;
|
|
692
692
|
if (item instanceof Node || item instanceof HerbError) {
|
|
@@ -710,7 +710,7 @@ class Node {
|
|
|
710
710
|
.treeInspect()
|
|
711
711
|
.trimStart()
|
|
712
712
|
.split("\n")
|
|
713
|
-
.map((line, index) => index
|
|
713
|
+
.map((line, index) => index === 0 ? line.trimStart() : `${prefix}${prefix2}${line}`)
|
|
714
714
|
.join("\n")
|
|
715
715
|
.trimStart();
|
|
716
716
|
output += `\n`;
|
|
@@ -951,6 +951,7 @@ class HTMLElementNode extends Node {
|
|
|
951
951
|
body;
|
|
952
952
|
close_tag;
|
|
953
953
|
is_void;
|
|
954
|
+
source;
|
|
954
955
|
static get type() {
|
|
955
956
|
return "AST_HTML_ELEMENT_NODE";
|
|
956
957
|
}
|
|
@@ -964,6 +965,7 @@ class HTMLElementNode extends Node {
|
|
|
964
965
|
body: (data.body || []).map(node => fromSerializedNode(node)),
|
|
965
966
|
close_tag: data.close_tag ? fromSerializedNode((data.close_tag)) : null,
|
|
966
967
|
is_void: data.is_void,
|
|
968
|
+
source: data.source,
|
|
967
969
|
});
|
|
968
970
|
}
|
|
969
971
|
constructor(props) {
|
|
@@ -973,6 +975,7 @@ class HTMLElementNode extends Node {
|
|
|
973
975
|
this.body = props.body;
|
|
974
976
|
this.close_tag = props.close_tag;
|
|
975
977
|
this.is_void = props.is_void;
|
|
978
|
+
this.source = props.source;
|
|
976
979
|
}
|
|
977
980
|
accept(visitor) {
|
|
978
981
|
visitor.visitHTMLElementNode(this);
|
|
@@ -1004,6 +1007,7 @@ class HTMLElementNode extends Node {
|
|
|
1004
1007
|
body: this.body.map(node => node.toJSON()),
|
|
1005
1008
|
close_tag: this.close_tag ? this.close_tag.toJSON() : null,
|
|
1006
1009
|
is_void: this.is_void,
|
|
1010
|
+
source: this.source,
|
|
1007
1011
|
};
|
|
1008
1012
|
}
|
|
1009
1013
|
treeInspect() {
|
|
@@ -1014,7 +1018,8 @@ class HTMLElementNode extends Node {
|
|
|
1014
1018
|
output += `├── tag_name: ${this.tag_name ? this.tag_name.treeInspect() : "∅"}\n`;
|
|
1015
1019
|
output += `├── body: ${this.inspectArray(this.body, "│ ")}`;
|
|
1016
1020
|
output += `├── close_tag: ${this.inspectNode(this.close_tag, "│ ")}`;
|
|
1017
|
-
output +=
|
|
1021
|
+
output += `├── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
|
|
1022
|
+
output += `└── source: ${this.source ? JSON.stringify(this.source) : "∅"}\n`;
|
|
1018
1023
|
return output;
|
|
1019
1024
|
}
|
|
1020
1025
|
}
|
|
@@ -2875,7 +2880,7 @@ class ParseResult extends Result {
|
|
|
2875
2880
|
}
|
|
2876
2881
|
|
|
2877
2882
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
2878
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.
|
|
2883
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/node-type-guards.ts.erb
|
|
2879
2884
|
/**
|
|
2880
2885
|
* Type guard functions for AST nodes.
|
|
2881
2886
|
* These functions provide type checking by combining both instanceof
|
|
@@ -3260,7 +3265,11 @@ function isParseResult(object) {
|
|
|
3260
3265
|
* Checks if a node is an ERB output node (generates content: <%= %> or <%== %>)
|
|
3261
3266
|
*/
|
|
3262
3267
|
function isERBOutputNode(node) {
|
|
3263
|
-
|
|
3268
|
+
if (!isNode(node, ERBContentNode))
|
|
3269
|
+
return false;
|
|
3270
|
+
if (!node.tag_opening?.value)
|
|
3271
|
+
return false;
|
|
3272
|
+
return ["<%=", "<%=="].includes(node.tag_opening?.value);
|
|
3264
3273
|
}
|
|
3265
3274
|
/**
|
|
3266
3275
|
* Checks if a node is a non-output ERB node (control flow: <% %>)
|
|
@@ -3358,7 +3367,7 @@ function getNodesAfterPosition(nodes, position, inclusive = true) {
|
|
|
3358
3367
|
}
|
|
3359
3368
|
|
|
3360
3369
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
3361
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.
|
|
3370
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/visitor.ts.erb
|
|
3362
3371
|
class Visitor {
|
|
3363
3372
|
visit(node) {
|
|
3364
3373
|
if (!node)
|
|
@@ -3587,6 +3596,8 @@ class Printer extends Visitor {
|
|
|
3587
3596
|
* @throws {Error} When node has parse errors and ignoreErrors is false
|
|
3588
3597
|
*/
|
|
3589
3598
|
print(input, options = DEFAULT_PRINT_OPTIONS) {
|
|
3599
|
+
if (!input)
|
|
3600
|
+
return "";
|
|
3590
3601
|
if (isToken(input)) {
|
|
3591
3602
|
return input.value;
|
|
3592
3603
|
}
|