rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[api-extractor] refactor import() type support, to support more cases

Open adventure-yunfei opened this issue 4 months ago • 3 comments

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 https://github.com/adventure-yunfei/web-build-tools/pull/4.)

How it was tested

Add more test cases for dymanic import type.

Impacted documentation

adventure-yunfei avatar Aug 28 '25 06:08 adventure-yunfei

seems pretty easy to support import Foo = X.Y.Z;, with AstSubPathImport entity. see https://github.com/adventure-yunfei/web-build-tools/pull/6

adventure-yunfei avatar Aug 28 '25 09:08 adventure-yunfei

@adventure-yunfei 想不想来字节跳动一起工作啊?😸

octogonz avatar Sep 12 '25 03:09 octogonz

@adventure-yunfei 想不想来字节跳动一起工作啊?😸

才发现去 tiktok 了。现在还没换工作的想法。字节国内外都是好公司,后续有机会的话当然要试一下。

adventure-yunfei avatar Oct 13 '25 02:10 adventure-yunfei