ember-estree 0.6.5 → 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 +13 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-estree",
3
- "version": "0.6.5",
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
@@ -831,8 +831,19 @@ export function print(node) {
831
831
 
832
832
  case "GlimmerAttrNode": {
833
833
  const name = node.name ?? "";
834
- const value = print(node.value);
835
- 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)}`;
836
847
  }
837
848
 
838
849
  case "GlimmerConcatStatement": {