ember-estree 0.6.5 → 0.6.7

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 +27 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-estree",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
4
4
  "description": "ESTree generator for gjs and gts file used by ember",
5
5
  "keywords": [
6
6
  "AST",
package/src/print.js CHANGED
@@ -373,6 +373,8 @@ export function print(node) {
373
373
  const attrs = (node.attributes ?? []).map(print);
374
374
  const attrStr = attrs.length ? ` with { ${attrs.join(", ")} }` : "";
375
375
  if (specs.length === 0) return `import ${source}${attrStr};`;
376
+ // `import type { ... }` — a type-only import declaration.
377
+ const typeKind = node.importKind === "type" ? "type " : "";
376
378
  const defaultSpec = specs.find(
377
379
  (_, i) => node.specifiers[i].type === "ImportDefaultSpecifier",
378
380
  );
@@ -382,7 +384,7 @@ export function print(node) {
382
384
  if (defaultSpec) parts.push(defaultSpec);
383
385
  if (nsSpec) parts.push(print(nsSpec));
384
386
  if (namedSpecs.length) parts.push(`{ ${namedSpecs.join(", ")} }`);
385
- return `import ${parts.join(", ")} from ${source}${attrStr};`;
387
+ return `import ${typeKind}${parts.join(", ")} from ${source}${attrStr};`;
386
388
  }
387
389
 
388
390
  case "ImportDefaultSpecifier":
@@ -391,7 +393,9 @@ export function print(node) {
391
393
  case "ImportSpecifier": {
392
394
  const imported = print(node.imported);
393
395
  const local = print(node.local);
394
- return imported === local ? imported : `${imported} as ${local}`;
396
+ const spec = imported === local ? imported : `${imported} as ${local}`;
397
+ // Inline `import { type Foo }` modifier.
398
+ return node.importKind === "type" ? `type ${spec}` : spec;
395
399
  }
396
400
 
397
401
  case "ImportNamespaceSpecifier":
@@ -408,19 +412,24 @@ export function print(node) {
408
412
  if (node.specifiers?.length) {
409
413
  const specs = node.specifiers.map(print).join(", ");
410
414
  const from = node.source ? ` from ${print(node.source)}` : "";
411
- return `export { ${specs} }${from};`;
415
+ // `export type { ... }` — a type-only export declaration.
416
+ const typeKind = node.exportKind === "type" ? "type " : "";
417
+ return `export ${typeKind}{ ${specs} }${from};`;
412
418
  }
413
419
  return "";
414
420
 
415
421
  case "ExportAllDeclaration": {
416
422
  const exported = node.exported ? ` as ${print(node.exported)}` : "";
417
- return `export *${exported} from ${print(node.source)};`;
423
+ const typeKind = node.exportKind === "type" ? "type " : "";
424
+ return `export ${typeKind}*${exported} from ${print(node.source)};`;
418
425
  }
419
426
 
420
427
  case "ExportSpecifier": {
421
428
  const local = print(node.local);
422
429
  const exported = print(node.exported);
423
- return local === exported ? local : `${local} as ${exported}`;
430
+ const spec = local === exported ? local : `${local} as ${exported}`;
431
+ // Inline `export { type Foo }` modifier.
432
+ return node.exportKind === "type" ? `type ${spec}` : spec;
424
433
  }
425
434
 
426
435
  // ── JSX (unsupported — Ember uses Glimmer templates) ─────────
@@ -831,8 +840,19 @@ export function print(node) {
831
840
 
832
841
  case "GlimmerAttrNode": {
833
842
  const name = node.name ?? "";
834
- const value = print(node.value);
835
- return `${name}=${value}`;
843
+ const value = node.value;
844
+ // A plain text value carries no quote style in the AST, so quote it
845
+ // (always valid) — printing it raw drops the quotes and corrupts any
846
+ // value with whitespace, e.g. `data-x="a b"` -> `data-x=a b`. An empty
847
+ // text value is a valueless attribute (`<input disabled>`).
848
+ if (value?.type === "GlimmerTextNode") {
849
+ const chars = value.chars ?? "";
850
+ if (chars === "") return name;
851
+ const quote = chars.includes('"') ? "'" : '"';
852
+ return `${name}=${quote}${chars}${quote}`;
853
+ }
854
+ // Mustache (`{{x}}`) and concat (`"a {{b}}"`) values print themselves.
855
+ return `${name}=${print(value)}`;
836
856
  }
837
857
 
838
858
  case "GlimmerConcatStatement": {