Skip to content

fix(@formatjs/unplugin): preserve space when removing JSX attribute on single line#6165

Merged
longlho merged 2 commits intomainfrom
claude/issue-6164-20260318-2139
Mar 19, 2026
Merged

fix(@formatjs/unplugin): preserve space when removing JSX attribute on single line#6165
longlho merged 2 commits intomainfrom
claude/issue-6164-20260318-2139

Conversation

@longlho
Copy link
Member

@longlho longlho commented Mar 19, 2026

When a JSX attribute (e.g. description) preceded another attribute on the same line and was removed, the removeJSXAttribute function consumed both the leading and trailing whitespace, producing invalid-looking output like <FormattedMessagedefaultMessage={...} />.

Fixes #6164

Generated with Claude Code

github-actions bot and others added 2 commits March 18, 2026 21:45
…n single line

When a JSX attribute (e.g. description) preceded another attribute on the
same line and was removed, the removeJSXAttribute function was consuming
both the leading and trailing whitespace around the attribute. This left
no space separator between the element name and the next attribute,
producing invalid-looking output like:

  <FormattedMessagedefaultMessage={...} />

The fix: stop consuming trailing whitespace. Expand backward only,
including the preceding newline (for multi-line JSX) so entire lines are
cleanly removed in that case. This ensures the space before the following
attribute is always preserved on single-line elements.

Fixes #6164

Co-authored-by: Long Ho <longlho@users.noreply.github.com>
…SX attr

- Fix bug where generated id was swallowed when description was the first
  JSX attribute (insertionPoint coincided with the removal range)
- Change JSX insertionPoint to always use elementNode.name.end instead of
  firstAttr.start, making id insertion immune to attribute removals
- Replace loose toContain/not.toContain test assertions with exact toBe
  checks for deterministic output verification

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@longlho longlho enabled auto-merge (squash) March 19, 2026 00:58
@longlho longlho merged commit db32215 into main Mar 19, 2026
6 checks passed
@longlho longlho deleted the claude/issue-6164-20260318-2139 branch March 19, 2026 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated code lacks a space when FormattedMessage is on one line

1 participant