Skip to content

fix: keep indentation indicator on empty block scalar before a comment - #711

Open
abhijeet117 wants to merge 1 commit into
eemeli:mainfrom
abhijeet117:fix/empty-block-scalar-comment-indicator
Open

fix: keep indentation indicator on empty block scalar before a comment#711
abhijeet117 wants to merge 1 commit into
eemeli:mainfrom
abhijeet117:fix/empty-block-scalar-comment-indicator

Conversation

@abhijeet117

Copy link
Copy Markdown

Summary

For an empty block scalar followed by a document-level comment, toString() emitted a bare | header without an indentation indicator. When that output is re-parsed, the comment line is no longer outside the block scalar and becomes part of the scalar value, so parseDocument('|5\n#comment\n').toString() does not round-trip: the comment turns into string data. The empty-value branch now emits an indentation indicator when a top-level comment follows, matching the protection that non-empty block scalars get through forced content indentation.

Testing

Reproduced with parseDocument('|5\n#comment\n'): the first toString() output reparsed as the value "\n\n#comment\n" with no comment. Added a round-trip regression test in tests/doc/comments.ts that fails without this change. Full vitest suite passes (3387 tests), eslint and tsc are clean.

Checklist

  • bug reproduced before fix
  • root cause identified
  • bug fixed
  • tests passed

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.

1 participant