Unverified Commit cb4c08c0 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Fix SSG Named Export Transform (#9649)

parent 10b2eb5b
...@@ -27,15 +27,11 @@ export default function nextTransformSsg({ ...@@ -27,15 +27,11 @@ export default function nextTransformSsg({
return return
} }
if (declaration.type === 'VariableDeclaration') { if (declaration.type !== 'FunctionDeclaration') {
return return
} }
const name = const name = declaration.id && declaration.id.name
declaration.type === 'FunctionDeclaration'
? declaration.id && declaration.id.name
: null
if (name == null) { if (name == null) {
throw new Error(`invariant: null function declaration`) throw new Error(`invariant: null function declaration`)
} }
......
...@@ -241,5 +241,25 @@ describe('babel plugin (next-ssg-transform)', () => { ...@@ -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;"` `"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;"`
)
})
}) })
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment