Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a new AST annotation to keep track of any typedef types defined by a definition site. This is different from the type of the value, in that e.g. ``` /** @typedef {string} */ ns.MyString; ``` calling `getJSType()` on the `ns.MyString` qualified name node returns the undefined type, since `ns.MyString` has a runtime value of undefined, but the type *name* represents a string, which we store in `Node#getTypedefTypeProp`. This is necessary so that typedefs can be discovered on aliased namespaces: if `const alias = ns;` then `alias.MyString` will not be in the type registry, but we still need to be able to find it. This is now possible by actually adding the `MyString` property to the namespace type (it was omitted before, defined only in the registry), and then checking the definition node for the new annotation. This annotation is also transferred when a typedef is aliased directly. This approach is sub-optimal, since it does not consolidate the handling of other kinds of type names, whose types are easily derived from their value types (specifically, constructors and enum objects). It would be nice if typedef objects could also store their typename types, but since most enums are undefined or objects, this would require additional proxying and leads to a mess figuring out where to add the new declarations and not conflict with the subset of typedefs that were already previously being declared. On the other hand, this approach could be consolidated to also include class and enum names, which we may pursue in the future. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=219725240
- Loading branch information
Showing
5 changed files
with
302 additions
and
63 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
Oops, something went wrong.