Skip to content

Commit

Permalink
fix(babel): partially handle functions as default export
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 28, 2023
1 parent 55f1ffb commit a35258b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/loader/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 })
),
])
);
}
},
},
};
Expand Down

0 comments on commit a35258b

Please sign in to comment.