mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-17 17:39:44 +00:00
Add a test for the per name destructured export split
Four destructured names on one export statement must each get their
own node, and the old combined pattern syntax label must not survive
anywhere in the output.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh
(cherry picked from commit 3f62c3d85c)
This commit is contained in:
1 parent
fd9b1cdb40
commit
025caeaa93
1 file changed
+41
@@ -0,0 +1,41 @@
|
||||
"""#2604 Class 2: an exported object-destructure assignment must emit one node
|
||||
per exported name, not one combined node for the whole pattern.
|
||||
|
||||
`export const { auth, handlers } = NextAuth(config)` is NextAuth v5's own
|
||||
documented boilerplate (next-intl's `createNavigation()` is the same shape).
|
||||
Before this fix it collapsed to a single node whose id joined every
|
||||
destructured name (`stem_auth_handlers`) and whose label was the literal
|
||||
pattern syntax (`"{ auth, handlers }"`). A single-name import elsewhere
|
||||
(`import { auth } from './auth'`) looks for a node named `auth` alone, which
|
||||
never existed, so the import edge -- and any call resolved through it --
|
||||
dangled.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from graphify.extract import extract
|
||||
|
||||
_NEXTAUTH_HELPER = "function NextAuth(config) { return {}; }\n"
|
||||
|
||||
|
||||
def _extract(tmp_path, files: dict[str, str]):
|
||||
for name, body in files.items():
|
||||
p = tmp_path / name
|
||||
p.parent.mkdir(parents=True, exist_ok=True)
|
||||
p.write_text(body)
|
||||
r = extract([tmp_path / n for n in files],
|
||||
cache_root=tmp_path / "graphify-out", parallel=False)
|
||||
lbl = {n["id"]: n["label"] for n in r["nodes"]}
|
||||
return r, lbl
|
||||
|
||||
|
||||
def test_exported_destructure_emits_one_node_per_name(tmp_path):
|
||||
r, lbl = _extract(tmp_path, {
|
||||
"auth.ts": _NEXTAUTH_HELPER
|
||||
+ "export const { auth, handlers, signIn, signOut } = NextAuth({});\n",
|
||||
})
|
||||
labels = set(lbl.values())
|
||||
for name in ("auth", "handlers", "signIn", "signOut"):
|
||||
assert name in labels, f"no node for exported name {name!r}; got {sorted(labels)}"
|
||||
assert not any(label.startswith("{") for label in labels), (
|
||||
f"a combined-pattern label survived: {sorted(labels)}"
|
||||
)
|
||||
Reference in new issue
Block a user