當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript NodePath.getAllNextSiblings方法代碼示例

本文整理匯總了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)
}
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:48,代碼來源:wxml.ts

示例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)
}
開發者ID:topud,項目名稱:taro,代碼行數:40,代碼來源:wxml.ts


注:本文中的babel-traverse.NodePath.getAllNextSiblings方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。