Skip to content

Commit

Permalink
Make sure to update scope for page export declaration (#9115)
Browse files Browse the repository at this point in the history
* Register page export declaration to scope

* Update to not need to traverse to update scope
  • Loading branch information
ijjk authored Oct 18, 2019
1 parent fd0ba93 commit 499808f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/next/build/babel/plugins/next-page-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function replaceBundle(path: any, t: typeof BabelTypes) {
interface ConfigState {
isPrerender?: boolean
bundleDropped?: boolean
defaultExportUpdated?: boolean
}

// config to parsing pageConfig for client bundles
Expand Down Expand Up @@ -116,7 +117,7 @@ export default function nextPageConfig({
},
},
ExportDefaultDeclaration(path, state: ConfigState) {
if (!state.isPrerender) {
if (!state.isPrerender || state.defaultExportUpdated) {
return
}
const prev = t.cloneDeep(path.node.declaration)
Expand All @@ -127,7 +128,8 @@ export default function nextPageConfig({
prev.type = prev.type.replace(/Declaration$/, 'Expression') as any
}

path.insertBefore([
// @ts-ignore invalid return type
const [pageCompPath] = path.replaceWithMultiple([
t.variableDeclaration('const', [
t.variableDeclarator(t.identifier(pageComponentVar), prev as any),
]),
Expand All @@ -139,9 +141,10 @@ export default function nextPageConfig({
),
t.booleanLiteral(true)
),
t.exportDefaultDeclaration(t.identifier(pageComponentVar)),
])

path.node.declaration = t.identifier(pageComponentVar)
path.scope.registerDeclaration(pageCompPath)
state.defaultExportUpdated = true
},
},
}
Expand Down

0 comments on commit 499808f

Please sign in to comment.