fix: keep indent indicator on empty block scalar before a comment#697
Open
maximilize wants to merge 1 commit into
Open
fix: keep indent indicator on empty block scalar before a comment#697maximilize wants to merge 1 commit into
maximilize wants to merge 1 commit into
Conversation
An empty block scalar followed by a document comment dropped its explicit indent indicator, so on re-parse the comment was absorbed as the scalar's content. Emit the indicator for the empty-value case under forceBlockIndent, mirroring the existing indentSize logic. Fixes eemeli#687.
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.
Problem
Document.toString()corrupts an empty block scalar that is followed by a document comment — the comment round-trips back as the scalar's content:Fixes #687.
Cause
blockString()returns a bare|/>for an empty value, dropping the indent indicator even whenctx.forceBlockIndentis set — whichstringifyDocumentsets precisely when a document comment follows. Without the indicator the empty scalar has no explicit extent, so the trailing comment is absorbed as its content on re-parse.Fix
Emit the indent indicator for the empty-value case when
forceBlockIndentis set, mirroring the existingindentSizelogic a few lines below.Tests
Added a round-trip regression test in
tests/doc/comments.ts. The full suite passes, including the YAML and JSON test suites — no regressions.🤖 This pull request was written with AI assistance (Claude Code).