Elide namespace imports used only by type-only export aliases#4110
Elide namespace imports used only by type-only export aliases#4110Copilot wants to merge 2 commits into
Conversation
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
| if isPartOfImportEqualsModuleReference(location) { | ||
| return | ||
| } |
There was a problem hiding this comment.
The old compiler normally does not reach this case for checked TS emit: it records references during checking with specific hints (the import = declaration is marked via ReferenceHint.ExportImportEquals), rather than treating the RHS qualified name as an emitted expression. Its recursive markLinkedReferences fallback is mainly for noCheck/unchecked emit, where this pattern also preserves the import. tsgo currently relies on the recursive pass for normal import elision, so the RHS ns.A was visited and incorrectly marked ns as a value reference unless we skip import-equals module references here.
There was a problem hiding this comment.
The old compiler normally does not reach this case for checked TS emit: it records references during checking with specific hints (the import = declaration is marked via ReferenceHint.ExportImportEquals), rather than treating the RHS qualified name as an emitted expression. Its recursive markLinkedReferences fallback is mainly for noCheck/unchecked emit, where this pattern also preserves the import. tsgo currently relies on the recursive pass for normal import elision, so the RHS ns.A was visited and incorrectly marked ns as a value reference unless we skip import-equals module references here.
A namespace import was preserved when its only use was a type-only
export importalias. This caused tsgo to emit runtime imports that TypeScript elides.Alias reference tracking
import =alias.import =reference path.Regression coverage
which now emits: