Skip to content

Commit a35258b

Browse files
committed
fix(babel): partially handle functions as default export
1 parent 55f1ffb commit a35258b

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/loader/babel.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ const babelPluginUntyped: PluginItem = function (
101101
}
102102

103103
// Do not add meta to internal functions
104-
if (p.parent.type !== "ExportNamedDeclaration") {
104+
if (
105+
p.parent.type !== "ExportNamedDeclaration" &&
106+
p.parent.type !== "ExportDefaultDeclaration"
107+
) {
105108
return;
106109
}
107110

@@ -188,14 +191,18 @@ const babelPluginUntyped: PluginItem = function (
188191
});
189192

190193
// Replace function with it's meta
191-
p.replaceWith(
192-
t.variableDeclaration("const", [
193-
t.variableDeclarator(
194-
t.identifier(p.node.id.name),
195-
astify({ $schema: schema })
196-
),
197-
])
198-
);
194+
if (p.parent.type === "ExportDefaultDeclaration") {
195+
p.replaceWith(astify({ $schema: schema }));
196+
} else {
197+
p.replaceWith(
198+
t.variableDeclaration("const", [
199+
t.variableDeclarator(
200+
t.identifier(p.node.id.name),
201+
astify({ $schema: schema })
202+
),
203+
])
204+
);
205+
}
199206
},
200207
},
201208
};

0 commit comments

Comments
 (0)