-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flow] Declaration merging for declare namespaces in libdefs
Summary: In this diff, we implement basic declaration merging for `declare namespace` in libdefs. I specifically chose to limit to libdef for now due to its relative self-contained-ness: with some addition work to propagate some additional kinds of signature errors in type sig, we can do the enforcement completely within type sig. Within type sig, we have a specialized implementation of namespace binding. When binding the namespace, it will see whether there is already a namespace in the global libdef scope. If so, we will try to merge it (there are a lot of case analysis, including the most complicated one of promoting a type-only namespace to a value namespace due to merging, which I explained in the comments and checked in tests). When we are merging together two namespaces, we will error on duplicate names, e.g. ``` declare namespace ns { declare const foo: string; } declare namespace ns { declare const foo: string; // error } ``` This error will be added through a new signature error called validation error, which is not a result of unsupported expressions being any, but a result of simple syntactic validation. We can do the validation while we are merging, so it's very convenient. Note that we currently don't error on overridden libdefs, even those within the same file, but we can use similar mechanism to achieve that. (We do need additional tracking, since erroring on the shadowed one will be too impractical right now, as it can cause the shadowed builtin to error, which we can't suppress) A similar approach can be taken to support declaration merging for `declare module` as well (although with even more annoying case analysis for different kinds of modules (cjs/esm)). However, this diff won't do it, and it will be left as an exercise for an interested reader. Changelog: [feature] Declaration merging for `declare namespace` is now supported in toplevel library definitions. Reviewed By: panagosg7 Differential Revision: D70303553 fbshipit-source-id: b0c7b74813b0913cb273931deec3f591611d64d7
- Loading branch information
1 parent
7944ce6
commit 632778a
Showing
21 changed files
with
468 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.