Skip to content

Fix indent of JSX in lists in JSX #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading