diff --git a/lib/printer.ts b/lib/printer.ts index 807e0765..5b3f9618 100644 --- a/lib/printer.ts +++ b/lib/printer.ts @@ -3005,13 +3005,19 @@ function printExportDeclaration(path: any, options: any, print: any) { parts.push("*"); } else if (decl.specifiers.length === 0) { parts.push("{}"); - } else if (decl.specifiers[0].type === "ExportDefaultSpecifier") { + } else if ( + decl.specifiers[0].type === "ExportDefaultSpecifier" || + decl.specifiers[0].type === "ExportNamespaceSpecifier" + ) { const unbracedSpecifiers: any[] = []; const bracedSpecifiers: any[] = []; path.each(function (specifierPath: any) { const spec = specifierPath.getValue(); - if (spec.type === "ExportDefaultSpecifier") { + if ( + spec.type === "ExportDefaultSpecifier" || + spec.type === "ExportNamespaceSpecifier" + ) { unbracedSpecifiers.push(print(specifierPath)); } else { bracedSpecifiers.push(print(specifierPath)); diff --git a/package-lock.json b/package-lock.json index 14459257..737e0693 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "recast", - "version": "0.23.5", + "version": "0.23.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "recast", - "version": "0.23.5", + "version": "0.23.6", "license": "MIT", "dependencies": { "ast-types": "^0.16.1", diff --git a/package.json b/package.json index 74fecb34..c9f07e21 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "Ben Newman ", "name": "recast", - "version": "0.23.5", + "version": "0.23.6", "description": "JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator", "keywords": [ "ast", diff --git a/test/printer.ts b/test/printer.ts index 0a5705c9..e25a961d 100644 --- a/test/printer.ts +++ b/test/printer.ts @@ -508,6 +508,56 @@ describe("printer", function () { assert.strictEqual(printer.printGenerically(ast).code, code); }); + it("export namespace", function () { + const printer = new Printer(); + + assert.strictEqual( + printer.print({ + type: "ExportNamedDeclaration", + exportKind: "value", + specifiers: [ + { + type: "ExportNamespaceSpecifier", + exported: { + type: "Identifier", + name: "Foobar", + }, + }, + ], + source: { + type: "StringLiteral", + value: "./foo", + }, + }).code, + `export * as Foobar from "./foo";`, + ); + }); + + it("export type namespace", function () { + const printer = new Printer(); + + assert.strictEqual( + printer.print({ + type: "ExportNamedDeclaration", + exportKind: "type", + specifiers: [ + { + type: "ExportNamespaceSpecifier", + exported: { + type: "Identifier", + name: "Foobar", + }, + }, + ], + source: { + type: "StringLiteral", + value: "./foo", + }, + }).code, + `export type * as Foobar from "./foo";`, + ); + }); + it("export default of IIFE", function () { const printer = new Printer(); let ast = b.exportDefaultDeclaration(