benjamn / recast

JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator
MIT License
4.91k stars 347 forks source link

Curly braces added to namespace export (`export *`) #1390

Closed egasimus closed 4 months ago

egasimus commented 5 months ago

export [type] * as Foobar from "./foo" parses to the following (simplified). Trying to print it back into code adds an extra pair of curly braces.

import recast from 'recast'
for (const exportKind of ["value", "type"]) {
  console.log(recast.print({
    type: 'ExportNamedDeclaration',
    exportKind,
    specifiers: [
      {
        type: 'ExportNamespaceSpecifier',
        exported: {
          type: 'Identifier',
          name: 'Foobar'
        }
      }
    ],
    source: {
      type: 'StringLiteral',
      value: './foo',
    }
  }).code)
}

Expected:

export * as Foobar from "./foo";
export type * as Foobar from "./foo";

Actual:

export { * as Foobar } from "./foo";
export type { * as Foobar } from "./foo";

Context:

I'm trying to modify some .d.mts files, and TS balks at the extra curly braces.

eventualbuddha commented 4 months ago

Fixed in v0.23.6.