• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript babel-types.isJSXIdentifier函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中babel-types.isJSXIdentifier函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isJSXIdentifier函数的具体用法?TypeScript isJSXIdentifier怎么用?TypeScript isJSXIdentifier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了isJSXIdentifier函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: convertAstExpressionToVariable

export function convertAstExpressionToVariable (node) {
  if (t.isObjectExpression(node)) {
    const obj = {}
    const properties = node.properties
    properties.forEach(property => {
      if (property.type === 'ObjectProperty' || property.type === 'ObjectMethod') {
        const key = convertAstExpressionToVariable(property.key)
        const value = convertAstExpressionToVariable(property.value)
        obj[key] = value
      }
    })
    return obj
  } else if (t.isArrayExpression(node)) {
    return node.elements.map(convertAstExpressionToVariable)
  } else if (t.isLiteral(node)) {
    return node['value']
  } else if (t.isIdentifier(node) || t.isJSXIdentifier(node)) {
    const name = node.name
    return name === 'undefined'
      ? undefined
      : name
  } else if (t.isJSXExpressionContainer(node)) {
    return convertAstExpressionToVariable(node.expression)
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:25,代码来源:astConvert.ts


示例2: replaceJSXTextWithTextComponent

export function replaceJSXTextWithTextComponent (path: NodePath<t.JSXText | t.JSXExpressionContainer>) {
  const parent = path.findParent(p => p.isJSXElement())
  if (parent && parent.isJSXElement() && t.isJSXIdentifier(parent.node.openingElement.name) && parent.node.openingElement.name.name !== 'Text') {
    path.replaceWith(t.jSXElement(
      t.jSXOpeningElement(t.jSXIdentifier('Text'), []),
      t.jSXClosingElement(t.jSXIdentifier('Text')),
      [path.isJSXText() ? t.jSXText(path.node.value) : path.node]
    ))
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:10,代码来源:utils.ts


示例3: findJSXAttrByName

export function findJSXAttrByName (attrs: t.JSXAttribute[], name: string) {
  for (const attr of attrs) {
    if (!t.isJSXIdentifier(attr.name)) {
      break
    }
    if (attr.name.name === name) {
      return attr
    }
  }
  return null
}
开发者ID:AlloyTeam,项目名称:Nuclear,代码行数:11,代码来源:jsx.ts


示例4: getWXS

function getWXS (attrs: t.JSXAttribute[], path: NodePath<t.JSXElement>, imports: Imports[]): WXS {
  let moduleName: string | null = null
  let src: string | null = null

  for (const attr of attrs) {
    if (t.isJSXIdentifier(attr.name)) {
      const attrName = attr.name.name
      const attrValue = attr.value
      let value: string | null = null
      if (attrValue === null) {
        throw new Error('WXS 标签的属性值不得为空')
      }
      if (t.isStringLiteral(attrValue)) {
        value = attrValue.value
      } else if (
        t.isJSXExpressionContainer(attrValue) &&
        t.isStringLiteral(attrValue.expression)
      ) {
        value = attrValue.expression.value
      }
      if (attrName === 'module') {
        moduleName = value
      }
      if (attrName === 'src') {
        src = value
      }
    }
  }

  if (!src) {
    const { children: [ script ] } = path.node
    if (!t.isJSXText(script)) {
      throw new Error('wxs 如果没有 src 属性,标签内部必须有 wxs 代码。')
    }
    src = './wxs__' + moduleName
    imports.push({
      ast: parseCode(script.value),
      name: moduleName as string,
      wxs: true
    })
  }

  if (!moduleName || !src) {
    throw new Error('一个 WXS 需要同时存在两个属性:`wxs`, `src`')
  }

  path.remove()

  return {
    module: moduleName,
    src
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:53,代码来源:wxml.ts


示例5: newJSXIfAttr

export function newJSXIfAttr (jsx: t.JSXElement, value: t.Identifier | t.Expression, path?: NodePath<t.JSXElement>) {
  const element = jsx.openingElement
  if (!t.isJSXIdentifier(element.name)) {
    return
  }
  if (element.name.name === 'Block' || element.name.name === 'block' || !path) {
    element.attributes.push(buildJSXAttr(Adapter.if, value))
  } else {
    const block = buildBlockElement()
    newJSXIfAttr(block, value)
    block.children.push(jsx)
    path.node = block
  }
}
开发者ID:topud,项目名称:taro,代码行数:14,代码来源:utils.ts


示例6:

 .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
 })
开发者ID:topud,项目名称:taro,代码行数:19,代码来源:wxml.ts


示例7: setJSXAttr

export function setJSXAttr (
  jsx: t.JSXElement,
  name: string,
  value?: t.StringLiteral | t.JSXExpressionContainer | t.JSXElement,
  path?: NodePath<t.JSXElement>
) {
  const element = jsx.openingElement
  if (!t.isJSXIdentifier(element.name)) {
    return
  }
  if (element.name.name === 'Block' || element.name.name === 'block' || !path) {
    jsx.openingElement.attributes.push(
      t.jSXAttribute(t.jSXIdentifier(name), value)
    )
  } else {
    const block = buildBlockElement()
    setJSXAttr(block, name, value)
    block.children = [jsx]
    path.node = block
  }
}
开发者ID:AlloyTeam,项目名称:Nuclear,代码行数:21,代码来源:jsx.ts


示例8: findMethodName

export function findMethodName (expression: t.Expression): string {
  let methodName
  if (
    t.isIdentifier(expression) ||
    t.isJSXIdentifier(expression)
  ) {
    methodName = expression.name
  } else if (t.isStringLiteral(expression)) {
    methodName = expression.value
  } else if (
    t.isMemberExpression(expression) &&
    t.isIdentifier(expression.property)
  ) {
    const { code } = generate(expression)
    const ids = code.split('.')
    if (ids[0] === 'this' && ids[1] === 'props' && ids[2]) {
      methodName = code.replace('this.props.', '')
    } else {
      methodName = expression.property.name
    }
  } else if (
    t.isCallExpression(expression) &&
    t.isMemberExpression(expression.callee) &&
    t.isIdentifier(expression.callee.object)
  ) {
    methodName = expression.callee.object.name
  } else if (
    t.isCallExpression(expression) &&
    t.isMemberExpression(expression.callee) &&
    t.isMemberExpression(expression.callee.object) &&
    t.isIdentifier(expression.callee.property) &&
    expression.callee.property.name === 'bind' &&
    t.isIdentifier(expression.callee.object.property)
  ) {
    methodName = expression.callee.object.property.name
  } else {
    throw codeFrameError(expression.loc, '当 props 为事件时(props name 以 `on` 开头),只能传入一个 this 作用域下的函数。')
  }
  return methodName
}
开发者ID:topud,项目名称:taro,代码行数:40,代码来源:utils.ts


示例9: traverse

t.assertBinaryExpression(ast, { operator: "*" });

const exp: t.Expression = t.nullLiteral();

// React examples:
// https://github.com/babel/babel/blob/4e50b2d9d9c376cee7a2cbf56553fe5b982ea53c/packages/babel-plugin-transform-react-inline-elements/src/index.js#L61
traverse(ast, {
    JSXElement(path, file) {
        const { node } = path;
        const open = node.openingElement;

        // init
        const type = open.name;

        let newType: t.StringLiteral;
        if (t.isJSXIdentifier(type) && t.react.isCompatTag(type.name)) {
            newType = t.stringLiteral(type.name);
        }

        const args: any[] = [];
        if (node.children.length) {
            const children = t.react.buildChildren(node);
            args.push(
                t.unaryExpression("void", t.numericLiteral(0), true),
                ...children,
            );
        }
    }
});

// TypeScript Types
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:31,代码来源:babel-types-tests.ts


示例10: transform


//.........这里部分代码省略.........
    JSXOpeningElement (path) {
      const { name } = path.node.name as t.JSXIdentifier
      if (name === 'Provider') {
        const modules = path.scope.getAllBindings('module')
        const providerBinding = Object.values(modules).some((m: Binding) => m.identifier.name === 'Provider')
        if (providerBinding) {
          path.node.name = t.jSXIdentifier('View')
          const store = path.node.attributes.find(attr => attr.name.name === 'store')
          if (store && t.isJSXExpressionContainer(store.value) && t.isIdentifier(store.value.expression)) {
            storeName = store.value.expression.name
          }
          path.node.attributes = []
        }
      }

      if (IMAGE_COMPONENTS.has(name)) {
        for (const attr of path.node.attributes) {
          if (
            attr.name.name === 'src'
          ) {
            if (t.isStringLiteral(attr.value)) {
              imageSource.add(attr.value.value)
            } else if (t.isJSXExpressionContainer(attr.value)) {
              if (t.isStringLiteral(attr.value.expression)) {
                imageSource.add(attr.value.expression.value)
              }
            }
          }
        }
      }
    },
    JSXAttribute (path) {
      const { name, value } = path.node
      if (!t.isJSXIdentifier(name) || value === null || t.isStringLiteral(value) || t.isJSXElement(value)) {
        return
      }

      const expr = value.expression as any
      const exprPath = path.get('value.expression')
      if (!t.isBinaryExpression(expr, { operator: '+' }) && !t.isLiteral(expr) && name.name === 'style') {
        const jsxID = path.findParent(p => p.isJSXOpeningElement()).get('name')
        if (jsxID && jsxID.isJSXIdentifier() && DEFAULT_Component_SET.has(jsxID.node.name)) {
          exprPath.replaceWith(
            t.callExpression(t.identifier(INTERNAL_INLINE_STYLE), [expr])
          )
        }
      }

      if (name.name.startsWith('on')) {
        if (exprPath.isReferencedIdentifier()) {
          const ids = [expr.name]
          const fullPath = buildFullPathThisPropsRef(expr, ids, path)
          if (fullPath) {
            exprPath.replaceWith(fullPath)
          }
        }

        if (exprPath.isReferencedMemberExpression()) {
          const id = findFirstIdentifierFromMemberExpression(expr)
          const ids = getIdsFromMemberProps(expr)
          if (t.isIdentifier(id)) {
            const fullPath = buildFullPathThisPropsRef(id, ids, path)
            if (fullPath) {
              exprPath.replaceWith(fullPath)
            }
          }
开发者ID:topud,项目名称:taro,代码行数:67,代码来源:index.ts



注:本文中的babel-types.isJSXIdentifier函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap