Skip to content

Conversation

nikeokoronkwo
Copy link
Collaborator

@nikeokoronkwo nikeokoronkwo commented Aug 3, 2025

Fixes #399
Fixes #416
Fixes #437
Fixes #420

This issue adds support for namespaces, including generating code for namespaces, and performing lookup on namespaces/modules using qualified names, to map such names to actual TS declarations. Only exported declarations from the namespace are generated for, reducing the number of unnecessary declarations generated for.

The TS compiler recognizes it as a named module, allowing for an easy transition to module-based code generation (see #424).

The generated code is an extension type with static members to represent the namespace items.

  • Variables and Functions are mapped to static properties and methods, respectively.
  • Classes and Interfaces are generated prefixed by the namespace name (i.e Foo.Bar becomes FooBar), and for classes, a static method is provided to redirect to the constructor of the class, matching the same structure as the constructor function.
  • Namespaces are also generated prefixed by the namespace name, and a static getter is provided to access the namespace code as so.

Also:

  • This also supports nested namespaces, as seen in the example code.
  • This also supports cross-referencing by preloading the declarations into the nodemap, and updating them once a member has been implemented.
  • Import typealiases import Name = Namespace.Interface are resolved inline when inside of a namespace. External import typealiases, or exported ones are converted to type aliases. This does not work for import = require yet.
  • Namespace Imports are supported, although as of now, the types are deducted and referenced rather than handling the namespace import.

Tasks

  • Support Namespaces
  • Support Qualified Names
  • Support Namespace vs Global Type Resolution
  • Support Import Typealias
  • Support Namespaced Imports

@nikeokoronkwo nikeokoronkwo marked this pull request as ready for review August 5, 2025 20:24
@nikeokoronkwo nikeokoronkwo requested a review from srujzs August 5, 2025 20:24
@nikeokoronkwo
Copy link
Collaborator Author

@srujzs Just a final check: good to go?

@nikeokoronkwo nikeokoronkwo merged commit f51cc85 into dart-lang:main Aug 6, 2025
8 checks passed
@nikeokoronkwo nikeokoronkwo deleted the interop/namespaces branch August 6, 2025 04:13
Copy link
Contributor

@srujzs srujzs left a comment

Choose a reason for hiding this comment

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

Yes, LGTM! Thanks for the changes!

copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Aug 7, 2025
Revisions updated by `dart tools/rev_sdk_deps.dart`.

dartdoc (https://github.com/dart-lang/dartdoc/compare/414953e..82b48b5):
  82b48b53  2025-08-05  István Soós  Update highlight.js download instructions and resources. (dart-lang/dartdoc#4081)

ecosystem (https://github.com/dart-lang/ecosystem/compare/2fe3618..4543c38):
  4543c38  2025-08-06  Devon Carew  address a `Bad state: No element` element exception (dart-lang/ecosystem#321)
  e14472f  2025-08-06  Devon Carew  add a roadmap to our various mono-repos (dart-lang/ecosystem#318)
  e83479a  2025-08-06  Moritz  Fixes to health (dart-lang/ecosystem#363)
  552f534  2025-08-06  Moritz  Update API tool hash (dart-lang/ecosystem#362)

i18n (https://github.com/dart-lang/i18n/compare/c45e050..25cdb1b):
  25cdb1b4  2025-08-07  Moritz  Reenable mac size checks (dart-lang/i18n#1001)

shelf (https://github.com/dart-lang/shelf/compare/082d3ac..2a46b4f):
  2a46b4f  2025-08-05  Kevin Moore  Update dependencies across 3 packages (dart-lang/shelf#479)

test (https://github.com/dart-lang/test/compare/5aef971..9354f23):
  9354f239  2025-08-07  Liam Appelbe  Add `--coverage-path` and `--branch-coverage` options (dart-lang/test#2517)

tools (https://github.com/dart-lang/tools/compare/5e977d6..1b52e89):
  1b52e89e  2025-08-06  Moritz  Configure Gemini code review (dart-lang/tools#2141)

web (https://github.com/dart-lang/web/compare/1d5771b..f3c960f):
  f3c960f  2025-08-06  Nikechukwu  [web_generator] Add support for passing files as globs (dart-lang/web#427)
  f51cc85  2025-08-06  Nikechukwu  [interop] Add Support for Namespaces (dart-lang/web#436)

webdev (https://github.com/dart-lang/webdev/compare/7ff2d07..94c172c):
  94c172cc  2025-08-05  Nicholas Shahan  Wait for any remaining output in e2e_test.dart (dart-lang/webdev#2663)

Change-Id: Ie18635903f7379bc27e7ae23b916e10e4bdcef94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444360
Auto-Submit: Devon Carew <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Aug 7, 2025
… webdev"

This reverts commit 00240e8.

Reason for revert: failures on HHH

Original change's description:
> [deps] rev dartdoc, ecosystem, i18n, shelf, test, tools, web, webdev
>
> Revisions updated by `dart tools/rev_sdk_deps.dart`.
>
> dartdoc (https://github.com/dart-lang/dartdoc/compare/414953e..82b48b5):
>   82b48b53  2025-08-05  István Soós  Update highlight.js download instructions and resources. (dart-lang/dartdoc#4081)
>
> ecosystem (https://github.com/dart-lang/ecosystem/compare/2fe3618..4543c38):
>   4543c38  2025-08-06  Devon Carew  address a `Bad state: No element` element exception (dart-lang/ecosystem#321)
>   e14472f  2025-08-06  Devon Carew  add a roadmap to our various mono-repos (dart-lang/ecosystem#318)
>   e83479a  2025-08-06  Moritz  Fixes to health (dart-lang/ecosystem#363)
>   552f534  2025-08-06  Moritz  Update API tool hash (dart-lang/ecosystem#362)
>
> i18n (https://github.com/dart-lang/i18n/compare/c45e050..25cdb1b):
>   25cdb1b4  2025-08-07  Moritz  Reenable mac size checks (dart-lang/i18n#1001)
>
> shelf (https://github.com/dart-lang/shelf/compare/082d3ac..2a46b4f):
>   2a46b4f  2025-08-05  Kevin Moore  Update dependencies across 3 packages (dart-lang/shelf#479)
>
> test (https://github.com/dart-lang/test/compare/5aef971..9354f23):
>   9354f239  2025-08-07  Liam Appelbe  Add `--coverage-path` and `--branch-coverage` options (dart-lang/test#2517)
>
> tools (https://github.com/dart-lang/tools/compare/5e977d6..1b52e89):
>   1b52e89e  2025-08-06  Moritz  Configure Gemini code review (dart-lang/tools#2141)
>
> web (https://github.com/dart-lang/web/compare/1d5771b..f3c960f):
>   f3c960f  2025-08-06  Nikechukwu  [web_generator] Add support for passing files as globs (dart-lang/web#427)
>   f51cc85  2025-08-06  Nikechukwu  [interop] Add Support for Namespaces (dart-lang/web#436)
>
> webdev (https://github.com/dart-lang/webdev/compare/7ff2d07..94c172c):
>   94c172cc  2025-08-05  Nicholas Shahan  Wait for any remaining output in e2e_test.dart (dart-lang/webdev#2663)
>
> Change-Id: Ie18635903f7379bc27e7ae23b916e10e4bdcef94
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444360
> Auto-Submit: Devon Carew <[email protected]>
> Commit-Queue: Konstantin Shcheglov <[email protected]>
> Reviewed-by: Konstantin Shcheglov <[email protected]>

No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I239eff7add9e5432c67b05c8f7731e1a79d4e4db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444387
Bot-Commit: Rubber Stamper <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Rubber Stamper <[email protected]>
Auto-Submit: Devon Carew <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Alexander Aprelev <[email protected]>
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Aug 8, 2025
Revisions updated by `dart tools/rev_sdk_deps.dart`.

dartdoc (https://github.com/dart-lang/dartdoc/compare/414953e..82b48b5):
  82b48b53  2025-08-05  István Soós  Update highlight.js download instructions and resources. (dart-lang/dartdoc#4081)

ecosystem (https://github.com/dart-lang/ecosystem/compare/2fe3618..4543c38):
  4543c38  2025-08-06  Devon Carew  address a `Bad state: No element` element exception (dart-lang/ecosystem#321)
  e14472f  2025-08-06  Devon Carew  add a roadmap to our various mono-repos (dart-lang/ecosystem#318)
  e83479a  2025-08-06  Moritz  Fixes to health (dart-lang/ecosystem#363)
  552f534  2025-08-06  Moritz  Update API tool hash (dart-lang/ecosystem#362)

i18n (https://github.com/dart-lang/i18n/compare/c45e050..25cdb1b):
  25cdb1b4  2025-08-07  Moritz  Reenable mac size checks (dart-lang/i18n#1001)

shelf (https://github.com/dart-lang/shelf/compare/082d3ac..2a46b4f):
  2a46b4f  2025-08-05  Kevin Moore  Update dependencies across 3 packages (dart-lang/shelf#479)

tools (https://github.com/dart-lang/tools/compare/5e977d6..1b52e89):
  1b52e89e  2025-08-06  Moritz  Configure Gemini code review (dart-lang/tools#2141)

web (https://github.com/dart-lang/web/compare/1d5771b..f3c960f):
  f3c960f  2025-08-06  Nikechukwu  [web_generator] Add support for passing files as globs (dart-lang/web#427)
  f51cc85  2025-08-06  Nikechukwu  [interop] Add Support for Namespaces (dart-lang/web#436)

webdev (https://github.com/dart-lang/webdev/compare/7ff2d07..94c172c):
  94c172cc  2025-08-05  Nicholas Shahan  Wait for any remaining output in e2e_test.dart (dart-lang/webdev#2663)

Change-Id: Id553d989bdb5aea483e6ad7d955a965cfaa3cf16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444362
Auto-Submit: Devon Carew <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants