From bc87a950bb01eab7ba2e77e80914e7f4ba63f014 Mon Sep 17 00:00:00 2001 From: Brian Donovan <1938+eventualbuddha@users.noreply.github.com> Date: Sun, 3 Mar 2024 11:46:01 -0800 Subject: [PATCH 1/2] fix: print export namespace specifiers without braces Fixes #1390 --- lib/printer.ts | 10 ++++++++-- test/printer.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) 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/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( From 88a2baef95d9b63275a774a383d4493e20704ff0 Mon Sep 17 00:00:00 2001 From: Brian Donovan <1938+eventualbuddha@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:57:32 -0800 Subject: [PATCH 2/2] 0.23.6 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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",