Skip to content

Commit

Permalink
fix: print export namespace specifiers without braces
Browse files Browse the repository at this point in the history
Fixes #1390
  • Loading branch information
eventualbuddha committed Mar 3, 2024
1 parent 2a9a88b commit bc87a95
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
50 changes: 50 additions & 0 deletions test/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit bc87a95

Please sign in to comment.