From a35258bdae7342f531528b55f6e39a767c1cca19 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 28 Mar 2023 12:28:10 +0200 Subject: [PATCH] fix(babel): partially handle functions as default export --- src/loader/babel.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/loader/babel.ts b/src/loader/babel.ts index 9aab2b7..c9fed99 100644 --- a/src/loader/babel.ts +++ b/src/loader/babel.ts @@ -101,7 +101,10 @@ const babelPluginUntyped: PluginItem = function ( } // Do not add meta to internal functions - if (p.parent.type !== "ExportNamedDeclaration") { + if ( + p.parent.type !== "ExportNamedDeclaration" && + p.parent.type !== "ExportDefaultDeclaration" + ) { return; } @@ -188,14 +191,18 @@ const babelPluginUntyped: PluginItem = function ( }); // Replace function with it's meta - p.replaceWith( - t.variableDeclaration("const", [ - t.variableDeclarator( - t.identifier(p.node.id.name), - astify({ $schema: schema }) - ), - ]) - ); + if (p.parent.type === "ExportDefaultDeclaration") { + p.replaceWith(astify({ $schema: schema })); + } else { + p.replaceWith( + t.variableDeclaration("const", [ + t.variableDeclarator( + t.identifier(p.node.id.name), + astify({ $schema: schema }) + ), + ]) + ); + } }, }, };