fix(writer): don't splice import type { as a Python simple import#83
Merged
gjtorikian merged 1 commit intoMay 19, 2026
Merged
Conversation
`isPythonSimpleImport` matched any line starting with `import` followed
by a word character and lacking a `from` clause. That correctly catches
Python's `import hashlib` and rejects TS's `import X from '…'`, but it
also matched the bare first line of a TS multi-line type import:
import type {
WebhookEndpoint,
} from './interfaces/webhook-endpoint.interface';
The opener `import type {` has no `from` on its own line, so the
detector pulled it into `existingSimple` and the splice step injected
the bare opener into the regenerated file — producing an orphan
`import type {` that broke TypeScript parsing.
Tighten the regex to exclude lines containing `{` or `}`. Multi-line TS
type imports are already covered by the dedicated TS collector below.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
isPythonSimpleImportmatched the bare opener of a TS multi-lineimport type { … }block, splicing a strandedimport type {line into regenerated files and breaking TypeScript parsing.{or}— multi-line TS type imports are already covered by the dedicated TS collector.import type {is not spliced as a simple import when the existing file uses multi-line TS type imports.Repro
When the existing file looks like:
…and the emitter regenerates with a single-line type import, the second line (
import type {) — having nofromon its own line — was treated as a Python simple import likeimport json, andspliceExtraImportsinjected it verbatim into the output as an orphan.Test plan
npm test(1422/1422)npm run typechecknpm run lintworkos-nodeno longer produces an orphanimport type {insrc/webhooks/webhooks.ts.🤖 Generated with Claude Code