Allow both module.exports= and module.exports property assignments - #23228
Merged
Nathan Shively-Sanders (sandersn) merged 5 commits intoApr 6, 2018
Merged
Nathan Shively-Sanders (sandersn) merged 5 commits into
Nathan Shively-Sanders (sandersn) merged 5 commits into
Conversation
Nathan Shively-Sanders (sandersn)
requested a review
from Mohamed Hegazy (mhegazy)
April 6, 2018 19:38
Mohamed Hegazy (mhegazy)
approved these changes
Apr 6, 2018
Nathan Shively-Sanders (sandersn)
deleted the
js/allow-module-exports-with-exports-assignments
branch
April 6, 2018 20:04
This was referenced Apr 6, 2018
Mohsen Azimi (mohsen1)
pushed a commit
to mohsen1/webpack
that referenced
this pull request
Apr 11, 2018
Tobias Koppers (sokra)
pushed a commit
to webpack/webpack
that referenced
this pull request
Apr 12, 2018
This was referenced Apr 19, 2018
Closed
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.exportsand to assign properties tomodule.exports:This should be treated as equivalent to the Typescript:
This PR merges
module.exportsassignments withmodule.exportsproperty 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
exportsof 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