From 82b944e5c30f98e2b26e783701fdac40c62cebeb Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 20 Sep 2021 14:36:38 +0200 Subject: [PATCH] Fix #96 --- src/index.ts | 11 ++--------- .../already wrapped gSSP and component/code.js | 10 ++++++++++ .../already wrapped gSSP and component/output.js | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 test/pages/already wrapped gSSP and component/code.js create mode 100644 test/pages/already wrapped gSSP and component/output.js 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