diff --git a/src/index.ts b/src/index.ts index 70c1912..0517d42 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,6 @@ import { isClassDeclaration, isExportDefaultDeclaration, isFunctionDeclaration, - isFunctionExpression, isIdentifier, isVariableDeclaration, stringLiteral, @@ -119,14 +118,6 @@ function wrapExportDefaultDeclaration(path: NodePath) { const { node } = path; - if (isIdentifier(node.declaration)) { - node.declaration = wrapInHOC(node.declaration); - } - - if (isFunctionExpression(node.declaration)) { - node.declaration = wrapInHOC(node.declaration); - } - if ( isFunctionDeclaration(node.declaration) || isClassDeclaration(node.declaration) @@ -145,6 +136,8 @@ function wrapExportDefaultDeclaration(path: NodePath) { ); } } + } else { + node.declaration = wrapInHOC(node.declaration); } } diff --git a/test/pages/already wrapped gSSP and component/code.js b/test/pages/already wrapped gSSP and component/code.js new file mode 100644 index 0000000..85f5508 --- /dev/null +++ b/test/pages/already wrapped gSSP and component/code.js @@ -0,0 +1,10 @@ +export const getServerSideProps = withAuthUserTokenSSR({ + whenUnauthed: AuthAction.REDIRECT_TO_LOGIN, +})(async ({ AuthUser }) => { + // ... + return { + props, + }; +}); + +export default withAuthUser()(Component); \ No newline at end of file diff --git a/test/pages/already wrapped gSSP and component/output.js b/test/pages/already wrapped gSSP and component/output.js new file mode 100644 index 0000000..2d973b4 --- /dev/null +++ b/test/pages/already wrapped gSSP and component/output.js @@ -0,0 +1,14 @@ +import { withSuperJSONPage as _withSuperJSONPage } from 'babel-plugin-superjson-next/tools'; +import { withSuperJSONProps as _withSuperJSONProps } from 'babel-plugin-superjson-next/tools'; +export const getServerSideProps = _withSuperJSONProps( + withAuthUserTokenSSR({ + whenUnauthed: AuthAction.REDIRECT_TO_LOGIN, + })(async ({ AuthUser }) => { + // ... + return { + props, + }; + }), + ['smth'] +); +export default _withSuperJSONPage(withAuthUser()(Component)); \ No newline at end of file