Elide empty named imports next to a default import under verbatimModuleSyntax - #64578
Conversation
…leSyntax
With verbatimModuleSyntax, erasing every type-only specifier next to a default import used to leave behind an empty {}. The default binding already keeps the import, so the empty braces are dropped now. Braces written in the source and imports without a default binding are unchanged.
Fixes microsoft#62239
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The narrow guard matches the intended behavior, regression cases cover its boundaries, and no blocking issues were identified.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes #62239 by dropping named-import braces emptied by type erasure when a default import remains under verbatimModuleSyntax.
Changes:
- Updates the type eraser while preserving source-written
{}and imports without a default binding. - Adds regression coverage and matching emit, type, and symbol baselines.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/verbatimModuleSyntaxDefaultImportTypeOnlyNamed.ts |
Tests elision and preservation cases. |
tsc/testdata/baselines/reference/compiler/verbatimModuleSyntaxDefaultImportTypeOnlyNamed.types |
Records expected types. |
tsc/testdata/baselines/reference/compiler/verbatimModuleSyntaxDefaultImportTypeOnlyNamed.symbols |
Records expected symbols. |
tsc/testdata/baselines/reference/compiler/verbatimModuleSyntaxDefaultImportTypeOnlyNamed.js |
Records expected import emission. |
tsc/internal/transformers/tstransforms/typeeraser.go |
Removes redundant empty named bindings. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
I thought this behavior was intentional? Andrew Branch (@andrewbranch) |
|
Yes, because |
|
Makes sense. Node's type stripping, ts-blank-space and esbuild all keep the |
|
Sorry, I misread the issue; I didn't realize that the first default import was not also a |
|
|
Fixes #62239
With verbatimModuleSyntax on, tsc kept an empty
{}after a default import when all the named imports were type-only:The default binding keeps the import, so the braces do nothing there. Imports without a default binding still emit
import {} from "./a", and a{}you write in the source stays. 6.0 emits the braces too, and this PR changes that. Ryan approved the same change for the old codebase in #62349 before the bot closed it during the 6.0 freeze.I wrote this change with Claude Code. I chose this issue, read and understand the change, and will handle review feedback myself.