Skip to content

Fix extractDocs for re-exported (aliased) symbols - #55

Merged
josevalim merged 4 commits into
tidewave-ai:mainfrom
emzo:fix-aliased-symbol-docs
Mar 18, 2026
Merged

Fix extractDocs for re-exported (aliased) symbols#55
josevalim merged 4 commits into
tidewave-ai:mainfrom
emzo:fix-aliased-symbol-docs

Conversation

@emzo

@emzo emzo commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • extractDocs fails for symbols that are re-exported through barrel files (e.g. @reduxjs/toolkit:createSlice, @mui/material:Button), even though getSourceLocation works fine for the same references.
  • The root cause is that re-exported symbols have SymbolFlags.Alias and no direct valueDeclaration. The existing declaration-type checks in extractDocs don't account for this, causing the symbol to fall through to findSymbolInJavaScriptFile which fails on .d.ts files.
  • Fix: resolve aliases via checker.getAliasedSymbol() before checking the declaration type. This recovers the original declaration and its full documentation.

This affects most of the npm ecosystem — any package using barrel re-exports (export { X } from './X').

Test plan

  • Added test fixtures (reexport-source.ts + reexport-barrel.ts) with a barrel file that re-exports functions, classes, enums, and interfaces
  • 6 new tests covering all re-exported symbol types and the error path
  • Verified the 5 positive tests fail without the fix and pass with it
  • Full test suite passes (134 tests)

emzo added 2 commits March 17, 2026 17:23
Packages like @reduxjs/toolkit and @mui/material use barrel exports
(e.g. `export { createSlice } from './createSlice'`). These symbols
have SymbolFlags.Alias and no direct valueDeclaration, causing
extractDocs to fall through to findSymbolInJavaScriptFile which fails
on .d.ts files.

Fix: resolve aliases via checker.getAliasedSymbol() before checking
the declaration type. This recovers the original FunctionDeclaration/
ClassDeclaration and its full documentation.
Tests extractDocs against a barrel file that re-exports functions,
classes, enums, and interfaces. Verifies that documentation, kind,
and member access all work through the alias chain.
@josevalim

Copy link
Copy Markdown
Contributor

@emzo thank you! Can you please run the linter/formatter?

@emzo

emzo commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Of course. Apologies, I forgot that step!

@emzo

emzo commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

That's now done @josevalim

Split Result (interface) into a separate `export type` to satisfy
tsc --noEmit with verbatimModuleSyntax enabled.
@josevalim
josevalim merged commit 8a276c1 into tidewave-ai:main Mar 18, 2026
2 checks passed
@josevalim

Copy link
Copy Markdown
Contributor

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants