ember-estree 0.6.4 → 0.6.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/print.js +22 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-estree",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "ESTree generator for gjs and gts file used by ember",
5
5
  "keywords": [
6
6
  "AST",
package/src/print.js CHANGED
@@ -83,6 +83,9 @@ export function print(node) {
83
83
  case "ChainExpression":
84
84
  return print(node.expression);
85
85
 
86
+ case "ParenthesizedExpression":
87
+ return `(${print(node.expression)})`;
88
+
86
89
  case "ArrowFunctionExpression": {
87
90
  const typeParams = node.typeParameters ? print(node.typeParameters) : "";
88
91
  const params = (node.params ?? []).map(print).join(", ");
@@ -772,11 +775,13 @@ export function print(node) {
772
775
  const attrs = (node.attributes ?? []).map(print).join(" ");
773
776
  const modifiers = (node.modifiers ?? []).map(print).join(" ");
774
777
  const children = (node.children ?? []).map(print).join("");
778
+ const blockParams = node.blockParams ?? [];
779
+ const asParams = blockParams.length ? ` as |${blockParams.join(" ")}|` : "";
775
780
  const parts = [tag];
776
781
  if (attrs) parts.push(attrs);
777
782
  if (modifiers) parts.push(modifiers);
778
783
  if (node.selfClosing) return `<${parts.join(" ")} />`;
779
- return `<${parts.join(" ")}>${children}</${tag}>`;
784
+ return `<${parts.join(" ")}${asParams}>${children}</${tag}>`;
780
785
  }
781
786
 
782
787
  case "GlimmerElementNodePart":
@@ -799,6 +804,8 @@ export function print(node) {
799
804
  const path = print(node.path);
800
805
  const params = (node.params ?? []).map(print).join(" ");
801
806
  const hash = node.hash ? print(node.hash) : "";
807
+ const blockParams = node.program?.blockParams ?? [];
808
+ const asParams = blockParams.length ? ` as |${blockParams.join(" ")}|` : "";
802
809
  const body = (node.body ?? node.program?.body ?? []).map(print).join("");
803
810
  const inverse = node.inverse
804
811
  ? `{{else}}${(node.inverse.body ?? []).map(print).join("")}`
@@ -806,7 +813,7 @@ export function print(node) {
806
813
  const parts = [path];
807
814
  if (params) parts.push(params);
808
815
  if (hash) parts.push(hash);
809
- return `{{#${parts.join(" ")}}}${body}${inverse}{{/${print(node.path)}}}`;
816
+ return `{{#${parts.join(" ")}${asParams}}}${body}${inverse}{{/${print(node.path)}}}`;
810
817
  }
811
818
 
812
819
  case "GlimmerPathExpression":
@@ -824,8 +831,19 @@ export function print(node) {
824
831
 
825
832
  case "GlimmerAttrNode": {
826
833
  const name = node.name ?? "";
827
- const value = print(node.value);
828
- return `${name}=${value}`;
834
+ const value = node.value;
835
+ // A plain text value carries no quote style in the AST, so quote it
836
+ // (always valid) — printing it raw drops the quotes and corrupts any
837
+ // value with whitespace, e.g. `data-x="a b"` -> `data-x=a b`. An empty
838
+ // text value is a valueless attribute (`<input disabled>`).
839
+ if (value?.type === "GlimmerTextNode") {
840
+ const chars = value.chars ?? "";
841
+ if (chars === "") return name;
842
+ const quote = chars.includes('"') ? "'" : '"';
843
+ return `${name}=${quote}${chars}${quote}`;
844
+ }
845
+ // Mustache (`{{x}}`) and concat (`"a {{b}}"`) values print themselves.
846
+ return `${name}=${print(value)}`;
829
847
  }
830
848
 
831
849
  case "GlimmerConcatStatement": {