Skip to content

Fix anchor on MappingStart in sequence entry losing prefix#6732

Merged
knutwannheden merged 1 commit intomainfrom
yaml-anchor-parser-fix
Feb 13, 2026
Merged

Fix anchor on MappingStart in sequence entry losing prefix#6732
knutwannheden merged 1 commit intomainfrom
yaml-anchor-parser-fix

Conversation

@knutwannheden
Copy link
Copy Markdown
Contributor

@knutwannheden knutwannheden commented Feb 13, 2026

Summary

  • Fix YAML parser losing the dash prefix when an anchor appears on a MappingStart event inside a sequence entry (e.g. - &b\n k2: v2)
  • The dash-index truncation of fmt in the MappingStart anchor handling was incorrectly stripping the - from the format string, causing SequenceBuilder to create entries with isDash=false
  • Add tests for both Java and TypeScript parsers

Test plan

  • New test anchorOnMappingInSequenceEntry passes
  • Full :rewrite-yaml:test suite passes with no regressions
  • TypeScript parser test added (already handled this case correctly)

When a YAML anchor appeared on a MappingStart event inside a sequence
(e.g. `- &b\n  k2: v2`), the dash prefix was incorrectly truncated
from the mapping's format string. This caused the SequenceBuilder to
create an entry with isDash=false, producing `- k: v &b\n  k2: v2`
instead of preserving the original `- k: v\n- &b\n  k2: v2`.

The fix removes the dash-index truncation of `fmt` in the MappingStart
anchor handling. The `fmt` is kept as-is so the SequenceBuilder can
properly split it and preserve the dash indicator.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Feb 13, 2026
@knutwannheden knutwannheden merged commit b65f9c0 into main Feb 13, 2026
1 check passed
@knutwannheden knutwannheden deleted the yaml-anchor-parser-fix branch February 13, 2026 10:38
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant