Skip to content

[interop] Add support for importing and exporting declarations, as well as multi-file output #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

nikeokoronkwo
Copy link
Collaborator

@nikeokoronkwo nikeokoronkwo commented Jul 17, 2025

Fixes #378
Fixes #387

This PR is for adding support for multiple file processing, with support for exporting and importing declarations even between files.

It makes use of a TransformManager which transforms various files and uses a ProgramMap to memoize and keep track of dependencies across files, which helps in reducing expensive transform calls to declarations already referenced from other files.

The type checker helps to resolve types and imports, as well as resolve import declarations. Import declarations are not parsed by default so that we know we are only making use of imports actually referenced in code (which is helpful in single outputs for instance).

(The program map makes use of package:paths PathMap to easily work with paths for files and declarations, as the TS output may resolve either to a relative import in the file, or may reference the declaration externally as an absolute path).

Imported declarations are declared as ReferredTypes with a url property, which allows for referencing the normal

Exports are rewritten based on how they are specified, and are processed after transformation (since they are separate declarations and may be referenced as they are.

Imports are processed depending on the presence of the file:

  • If TS can find the file (i.e not global scope), then the declaration is referenced with the proper name as an import
  • If the file needed/imported is not included in the multi-file input params, then the declarations are generated in the output file as a single output.
  • If the declaration is in the global scope, then the generator can auto-generate these declarations as so.

TODOs

  • Implement support for import declarations
  • Implement support for multi-file projects/processing
  • Implement integration test as multi-file test

# Conflicts:
#	web_generator/lib/src/interop_gen/transform/transformer.dart
#	web_generator/lib/src/js/typescript.types.dart
- added import support
- added gen of code inside file in the case of non multi-import
- added support for multiple file generation
- using `TransformManager` for managing transformation of code
@nikeokoronkwo nikeokoronkwo changed the title WIP: [interop] Add support for importing and exporting declarations, as well as multi-file output [interop] Add support for importing and exporting declarations, as well as multi-file output Jul 20, 2025
@nikeokoronkwo nikeokoronkwo marked this pull request as ready for review July 20, 2025 00:40
# Conflicts:
#	web_generator/lib/src/ast/declarations.dart
#	web_generator/lib/src/interop_gen/transform.dart
#	web_generator/lib/src/interop_gen/transform/transformer.dart
#	web_generator/lib/src/js/typescript.types.dart
@kevmoo kevmoo requested a review from srujzs July 21, 2025 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interop Gen: Support Import Declarations and Multi-File Output Interop Gen: Support Export/Import Declarations
2 participants