Skip to content

Commit

Permalink
Fix indent of JSX in lists in JSX
Browse files Browse the repository at this point in the history
Closes GH-13.

Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
XiNiHa authored Mar 13, 2024
1 parent e5b6658 commit 04dffd3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,9 @@ function containerFlow(parent, state, info) {
function inferDepth(state) {
let depth = 0

for (const x of state.stack) {
for (let i = state.stack.length - 1; i >= 0; i--) {
const x = state.stack[i]
if (x === 'listItem') break
if (x === 'mdxJsxFlowElement') {
depth++
}
Expand Down
34 changes: 34 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2549,6 +2549,40 @@ test('roundtrip', async function (t) {
)
}
)

await t.test('should roundtrip `nested JSXs and lists`', async function () {
const source = `<JSX>
* list item
<JSX>
* list item
<JSX>
<JSX>
* list item
* list item
<JSX>
content
</JSX>
<JSX>
content
</JSX>
</JSX>
</JSX>
</JSX>
<JSX>
<JSX>
content
</JSX>
</JSX>
</JSX>
`
equal(source, source)
})
})

/**
Expand Down

0 comments on commit 04dffd3

Please sign in to comment.