本文整理匯總了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)
}