fix(cli): collect re-exported names for deno test --doc injection#33511
Merged
Conversation
The doc-test extractor injects an `import { ... }` statement bringing
in every named export of the base file 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 the
collector returned early whenever a `NamedExport` had a source —
meaning a snippet that called `foo()` failed type-checking with
`TS2304: Cannot find name 'foo'`.
Treat the names listed in a re-export's specifiers as exports of the
current module, with `default`-as-`default` and namespace re-exports
(`export *`, `export * as ns`) still excluded since we'd have to
follow the chain to know their actual exported names.
Fixes denoland#30550.
lunadogbot
approved these changes
Apr 26, 2026
lunadogbot
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Walked through every specifier case in the snapshot test against the new logic:
export */export * as name1→ExportSpecifier::Namespace, theif let ::Named(...)skips them. Correct (these would need chasing the re-export chain).export { name2 }→orig=name2, exported=None→name="name2"→ inserted. ✓export { name3 as N3 }→orig=name3, exported=Some(N3)→name="N3"→ inserted. ✓export { default }→orig=default, exported=None→name="default"→ skipped via thedefaultearly-continue. ✓export { default as myDefault }→orig=default, exported=Some(myDefault)→name="myDefault"→ inserted. ✓export { foo as default }(PR body's note) →orig=foo, exported=Some(default)→name="default"→ skipped. ✓
Also verified the downstream consumer (to_import_specifiers, line 296+) just emits each atom as an ImportNamedSpecifier, and at runtime the re-exported name does live as a real named export of the doc-test base file, so the injected import { name2 } from "./base.ts" will resolve.
3 tasks
crowlKats
approved these changes
Jun 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
`deno test --doc` extracts each fenced ```ts` block and injects an `import { ... } from ""` 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
/**
*/
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:
Fixes #30550.
Test plan