Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/extractors/javascript/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,14 @@ func (x *extractor) isFunctionWrapperCall(n ts.Node) bool {
// also take a function but are imperative side-effects,
// not values bound to a name — the `const cleanup =
// useEffect(...)` shape is not idiomatic.
"useCallback", "useMemo":
"useCallback", "useMemo",
// Next.js data cache (next/cache): `const getItems =
// unstable_cache(async (...) => {...}, [key], {revalidate})`
// returns the cached wrapper around its first argument, so the
// bound name is a function, the same shape as the hook wrappers
// above. Without this the declaration falls through every
// branch and no entity is emitted for the name at all.
"unstable_cache":
return true
}
// Issue #2859 — generic Higher-Order Component naming convention.
Expand Down
20 changes: 20 additions & 0 deletions internal/extractors/javascript/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,26 @@ func TestConstExportReactWrappers(t *testing.T) {
assertKind(t, entities, "Connected", "SCOPE.Operation")
}

const constExportNextUnstableCacheSrc = `
import { unstable_cache } from "next/cache";

export const getItems = unstable_cache(
async (ownerId) => fetchItems(ownerId),
["items"],
{ revalidate: 60 },
);
`

// unstable_cache returns the cached wrapper around its first argument, so the
// bound name is callable. Same shape as useCallback/useMemo.
func TestConstExportNextUnstableCache(t *testing.T) {
src := []byte(constExportNextUnstableCacheSrc)
tree := parseJS(t, src)
entities := extract(t, src, "javascript", tree)

assertKind(t, entities, "getItems", "SCOPE.Operation")
}

const constExportHookAliasSrc = `
import { useSelector, useDispatch } from "react-redux";

Expand Down
Loading