Skip to content

Commit

Permalink
fix: Ignore newline after block seq indicator as space before value (f…
Browse files Browse the repository at this point in the history
…ixes #590)
  • Loading branch information
eemeli committed Nov 23, 2024
1 parent aa1898a commit 38affe5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compose/resolve-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function resolveProps(
case 'newline':
if (atNewline) {
if (comment) comment += token.source
else spaceBefore = true
else if (!found || indicator !== 'seq-item-ind') spaceBefore = true
} else commentSep += token.source
atNewline = true
hasNewline = true
Expand Down
23 changes: 23 additions & 0 deletions tests/doc/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,29 @@ describe('blank lines', () => {
expect(String(doc)).toBe('- a\n\n- b\n\n- c\n')
})

test('between seq indicator and value (#590)', () => {
const src = source`
key:
-
- a
-
-
b
`
const doc = YAML.parseDocument(src)
expect(String(doc)).toBe(
source`
key:
- a
- b
`.replace(/·/g, ' ')
)
})

test('between seq items with leading comments', () => {
const src = source`
#A
Expand Down

0 comments on commit 38affe5

Please sign in to comment.