本文整理汇总了TypeScript中babel-traverse.NodePath.getAllNextSiblings方法的典型用法代码示例。如果您正苦于以下问题:TypeScript NodePath.getAllNextSiblings方法的具体用法?TypeScript NodePath.getAllNextSiblings怎么用?TypeScript NodePath.getAllNextSiblings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babel-traverse.NodePath
的用法示例。
在下文中一共展示了NodePath.getAllNextSiblings方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: transformIf
function transformIf (
name: string,
attr: NodePath<t.JSXAttribute>,
jsx: NodePath<t.JSXElement>,
value: AttrValue
) {
if (name !== WX_IF) {
return
}
const conditions: Condition[] = []
let siblings: NodePath<t.Node>[] = []
try {
siblings = jsx.getAllNextSiblings().filter(s => !(s.isJSXExpressionContainer() && s.get('expression').isJSXEmptyExpression()))
} catch (error) {
return
}
if (value === null || !t.isJSXExpressionContainer(value)) {
// tslint:disable-next-line
console.error('wx:if 的值需要用双括号 `{{}}` 包裹它的值')
if (value && t.isStringLiteral(value)) {
value = t.jSXExpressionContainer(buildTemplate(value.value))
}
}
conditions.push({
condition: WX_IF,
path: jsx,
tester: value as t.JSXExpressionContainer
})
attr.remove()
for (let index = 0; index < siblings.length; index++) {
const sibling = siblings[index]
const next = cloneDeep(siblings[index + 1])
const currMatches = findWXIfProps(sibling)
const nextMatches = findWXIfProps(next)
if (currMatches === null) {
break
}
conditions.push({
condition: currMatches.reg.input as string,
path: sibling as any,
tester: currMatches.tester as t.JSXExpressionContainer
})
if (nextMatches === null) {
break
}
}
handleConditions(conditions)
}
示例2: transformIf
function transformIf (
name: string,
attr: NodePath<t.JSXAttribute>,
jsx: NodePath<t.JSXElement>,
value: AttrValue
) {
if (name !== WX_IF) {
return
}
const conditions: Condition[] = []
let siblings: NodePath<t.Node>[] = []
try {
siblings = jsx.getAllNextSiblings()
} catch (error) {
return
}
conditions.push({
condition: WX_IF,
path: jsx,
tester: value as t.JSXExpressionContainer
})
attr.remove()
for (const [index, sibling] of siblings.entries()) {
const next = siblings[index + 1]
const currMatches = findWXIfProps(sibling)
const nextMatches = findWXIfProps(next)
if (currMatches === null) {
break
}
conditions.push({
condition: currMatches.reg.input as string,
path: sibling as any,
tester: currMatches.tester as t.JSXExpressionContainer
})
if (nextMatches === null) {
break
}
}
handleConditions(conditions)
}