当前位置: 首页>>代码示例>>TypeScript>>正文


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

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


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

示例1: resetTSClassProperty

export function resetTSClassProperty (body) {
  for (const method of body) {
    if (t.isClassMethod(method) && method.kind === 'constructor') {
      for (const statement of cloneDeep(method.body.body)) {
        if (t.isExpressionStatement(statement) && t.isAssignmentExpression(statement.expression)) {
          const expr = statement.expression
          const { left, right } = expr
          if (
            t.isMemberExpression(left) &&
              t.isThisExpression(left.object) &&
              t.isIdentifier(left.property)
          ) {
            if (
              (t.isArrowFunctionExpression(right) || t.isFunctionExpression(right)) ||
                (left.property.name === 'config' && t.isObjectExpression(right))
            ) {
              body.push(
                t.classProperty(left.property, right)
              )
              remove(method.body.body, statement)
            }
          }
        }
      }
    }
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:27,代码来源:helper.ts

示例2: isDerivedFromProps

export function isDerivedFromProps (scope: Scope, bindingName: string) {
  const binding = scope.getBinding(bindingName)
  if (binding && binding.path.isVariableDeclarator()) {
    const init = binding.path.get('init')
    if (init.isMemberExpression()) {
      const { object, property } = init.node
      if (t.isThisExpression(object) && t.isIdentifier(property, { name: 'props' })) {
        return true
      }
    }
  }
  return false
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:13,代码来源:utils.ts

示例3: getArgumentName

export function getArgumentName (arg) {
  if (t.isThisExpression(arg)) {
    return 'this'
  } else if (t.isNullLiteral(arg)) {
    return 'null'
  } else if (t.isStringLiteral(arg) || t.isNumericLiteral(arg)) {
    return arg.value
  } else if (t.isIdentifier(arg)) {
    return arg.name
  } else {
    return generate(arg).code
  }
  throw new Error(`bind 不支持传入该参数: ${arg}`)
}
开发者ID:topud,项目名称:taro,代码行数:14,代码来源:utils.ts

示例4: getIdsFromMemberProps

function getIdsFromMemberProps (member: t.MemberExpression) {
  let ids: string[] = []
  const { object, property } = member
  if (t.isMemberExpression(object)) {
    ids = ids.concat(getIdsFromMemberProps(object))
  }
  if (t.isThisExpression(object)) {
    ids.push('this')
  }
  if (t.isIdentifier(object)) {
    ids.push(object.name)
  }
  if (t.isIdentifier(property)) {
    ids.push(property.name)
  }
  return ids
}
开发者ID:topud,项目名称:taro,代码行数:17,代码来源:index.ts

示例5: handleThirdPartyComponent

 method.body.body = method.body.body.filter(statement => {
   if (t.isExpressionStatement(statement) && t.isAssignmentExpression(statement.expression)) {
     const expr = statement.expression
     const { left, right } = expr
     if (
       t.isMemberExpression(left) &&
       t.isThisExpression(left.object) &&
       t.isIdentifier(left.property)
     ) {
       if (
         (t.isArrowFunctionExpression(right) || t.isFunctionExpression(right))
         ||
         (left.property.name === 'config' && t.isObjectExpression(right))
       ) {
         const classProp = t.classProperty(left.property, right)
         body.push(classProp)
         handleThirdPartyComponent(classProp)
         return false
       }
     }
   }
   return true
 })
开发者ID:topud,项目名称:taro,代码行数:23,代码来源:index.ts

示例6: parseAttribute

function parseAttribute (attr: Attribute) {
  let { key, value } = attr
  let jsxValue: null | t.JSXExpressionContainer | t.StringLiteral = null
  if (value) {
    if (key === 'class' && value.startsWith('[') && value.endsWith(']')) {
      value = value.slice(1, value.length - 1).replace(',', '')
      // tslint:disable-next-line
      console.log(codeFrameError(attr, 'Taro/React 不支持 class 传入数组,此写法可能无法得到正确的 class'))
    }
    const { type, content } = parseContent(value)

    if (type === 'raw') {
      jsxValue = t.stringLiteral(content)
    } else {
      let expr: t.Expression
      try {
        expr = buildTemplate(content)
      } catch (error) {
        const pureContent = content.slice(1, content.length - 1)
        if (reserveKeyWords.has(pureContent) && type !== 'raw') {
          const err = `转换模板参数: \`${key}: ${value}\` 报错: \`${pureContent}\` 是 JavaScript 保留字,请不要使用它作为值。`
          if (key === WX_KEY) {
            expr = t.stringLiteral('')
          } else {
            throw new Error(err)
          }
        } else if (content.includes(':')) {
          const [ key, value ] = pureContent.split(':')
          expr = t.objectExpression([t.objectProperty(t.stringLiteral(key), parseExpression(value))])
        } else if (content.includes('...') && content.includes(',')) {
          const objExpr = content.slice(1, content.length - 1).split(',')
          const props: (t.SpreadProperty | t.ObjectProperty)[] = []
          for (const str of objExpr) {
            const s = str.trim()
            if (s.includes('...')) {
              props.push(t.spreadProperty(t.identifier(s.slice(3))))
            } else {
              props.push(t.objectProperty(t.identifier(s), t.identifier(s)))
            }
          }
          expr = t.objectExpression(props)
        } else {
          const err = `转换模板参数: \`${key}: ${value}\` 报错`
          throw new Error(err)
        }
      }
      if (t.isThisExpression(expr)) {
        // tslint:disable-next-line
        console.error('在参数中使用 `this` 可能会造成意想不到的结果,已将此参数修改为 `__placeholder__`,你可以在转换后的代码查找这个关键字修改。')
        expr = t.stringLiteral('__placeholder__')
      }
      jsxValue = t.jSXExpressionContainer(expr)
    }
  }

  const jsxKey = handleAttrKey(key)
  if (/^on[A-Z]/.test(jsxKey) && jsxValue && t.isStringLiteral(jsxValue)) {
    jsxValue = t.jSXExpressionContainer(
      t.memberExpression(t.thisExpression(), t.identifier(jsxValue.value))
    )
  }

  if (key.startsWith('catch') && value && value === 'true') {
    jsxValue = t.jSXExpressionContainer(
      t.memberExpression(t.thisExpression(), t.identifier('privateStopNoop'))
    )
    globals.hasCatchTrue = true
  }
  return t.jSXAttribute(t.jSXIdentifier(jsxKey), jsxValue)
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:70,代码来源:wxml.ts

示例7:

 const isArrowFunctionInJSX = path.findParent(p => p.isJSXAttribute() ||
   (
     p.isAssignmentExpression() && t.isMemberExpression(p.node.left) && t.isThisExpression(p.node.left.object)
       && t.isIdentifier(p.node.left.property) && p.node.left.property.name.startsWith('')
   )
开发者ID:YangShaoQun,项目名称:taro,代码行数:5,代码来源:utils.ts


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