Skip to content

feat(js_interop_gen): support TS Compiler API and resolve all type-system errors - #560

Open
kevmoo wants to merge 2 commits into
more_dtsfrom
ts_compiler_migration
Open

feat(js_interop_gen): support TS Compiler API and resolve all type-system errors#560
kevmoo wants to merge 2 commits into
more_dtsfrom
ts_compiler_migration

Conversation

@kevmoo

@kevmoo kevmoo commented Jun 13, 2026

Copy link
Copy Markdown
Member

This PR is Phase 2 of our JS Interop generator migration, and is perfectly stacked on top of the Node.js migration PR (more_dts).

It migrates the massive, complex TypeScript Compiler API to the dogfooded generator, producing a ~10,000-line typescript_api.dart file that compiles and analyzes with perfect 100% cleanliness—zero errors, zero warnings, and zero infos!

🛠️ Summary of Breakthroughs & Fixes

  1. Typedef Recursion in Type Maps: Added recursive type alias resolution in createTypeMap to correctly discover underlying custom interface bounds.
  2. Generic Parameter Preservation: Re-architected deduceType to check the typeMap first, ensuring type parameters like <JSAny> are never lost during LCA resolution.
  3. Representation-Aware Empty Implements Fallbacks: Empty implements clauses dynamically fall back to JSObject or JSAny based on whether the representation type is a subtype of JSObject.
  4. Nullable Implements Guard: Prevented nullable types from appearing in implements clauses (which is syntactically prohibited in Dart).
  5. Enums as Proper JS Interop Types: Forced all enums to wrap JSNumber/JSString and explicitly implement them to resolve bounds mismatches.
  6. Backtick-Aware Doc Comment Tag Wrapping: Implemented an elegant, backtick-aware formatter in formatDocs that automatically wraps HTML-like tags (such as <reference ...> or <T>) in backticks, styling them as inline code and completely satisfying the analyzer without over-escaping tags already inside code blocks.
  7. Revived and Extended Unit Tests:
    • Fixed a pre-existing crash in the ClosureType constructor.
    • Added 3 new comprehensive unit tests in type_map_test.dart with 100% green coverage.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the js_interop_gen tool by improving member conflict resolution, type hierarchy resolution, and generic type parameter validation during code generation. It also adds escaping for unintended HTML tags in doc comments to prevent Dart analyzer warnings. The review feedback highlights several critical and high-severity issues, including incorrect string interpolation of TypeReference objects inside Code(...) blocks, potential cache collisions in _memberHierarchyCache from using non-unique names, and unsafe in-place mutation of shared AST type instances. Additionally, the reviewer recommends respecting member renaming when resolving conflicts and removing leftover debug print statements.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread js_interop_gen/lib/src/ast/declarations.dart Outdated
Comment thread js_interop_gen/lib/src/ast/types.dart Outdated
Comment thread js_interop_gen/lib/src/ast/helpers.dart Outdated
Comment thread js_interop_gen/lib/src/interop_gen/sub_type.dart Outdated
Comment thread js_interop_gen/lib/src/interop_gen/sub_type.dart Outdated
Comment thread js_interop_gen/lib/src/ast/declarations.dart
@kevmoo
kevmoo force-pushed the ts_compiler_migration branch from 026f0ef to ca900d4 Compare June 15, 2026 17:24

static const AnonymousUnion_7177595 polygon = AnonymousUnion_7177595._(
'polygon',
static final AnonymousUnion_7177595 polygon = AnonymousUnion_7177595._(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't LIKE this change. I need to dig in to understand what changed

@kevmoo

kevmoo commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the JS interop generator to improve type hierarchy resolution, support merged declarations, and update enum representation types to use JS types instead of primitive Dart types. It also adds HTML tag escaping in documentation formatting to prevent analyzer warnings. The review feedback suggests avoiding in-place mutation of shared AST type instances in sub_type.dart, expanding the allowed HTML tags list in formatting.dart, and implementing cycle guards in getMemberHierarchy and findMemberInHierarchy to prevent infinite recursion on circular type hierarchies.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread js_interop_gen/lib/src/interop_gen/sub_type.dart
Comment thread js_interop_gen/lib/src/formatting.dart
Comment thread js_interop_gen/lib/src/ast/helpers.dart
Comment thread js_interop_gen/lib/src/ast/helpers.dart Outdated
…stem errors

Migrate js_interop_gen parser infrastructure to use the TypeScript Compiler API bindings.

- Add generated TypeScript API bindings in lib/src/js/generated/typescript_api.dart and binding update script.
- Refactor AST nodes, type representation, and parser logic to interface with the TypeScript Compiler API.
- Fix sub-type hierarchy, type mapping, and union casting resolution.
- Restore SDK-internal formatting for golden test expected files and update generator goldens.
@kevmoo
kevmoo force-pushed the ts_compiler_migration branch from 3715854 to 5434de9 Compare July 1, 2026 00:56
- Use cloneType in getLowestCommonAncestorOfTypes to prevent in-place nullability mutation.
- Add img, hr, details, summary to allowed HTML tags in doc comment formatting.
- Add visited set cycle guards to getMemberHierarchy and findMemberInHierarchy.
- Add unit tests in generate_docs_test and type_map_test.
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.

1 participant