Skip to content

fix(writer): splice hand-written PHP and Ruby imports during overwrite#81

Merged
gjtorikian merged 1 commit into
fix-writer-ts-import-splicingfrom
fix-writer-php-ruby-import-splicing
May 18, 2026
Merged

fix(writer): splice hand-written PHP and Ruby imports during overwrite#81
gjtorikian merged 1 commit into
fix-writer-ts-import-splicingfrom
fix-writer-php-ruby-import-splicing

Conversation

@gjtorikian
Copy link
Copy Markdown
Collaborator

Stacked on top of #80. Targets that branch; rebase to main once #80 merges.

Summary

Same gap as #80, applied proactively to PHP and Ruby. spliceExtraImports now preserves:

  • PHP: use Foo\Bar; and use Foo\Bar as Baz; — namespace-qualified only (a backslash anywhere in the path). Single-segment use TraitName; is left alone so in-class trait references inside the file body aren't mistakenly hoisted to the top.
  • Ruby: require '…' and require_relative '…'.

The lastImportIdx loop is also widened so PHP use and Ruby require lines anchor the splice position in the import block.

Why now (currently latent in both)

  • workos-php: WorkOS.php has @oagen-ignore-start/end regions referencing Passwordless, Vault, WebhookVerification, and Actions, but those classes live in the same WorkOS\ namespace so PHP resolves them without use. The day any of those moves to a sub-namespace, hand-written use statements would have been silently dropped.
  • workos-ruby: ships no @oagen-ignore-start/end regions today, but the Ruby emitter knows how to emit them; the first hand-written method needing an extra require_relative would have tripped the same gap.

Test plan

  • npm test — 1421/1421 pass; new tests for PHP use and Ruby require/require_relative preservation in writer-ignore.test.ts
  • npm run typecheck — clean

🤖 Generated with Claude Code

Same gap as the TypeScript fix in the prior commit, applied
proactively to PHP and Ruby. `spliceExtraImports` now preserves:

- PHP `use Foo\\Bar;` and `use Foo\\Bar as Baz;` (namespace-qualified
  only — single-segment `use TraitName;` is left alone so in-class
  trait references aren't mistakenly hoisted to the top of the file).
- Ruby `require '…'` and `require_relative '…'`.

Currently latent in both languages:

- workos-php's `WorkOS.php` has `@oagen-ignore-start/end` regions
  referencing `Passwordless`, `Vault`, `WebhookVerification`, and
  `Actions`, but those classes live in the same `WorkOS\\` namespace
  so PHP resolves them without `use`. The day any of those moves to
  a sub-namespace, hand-written `use` statements would have been
  silently dropped.
- workos-ruby ships no `@oagen-ignore-start/end` regions today, but
  the Ruby emitter knows how to emit them; the first hand-written
  method needing an extra `require_relative` would have tripped the
  same gap.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gjtorikian gjtorikian merged commit debf020 into fix-writer-ts-import-splicing May 18, 2026
5 checks passed
@gjtorikian gjtorikian deleted the fix-writer-php-ruby-import-splicing branch May 18, 2026 23:58
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