本文整理汇总了TypeScript中babel-traverse.NodePath.isJSXElement方法的典型用法代码示例。如果您正苦于以下问题:TypeScript NodePath.isJSXElement方法的具体用法?TypeScript NodePath.isJSXElement怎么用?TypeScript NodePath.isJSXElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babel-traverse.NodePath
的用法示例。
在下文中一共展示了NodePath.isJSXElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setAncestorCondition
export function setAncestorCondition (jsx: NodePath<t.Node>, expr: t.Expression): t.Expression {
const ifAttrSet = new Set<string>([
Adapter.if,
Adapter.else
])
const logicalJSX = jsx.findParent(p => p.isJSXElement() && p.node.openingElement.attributes.some(a => ifAttrSet.has(a.name.name as string))) as NodePath<t.JSXElement>
if (logicalJSX) {
const attr = logicalJSX.node.openingElement.attributes.find(a => ifAttrSet.has(a.name.name as string))
if (attr) {
if (attr.name.name === Adapter.else) {
const prevElement: NodePath<t.JSXElement | null> = (logicalJSX as any).getPrevSibling()
if (prevElement && prevElement.isJSXElement()) {
const attr = prevElement.node.openingElement.attributes.find(a => a.name.name === Adapter.if)
if (attr && t.isJSXExpressionContainer(attr.value)) {
const condition = reverseBoolean(cloneDeep(attr.value.expression))
expr = t.logicalExpression('&&', setAncestorCondition(logicalJSX, condition), expr)
}
}
} else if (t.isJSXExpressionContainer(attr.value)) {
const condition = cloneDeep(attr.value.expression)
expr = t.logicalExpression('&&', setAncestorCondition(logicalJSX, condition), expr)
}
}
}
return expr
}
示例2: findWXIfProps
function findWXIfProps (
jsx: NodePath<t.Node>
): { reg: RegExpMatchArray; tester: AttrValue } | null {
let matches: { reg: RegExpMatchArray; tester: AttrValue } | null = null
jsx &&
jsx.isJSXElement() &&
jsx
.get('openingElement')
.get('attributes')
.some(path => {
const attr = path.node
if (t.isJSXIdentifier(attr.name)) {
const name = attr.name.name
if (name === WX_IF) {
return true
}
const match = name.match(/wx:else|wx:elif/)
if (match) {
path.remove()
matches = {
reg: match,
tester: attr.value
}
return true
}
}
return false
})
return matches
}
示例3: setParentCondition
export function setParentCondition (jsx: NodePath<t.Node>, expr: t.Expression, array = false) {
const conditionExpr = jsx.findParent(p => p.isConditionalExpression())
const logicExpr = jsx.findParent(p => p.isLogicalExpression({ operator: '&&' }))
if (array) {
const ifAttrSet = new Set<string>([
Adapter.if,
Adapter.else
])
const logicalJSX = jsx.findParent(p => p.isJSXElement() && p.node.openingElement.attributes.some(a => ifAttrSet.has(a.name.name as string))) as NodePath<t.JSXElement>
if (logicalJSX) {
const attr = logicalJSX.node.openingElement.attributes.find(a => ifAttrSet.has(a.name.name as string))
if (attr) {
if (attr.name.name === Adapter.else) {
const prevElement: NodePath<t.JSXElement | null> = (logicalJSX as any).getPrevSibling()
if (prevElement && prevElement.isJSXElement()) {
const attr = prevElement.node.openingElement.attributes.find(a => a.name.name === Adapter.if)
if (attr && t.isJSXExpressionContainer(attr.value)) {
expr = t.conditionalExpression(reverseBoolean(cloneDeep(attr.value.expression)), expr, t.arrayExpression())
return expr
}
}
} else if (t.isJSXExpressionContainer(attr.value)) {
expr = t.conditionalExpression(cloneDeep(attr.value.expression), expr, t.arrayExpression())
return expr
}
}
}
}
if (conditionExpr && conditionExpr.isConditionalExpression()) {
const consequent = conditionExpr.get('consequent')
if (consequent === jsx || jsx.findParent(p => p === consequent)) {
expr = t.conditionalExpression(cloneDeep(conditionExpr.get('test').node) as any, expr, array ? t.arrayExpression([]) : t.nullLiteral())
}
}
if (logicExpr && logicExpr.isLogicalExpression({ operator: '&&' })) {
const consequent = logicExpr.get('right')
if (consequent === jsx || jsx.findParent(p => p === consequent)) {
expr = t.conditionalExpression(cloneDeep(logicExpr.get('left').node) as any, expr, array ? t.arrayExpression([]) : t.nullLiteral())
}
}
return expr
}