-
Notifications
You must be signed in to change notification settings - Fork 34
[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
base: main
Are you sure you want to change the base?
[interop] Add support for importing and exporting declarations, as well as multi-file output #418
Conversation
# 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
# 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
web_generator/test/integration/interop_gen/project/input/a.d.ts
Outdated
Show resolved
Hide resolved
web_generator/test/integration/interop_gen/import_export_input.d.ts
Outdated
Show resolved
Hide resolved
// export reference | ||
if (decl.isEmpty) _getTypeFromDeclaration(actualName, []); | ||
|
||
exportSet.removeWhere((e) => e.name == actualName.text); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 aProgramMap
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:path
sPathMap
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
ReferredType
s with aurl
property, which allows for referencing the normalExports 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: