Skip to content

Commit 4316a1a

Browse files
committed
Fix indentation of JSX inside of list item inside of JSX
1 parent e5b6658 commit 4316a1a

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,9 @@ function containerFlow(parent, state, info) {
772772
function inferDepth(state) {
773773
let depth = 0
774774

775-
for (const x of state.stack) {
775+
for (let i = state.stack.length - 1; i >= 0; i--) {
776+
const x = state.stack[i]
777+
if (x === 'listItem') break
776778
if (x === 'mdxJsxFlowElement') {
777779
depth++
778780
}

test.js

+34
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,40 @@ test('roundtrip', async function (t) {
25492549
)
25502550
}
25512551
)
2552+
2553+
await t.test('should roundtrip `nested JSXs and lists`', async function () {
2554+
const source = `<JSX>
2555+
* list item
2556+
2557+
<JSX>
2558+
* list item
2559+
2560+
<JSX>
2561+
<JSX>
2562+
* list item
2563+
2564+
* list item
2565+
2566+
<JSX>
2567+
content
2568+
</JSX>
2569+
2570+
<JSX>
2571+
content
2572+
</JSX>
2573+
</JSX>
2574+
</JSX>
2575+
</JSX>
2576+
2577+
<JSX>
2578+
<JSX>
2579+
content
2580+
</JSX>
2581+
</JSX>
2582+
</JSX>
2583+
`
2584+
equal(source, source)
2585+
})
25522586
})
25532587

25542588
/**

0 commit comments

Comments
 (0)