@loadable/babel-plugin
Version:
Babel plugin for loadable (required for SSR).
14 lines (11 loc) • 376 B
JavaScript
export default function requireAsyncProperty({ types: t }) {
function getFunc(funcPath) {
if (funcPath.isObjectMethod()) {
const { params, body, async } = funcPath.node
return t.arrowFunctionExpression(params, body, async)
}
return funcPath.node
}
return ({ funcPath }) =>
t.objectProperty(t.identifier('importAsync'), getFunc(funcPath))
}