This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

59
node_modules/hast-util-to-estree/lib/handlers/root.js generated vendored Normal file
View File

@@ -0,0 +1,59 @@
/**
* @typedef {import('estree-jsx').JSXFragment} JsxFragment
*
* @typedef {import('hast').Root} HastRoot
*
* @typedef {import('../state.js').State} State
*/
/**
* @typedef {JsxFragment['children'][number]} JsxChild
*/
import {whitespace} from 'hast-util-whitespace'
/**
* Turn a hast root node into an estree node.
*
* @param {HastRoot} node
* hast node to transform.
* @param {State} state
* Info passed around about the current state.
* @returns {JsxFragment}
* estree JSX fragment.
*/
export function root(node, state) {
const children = state.all(node)
/** @type {Array<JsxChild>} */
const cleanChildren = []
let index = -1
/** @type {Array<JsxChild> | undefined} */
let queue
// Remove surrounding whitespace nodes from the fragment.
while (++index < children.length) {
const child = children[index]
if (
child.type === 'JSXExpressionContainer' &&
child.expression.type === 'Literal' &&
whitespace(String(child.expression.value))
) {
if (queue) queue.push(child)
} else {
if (queue) cleanChildren.push(...queue)
cleanChildren.push(child)
queue = []
}
}
/** @type {JsxFragment} */
const result = {
type: 'JSXFragment',
openingFragment: {type: 'JSXOpeningFragment'},
closingFragment: {type: 'JSXClosingFragment'},
children: cleanChildren
}
state.inherit(node, result)
return result
}