Skip to content

Commit

Permalink
feat(gatsby): Traverse re-exports in static query mapper (gatsbyjs#36943
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tyhopp authored Nov 2, 2022
1 parent 8b26fa0 commit 151f20c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
9 changes: 9 additions & 0 deletions integration-tests/artifacts/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,15 @@ describe(`First run (baseline)`, () => {
expect(staticQueryHashes.sort()).toEqual(queries.map(hashQuery).sort())
})

test(`are written correctly when a re-exported query is imported`, async () => {
const queries = [titleQuery, ...globalQueries]
const pagePath = `/import-re-export/`

const { staticQueryHashes } = await readPageData(publicDir, pagePath)

expect(staticQueryHashes.sort()).toEqual(queries.map(hashQuery).sort())
})

test(`are written correctly when dynamically imported`, async () => {
const queries = [titleQuery, ...globalQueries]
const pagePath = `/dynamic/`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react"
import { useTitle } from "../hooks/use-title"

export function Title() {
const title = useTitle()
return <div>{title}</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Title as TitleReExport } from "./title-named-export"
6 changes: 6 additions & 0 deletions integration-tests/artifacts/src/pages/import-re-export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react"
import { TitleReExport } from "../components/title-re-export"

export default function ImportReExport() {
return <TitleReExport />
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,7 @@ export class StaticQueryMapper {
compilation.moduleGraph.getIncomingConnections(module)
for (const connection of incomingConnections) {
if (connection.originModule instanceof NormalModule) {
const shouldTraverse =
connection.dependency?.type !==
`harmony export imported specifier`

if (shouldTraverse) {
traverseModule(connection.originModule, config, visitedModules)
}
traverseModule(connection.originModule, config, visitedModules)
}
}
}
Expand Down

0 comments on commit 151f20c

Please sign in to comment.