[api-extractor] refactor import() type support, to support more cases
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 atype-onlyimport to an AstImport entity - for local
import(), simplify code to parse the localAstModuleand 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 forimport()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
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 想不想来字节跳动一起工作啊?😸
@adventure-yunfei 想不想来字节跳动一起工作啊?😸
才发现去 tiktok 了。现在还没换工作的想法。字节国内外都是好公司,后续有机会的话当然要试一下。