Skip to content

Conversation

adventure-yunfei
Copy link
Contributor

@adventure-yunfei adventure-yunfei commented Aug 28, 2025

Summary

Refactor import() type syntax support. Fixes cases in #5326 (except for one very rare case that requires more code changes: typeof import("./foo")").

Details

For import("foo").X.Y.Z import type syntax, instead of create a new ImportType kind of AstImport, creating a new synthetic entity AstSubPathImport to represent "importing nested part from an AstEntity".

Some detail changes:

  • import() is handled as a type-only import to an AstImport entity
  • for local import(), simplify code to parse the local AstModule and its first export, instead of parsing the right-most symbol.
  • for DtsEmitHelper, decouple code to modify import type node only by related entity info. (no assumption that always importing from top namespace. that may changes in some optimization cases which is not implemented yet.)
  • for AstNamespaceImport, remove declaration symbol (use module symbol instead) and use ts.SourceFile declaration for import() type syntax

I also plan to use AstSubPathImport (or a better name?) to support import equal syntax import Foo = X.Y.Z (which implemented in another way in adventure-yunfei#4.)

How it was tested

Add more test cases for dymanic import type.

Impacted documentation

@adventure-yunfei
Copy link
Contributor Author

seems pretty easy to support import Foo = X.Y.Z;, with AstSubPathImport entity. see adventure-yunfei#6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs triage
Development

Successfully merging this pull request may close these issues.

1 participant