Skip to content

fix(writer): don't splice import type { as a Python simple import#83

Merged
gjtorikian merged 1 commit into
mainfrom
fix-writer-python-simple-import-excludes-ts-brace
May 19, 2026
Merged

fix(writer): don't splice import type { as a Python simple import#83
gjtorikian merged 1 commit into
mainfrom
fix-writer-python-simple-import-excludes-ts-brace

Conversation

@gjtorikian
Copy link
Copy Markdown
Collaborator

Summary

  • isPythonSimpleImport matched the bare opener of a TS multi-line import type { … } block, splicing a stranded import type { line into regenerated files and breaking TypeScript parsing.
  • Tighten the detector to also exclude lines containing { or } — multi-line TS type imports are already covered by the dedicated TS collector.
  • Added a regression test that asserts 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:

import type { WorkOS } from '../workos';
import type {
  WebhookEndpoint,
} from './interfaces/webhook-endpoint.interface';
import { deserializeEvent } from '../common/serializers';

…and the emitter regenerates with a single-line type import, the second line (import type {) — having no from on its own line — was treated as a Python simple import like import json, and spliceExtraImports injected it verbatim into the output as an orphan.

Test plan

  • npm test (1422/1422)
  • npm run typecheck
  • npm run lint
  • Verified end-to-end: regenerated workos-node no longer produces an orphan import type { in src/webhooks/webhooks.ts.

🤖 Generated with Claude Code

`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>
@gjtorikian gjtorikian merged commit 8f7e245 into main May 19, 2026
5 checks passed
@gjtorikian gjtorikian deleted the fix-writer-python-simple-import-excludes-ts-brace branch May 19, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant