Skip to content

Commit 63b7767

Browse files
committed
Refactor code-style
1 parent 761add9 commit 63b7767

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

lib/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,19 +765,18 @@ function containerFlow(parent, state, info) {
765765
}
766766

767767
/**
768-
*
769768
* @param {State} state
770769
* @returns {number}
771770
*/
772771
function inferDepth(state) {
773772
let depth = 0
773+
let index = state.stack.length
774774

775-
for (let i = state.stack.length - 1; i >= 0; i--) {
776-
const x = state.stack[i]
777-
if (x === 'listItem') break
778-
if (x === 'mdxJsxFlowElement') {
779-
depth++
780-
}
775+
while (--index > -1) {
776+
const name = state.stack[index]
777+
778+
if (name === 'listItem') break
779+
if (name === 'mdxJsxFlowElement') depth++
781780
}
782781

783782
return depth

test.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,35 +2551,35 @@ test('roundtrip', async function (t) {
25512551
)
25522552

25532553
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>
2554+
const source = `<x>
2555+
* Alpha
2556+
2557+
<y>
2558+
* Bravo
2559+
2560+
<z>
2561+
<a>
2562+
* Charlie
2563+
2564+
* Delta
2565+
2566+
<b>
2567+
Echo
2568+
</b>
2569+
2570+
<b>
2571+
Foxtrot
2572+
</b>
2573+
</a>
2574+
</z>
2575+
</y>
2576+
2577+
<y>
2578+
<z>
2579+
Golf
2580+
</z>
2581+
</y>
2582+
</x>
25832583
`
25842584
equal(source, source)
25852585
})

0 commit comments

Comments
 (0)