Skip to content

Commit

Permalink
Fix SSG Named Export Transform (#9649)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Dec 6, 2019
1 parent 10b2eb5 commit cb4c08c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
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;"`
)
})
})
})

0 comments on commit cb4c08c

Please sign in to comment.