deno
8bc313c5 - fix(cli): collect re-exported names for `deno test --doc` injection (#33511)

Commit
53 days ago
fix(cli): collect re-exported names for `deno test --doc` injection (#33511) ## Summary \`deno test --doc\` extracts each fenced \`\`\`ts\` block and injects an \`import { ... } from \"<base file>\"\` statement that pulls in every named export, so snippets can reference module-level bindings without spelling out the import. Re-exports of the form \`export { foo } from \"./other.ts\"\` were dropped because \`ExportCollector::visit_named_export\` returned early whenever the parent \`NamedExport\` had a \`src\`. Result: \`\`\`ts // foo.ts export const foo = () => {}; // main.ts /** * \`\`\`ts * foo(); * \`\`\` */ export { foo } from \"./foo.ts\"; \`\`\` \`\`\` $ deno test --doc main.ts … TS2304 [ERROR]: Cannot find name 'foo'. foo(); ~~~ \`\`\` (The user works around this with an explicit \`import { foo } from \"./foo.ts\"; export { foo };\`, which the collector does pick up.) Treat the names listed in a re-export's specifiers as exports of the current module. Skipped: - \`export *\` / \`export * as ns\` — would require following the re-export chain to enumerate the names. - \`export { default } from \"./other.ts\"\` — only changes default-export plumbing, not the named-export surface. - \`export { foo as default } from \"./other.ts\"\` — same. Fixes #30550. ## Test plan - [x] Manual repro from the issue now type-checks and runs the doc test. - [x] Updated \`ExportCollector\` snapshot test in \`cli/util/extract.rs\` for re-exports — the case that previously expected \`atom_set!()\` now expects \`atom_set!(\"name2\", \"N3\", \"myDefault\")\` (the explicit named re-exports), with \`export *\` and \`export { default }\` still ignored. - [x] \`cargo fmt --check\`, \`cargo clippy --bin deno -- -D warnings\`. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Author
Parents
Loading