Fix CJS export of typedef and class w/latebound names #55053
Merged
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.
Fixes #53967
The problem is that the weird, ad-hoc CJS merge needs to happen at two different times. The first is its existing location in getCommonJsExportEquals. The second is getResolvedMembersOrExportsOfSymbol, which combines normal, early-bound symbols with late-bound symbols.
The CJS merge happens before the addition of late-bound symbols, so a merge will result in the loss of [Symbol.iterable] from the bug. But manually merging the resolvedExports/Members during the CJS merge also doesn't work, because it prevents the module's resolvedExports/Members from being filled in later.
Instead, this PR delays part of the CJS merge to
getResolvedMembersOrExportsOfSymbol. Unfortunately, this requires retrieving the original, unmerged symbols--since their resolvedExports/Members are already cached. I do this by looking at the symbols for each of the merged symbol's declarations, which feels wrong.
Please suggest alternate ways to do this. I don't think I understand the late-binding machinery well enough, so it's likely there's a cleaner way.