-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix cross-file merge of assignment decl valueDeclaration #26918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Previously mergeSymbol in the checker always updated valueDeclaration if target.valueDeclaration was an assignment declaration. The binder only updates target.valueDeclaration if it is an assignment declaration and source.valueDeclaration is *not* an assignment declaration. Now the checker behaves the same way as the binder.
Baseline diff in jsContainerMergeJsContainer on CI |
Makes commonjs merge with globals when appropriate.
src/compiler/checker.ts
Outdated
/** CommonJS is *almost* a module -- no merges -- except that assignment declarations need to merge with globals. */ | ||
function mergeCommonJsSymbolTable(target: SymbolTable, source: SymbolTable) { | ||
source.forEach((sourceSymbol, id) => { | ||
if (target.has(id) && sourceSymbol.flags & SymbolFlags.Assignment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talking with @weswigham, he pointed out that it would be better to store all the identifier-unbound declarations in a separate per-file commonJSGlobalAugmentations property that gets merged into globals instead of trying to filter here (there are plenty of symbols marked with Assignment that shouldn't necessarily merge with globals).
Instead of trying to filter these augmentations out of the normal symbol table of commonjs modules.
All right, the new table is in. I dropped the "common" part since all JS files create global augmentations, and they all need to be merged, regardless of whether they are in a commonJS module. |
Previously mergeSymbol in the checker always updated valueDeclaration if target.valueDeclaration was an assignment declaration. The binder only updates target.valueDeclaration if it is an assignment declaration and source.valueDeclaration is not an assignment declaration.
Now the checker behaves the same way as the binder.
Fixes #26877