Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SSG Named Export Transform #9649

Merged
merged 2 commits into from Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/next/build/babel/plugins/next-ssg-transform.ts
Expand Up @@ -27,15 +27,11 @@ export default function nextTransformSsg({
return
}

if (declaration.type === 'VariableDeclaration') {
if (declaration.type !== 'FunctionDeclaration') {
return
}

const name =
declaration.type === 'FunctionDeclaration'
? declaration.id && declaration.id.name
: null

const name = declaration.id && declaration.id.name
if (name == null) {
throw new Error(`invariant: null function declaration`)
}
Expand Down
20 changes: 20 additions & 0 deletions test/unit/babel-plugin-next-ssg-transform.test.js
Expand Up @@ -241,5 +241,25 @@ describe('babel plugin (next-ssg-transform)', () => {
`"const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__NEXT_SPR=true export default __NEXT_COMP;"`
)
})

it('should not crash for class declarations', () => {
const output = babel(trim`
function unstable_getStaticPaths() {
return []
}

export { unstable_getStaticPaths }

export class MyClass {}

export default function Test() {
return <div />
}
`)

expect(output).toMatchInlineSnapshot(
`"export class MyClass{}const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__NEXT_SPR=true export default __NEXT_COMP;"`
)
})
})
})