Support importing types across Turbo Module specs#56045
Open
christophpurrer wants to merge 1 commit intofacebook:mainfrom
Open
Support importing types across Turbo Module specs#56045christophpurrer wants to merge 1 commit intofacebook:mainfrom
christophpurrer wants to merge 1 commit intofacebook:mainfrom
Conversation
Summary: ## Changelog: [General] [Added] - Add cross-file type import support for React Native Turbo Module codegen Turbo Module JavaScript specs previously required all types (enums, type aliases) to be defined in the same file. This forced developers to duplicate type definitions when sharing them across multiple modules. This diff adds an optional `importedTypes` parameter to `parseString()` that allows the parser to resolve types defined in external files. The approach: - `parseString()` accepts an optional `TypeDeclarationMap` of imported types, which are merged with local types (local definitions take precedence). - `parseFile()` automatically resolves relative `import type` declarations by parsing the source files and extracting their type AST nodes. - A shared `resolveImportedTypes()` utility handles filesystem resolution for both Flow and TypeScript parsers. - `getImportsFromAST()` extracts type-only import declarations from the AST, filtering out value imports to avoid unnecessary filesystem I/O. - The flow-schema OTA safety tool is updated to build imported types from its existing import map infrastructure and pass them to the codegen parser. Code generators require zero changes since they consume the flat schema (enumMap/aliasMap), and imported types produce identical schema entries to file-local types. Differential Revision: D95646987
|
@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D95646987. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
Changelog:
[General] [Added] - Add cross-file type import support for React Native Turbo Module codegen
Turbo Module JavaScript specs previously required all types (enums, type aliases)
to be defined in the same file. This forced developers to duplicate type
definitions when sharing them across multiple modules.
This diff adds an optional
importedTypesparameter toparseString()thatallows the parser to resolve types defined in external files. The approach:
parseString()accepts an optionalTypeDeclarationMapof imported types,which are merged with local types (local definitions take precedence).
parseFile()automatically resolves relativeimport typedeclarations byparsing the source files and extracting their type AST nodes.
resolveImportedTypes()utility handles filesystem resolution forboth Flow and TypeScript parsers.
getImportsFromAST()extracts type-only import declarations from the AST,filtering out value imports to avoid unnecessary filesystem I/O.
existing import map infrastructure and pass them to the codegen parser.
Code generators require zero changes since they consume the flat schema
(enumMap/aliasMap), and imported types produce identical schema entries to
file-local types.
Differential Revision: D95646987