Repository navigation
[api-extractor] Fix handling of exported var declarations - #6155
Open
Yashvardhan Thanvi (Thanatos9404) wants to merge 1 commit into
Open
Yashvardhan Thanvi (Thanatos9404) wants to merge 1 commit into
Yashvardhan Thanvi (Thanatos9404) wants to merge 1 commit into
Conversation
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
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
API Extractor mishandled exported
vardeclarations. A default export backed bydeclare var _defaultkept the name_defaultin the .d.ts rollup instead of its exported name, andexport declare var zero: numberfailed with "Unable to analyze the export".Fixes #3353
Fixes #5507
Details
ExportAnalyzer.fetchReferencedAstEntity()returns early for any symbol withSymbolFlags.FunctionScopedVariable. That check is meant to stoptypeof xon a function parameter from being followed, but TypeScript also sets the flag onvardeclarations. The check now skips only symbols whose value declaration is not aVariableDeclaration, so parameters still return early andvardeclarations take the normal path. As a side effect, a non-exportedvarreferenced throughtypeofis now included in the rollup and reported asae-forgotten-export, matchingconst.How it was tested
Added an
exportVarscenario that fails onmainfor both issues and passes with the fix;typeOf3(the parameter case) and the other scenarios are unchanged, and the api-extractor tests pass.