Skip to content

[api-extractor] Fix handling of exported var declarations - #6155

Open
Yashvardhan Thanvi (Thanatos9404) wants to merge 1 commit into
microsoft:mainfrom
Thanatos9404:api-extractor-var-exports
Open

Yashvardhan Thanvi (Thanatos9404) wants to merge 1 commit into
microsoft:mainfrom
Thanatos9404:api-extractor-var-exports

Conversation

@Thanatos9404

Copy link
Copy Markdown

Summary

API Extractor mishandled exported var declarations. A default export backed by declare var _default kept the name _default in the .d.ts rollup instead of its exported name, and export declare var zero: number failed with "Unable to analyze the export".

Fixes #3353
Fixes #5507

Details

ExportAnalyzer.fetchReferencedAstEntity() returns early for any symbol with SymbolFlags.FunctionScopedVariable. That check is meant to stop typeof x on a function parameter from being followed, but TypeScript also sets the flag on var declarations. The check now skips only symbols whose value declaration is not a VariableDeclaration, so parameters still return early and var declarations take the normal path. As a side effect, a non-exported var referenced through typeof is now included in the rollup and reported as ae-forgotten-export, matching const.

How it was tested

Added an exportVar scenario that fails on main for both issues and passes with the fix; typeOf3 (the parameter case) and the other scenarios are unchanged, and the api-extractor tests pass.

fetchReferencedAstEntity() skipped every symbol with the
FunctionScopedVariable flag, so that "typeof x" on a function parameter
is not followed. TypeScript also sets that flag on "var" declarations,
so an exported var lost its name in the .d.ts rollup, or failed with
"Unable to analyze the export". Now only symbols that are not var
declarations are skipped.

Add an exportVar scenario that covers both cases.

This branch has not been deployed

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

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

[api-extractor] "ERROR: Internal Error: Unable to analyze the export" when using var [api-extractor] Lose name when export with declare var

1 participant