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 21 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.
Rather than transforming every declaration in a source file, the type checker gets the declarations exported from the file, and processes those declarations and its dependencies only, making processing faster

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.

# 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
@nikeokoronkwo nikeokoronkwo requested a review from srujzs July 23, 2025 21:57
// export reference
if (decl.isEmpty) _getTypeFromDeclaration(actualName, []);

exportSet.removeWhere((e) => e.name == actualName.text);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is needed because the new export shadows the old export.

A question: Can export specifiers and export declarations interleave? Can there be multiple of each? Do we follow the ordering correctly if so?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Export specifiers are contained in export declarations. There can be multiple export declarations. The order shouldn't matter, as you cannot export a symbol twice.

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