diff --git a/packages/eslint-mdx/src/worker.ts b/packages/eslint-mdx/src/worker.ts index 08877d6..47be4bf 100644 --- a/packages/eslint-mdx/src/worker.ts +++ b/packages/eslint-mdx/src/worker.ts @@ -377,60 +377,53 @@ runAsWorker( function handleChildren(node: Nodes) { return 'children' in node - ? (node.children as Nodes[]).reduce( - (acc, child) => { - processed.add(child) - - if ( - child.data && - 'estree' in child.data && - child.data.estree - ) { - const { estree } = child.data - - assert(estree.body.length <= 1) - - const statement = estree.body[0] - - isExpressionStatement(statement) - - const expression = statement?.expression - - if (child.type === 'mdxTextExpression') { - const { - start: { offset: start }, - end: { offset: end }, - } = node.position - - const expressionContainer: JSXExpressionContainer = { - ...normalizeNode(start, end), - type: 'JSXExpressionContainer', - expression: expression || { - ...normalizeNode(start + 1, end - 1), - type: 'JSXEmptyExpression', - }, - } - acc.push(expressionContainer) - } else if (expression) { - acc.push(expression as JSXElement['children'][number]) - } + ? node.children.reduce((acc, child) => { + processed.add(child) - comments.push(...estree.comments) - } else { - const expression = handleNode(child) as Arrayable< - JSXElement['children'] - > - if (Array.isArray(expression)) { - acc.push(...expression) - } else if (expression) { - acc.push(expression) + if (child.data && 'estree' in child.data && child.data.estree) { + const { estree } = child.data + + assert(estree.body.length <= 1) + + const statement = estree.body[0] + + isExpressionStatement(statement) + + const expression = statement?.expression + + if (child.type === 'mdxTextExpression') { + const { + start: { offset: start }, + end: { offset: end }, + } = node.position + + const expressionContainer: JSXExpressionContainer = { + ...normalizeNode(start, end), + type: 'JSXExpressionContainer', + expression: expression || { + ...normalizeNode(start + 1, end - 1), + type: 'JSXEmptyExpression', + }, } + acc.push(expressionContainer) + } else if (expression) { + acc.push(expression as JSXElement['children'][number]) } - return acc - }, - [], - ) + comments.push(...estree.comments) + } else { + const expression = handleNode(child) as Arrayable< + JSXElement['children'] + > + if (Array.isArray(expression)) { + acc.push(...expression) + } else if (expression) { + acc.push(expression) + } + } + + return acc + }, []) : [] }