Skip to content

Commit

Permalink
Merge branch 'canary' into justman00/fix-preview-false
Browse files Browse the repository at this point in the history
  • Loading branch information
justman00 authored Sep 4, 2020
2 parents 97c7832 + d97237a commit 6918288
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
41 changes: 34 additions & 7 deletions packages/next/build/babel/plugins/next-page-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,47 @@ export default function nextPageConfig({
exportPath.scope.getBinding(CONFIG_KEY)?.path.node,
].filter(Boolean)

for (const declaration of declarations) {
if (
!BabelTypes.isIdentifier(declaration.id, {
name: CONFIG_KEY,
})
) {
if (BabelTypes.isImportSpecifier(declaration)) {
for (const specifier of exportPath.node.specifiers) {
if (specifier.exported.name === CONFIG_KEY) {
// export {} from 'somewhere'
if (BabelTypes.isStringLiteral(exportPath.node.source)) {
throw new Error(
errorMessage(
exportState,
`Expected object but got import`
)
)
// import hello from 'world'
// export { hello as config }
} else if (
BabelTypes.isIdentifier(
(specifier as BabelTypes.ExportSpecifier).local
)
) {
if (
BabelTypes.isImportSpecifier(
exportPath.scope.getBinding(
(specifier as BabelTypes.ExportSpecifier).local.name
)?.path.node
)
) {
throw new Error(
errorMessage(
exportState,
`Expected object but got import`
)
)
}
}
}
}

for (const declaration of declarations) {
if (
!BabelTypes.isIdentifier(declaration.id, {
name: CONFIG_KEY,
})
) {
continue
}

Expand Down
10 changes: 10 additions & 0 deletions test/integration/page-config/pages/valid/config-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// eslint-disable-next-line no-unused-vars
import { config } from '../../config'

export const getServerSideProps = () => {
return {
props: {},
}
}

export default () => <p>hello world</p>
10 changes: 10 additions & 0 deletions test/integration/page-config/pages/valid/not-config-export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// eslint-disable-next-line no-unused-vars
export { config as notConfig } from '../../config'

export const getServerSideProps = () => {
return {
props: {},
}
}

export default () => <p>hello world</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// eslint-disable-next-line no-unused-vars
import { config } from '../../config'

export { config as notConfig }

export const getServerSideProps = () => {
return {
props: {},
}
}

export default () => <p>hello world</p>

0 comments on commit 6918288

Please sign in to comment.