Allow both module.exports= and module.exports property assignments #23228
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.
In Javascript, it's common both to assign to
module.exports
and to assign properties tomodule.exports
:This should be treated as equivalent to the Typescript:
This PR merges
module.exports
assignments withmodule.exports
property assignments to produce a symbol structure similar to the Typescript binding. Unfortunately, since we're merging values, the normal merging code will not work. After binding the first example, the file's exports have the following structure:Then when the checker encounters
var x = require(...)
, it looks up the file's exports and retrieves the "export=" entry.This PR copies the other entries of exports over to export='s exports:
This makes the
export=
symbol equivalent to the merged typescript in the second example.Then when the checker asks for the type of this symbol, it can get the property assignments by looking at the
exports
of the symbol.Since the same property can be assigned in both
export=
and property assignments, some unioning code is also required:In addition, if the
module.exports = 1
(or any primitive type), then subsequent assignments will be ignored, so none of the property assignments should show up as exports either.Fixes #22461