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

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

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

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



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

示例1: matchesCallExpression

export function matchesCallExpression(
    expression: babel.MemberExpression, path: string[]): boolean {
  if (!expression.property || !expression.object) {
    return false;
  }
  console.assert(path.length >= 2);

  if (!babel.isIdentifier(expression.property)) {
    return false;
  }
  // Unravel backwards, make sure properties match each step of the way.
  if (expression.property.name !== path[path.length - 1]) {
    return false;
  }
  // We've got ourselves a final member expression.
  if (path.length === 2 && babel.isIdentifier(expression.object)) {
    return expression.object.name === path[0];
  }
  // Nested expressions.
  if (path.length > 2 && babel.isMemberExpression(expression.object)) {
    return matchesCallExpression(
        expression.object, path.slice(0, path.length - 1));
  }

  return false;
}
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:26,代码来源:esutil.ts


示例2: if

 .forEach(prop => {
   if (t.isObjectProperty(prop)) {
     let propKey: string | null = null
     if (t.isStringLiteral(prop.key)) {
       propKey = prop.key.value
     }
     if (t.isIdentifier(prop.key)) {
       propKey = prop.key.name
       // propsKeys.push(prop.key.name)
     }
     if (t.isObjectExpression(prop.value) && propKey) {
       for (const p of prop.value.properties) {
         if (t.isObjectProperty(p)) {
           let key: string | null = null
           if (t.isStringLiteral(p.key)) {
             key = p.key.value
           }
           if (t.isIdentifier(p.key)) {
             key = p.key.name
           }
           if (key === 'value') {
             defaultProps.push({
               name: propKey,
               value: p.value
             })
           } else if (key === 'observer') {
             observeProps.push({
               name: propKey,
               observer: p.value
             })
           }
           if (!isValidVarName(propKey)) {
             throw codeFrameError(prop, `${propKey} 不是一个合法的 JavaScript 变量名`)
           }
         }
         if (t.isObjectMethod(p) && t.isIdentifier(p.key, { name: 'observer' })) {
           observeProps.push({
             name: propKey,
             observer: t.arrowFunctionExpression(p.params, p.body, p.async)
           })
         }
       }
     }
     if (propKey) {
       propsKeys.push(propKey)
     }
   }
 })
开发者ID:YangShaoQun,项目名称:taro,代码行数:48,代码来源:script.ts


示例3: getSuperClassCode

export function getSuperClassCode (path: NodePath<t.ClassDeclaration>) {
  const superClass = path.node.superClass
  if (t.isIdentifier(superClass)) {
    const binding = path.scope.getBinding(superClass.name)
    if (binding && binding.kind === 'module') {
      const bindingPath = binding.path.parentPath
      if (bindingPath.isImportDeclaration()) {
        const source = bindingPath.node.source
        if (source.value === TARO_PACKAGE_NAME) {
          return
        }
        try {
          const p = pathResolver(source.value, transformOptions.sourcePath) + (transformOptions.isTyped ? '.tsx' : '.js')
          const code = fs.readFileSync(p, 'utf8')
          return {
            code,
            sourcePath: source.value
          }
        } catch (error) {
          return
        }
      }
    }
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:25,代码来源:utils.ts


示例4: 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


示例5: 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


示例6:

export const getObjKey = (node) => {
  if (t.isIdentifier(node)) {
    return node.name
  } else {
    return node.value
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:7,代码来源:astConvert.ts


示例7: handleClosureJSXFunc

function handleClosureJSXFunc (jsx: NodePath<t.JSXElement>, mainClass: NodePath<t.ClassDeclaration>) {
  // 在 ./functional.ts 会把 FunctionExpression 转化为 arrowFunctionExpr
  // 所以我们这里只处理一种情况
  const arrowFunc = jsx.findParent(p => p.isArrowFunctionExpression())
  if (arrowFunc && arrowFunc.isArrowFunctionExpression()) {
    const parentPath = arrowFunc.parentPath
    if (parentPath.isVariableDeclarator()) {
      const id = parentPath.node.id
      if (t.isIdentifier(id) && id.name.startsWith('render')) {
        const funcName = `renderClosure${id.name.slice(6, id.name.length)}`
        mainClass.node.body.body.push(
          t.classProperty(
            t.identifier(funcName),
            cloneDeep(arrowFunc.node)
          )
        )
        parentPath.scope.rename(id.name, funcName)
        arrowFunc.replaceWith(t.memberExpression(
          t.thisExpression(),
          t.identifier(funcName)
        ))
      }
    }
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:25,代码来源:index.ts


示例8: template

 VariableDeclarator: (path) => {
   const { id, init } = path.node
   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('')
     )
   )
   if (isArrowFunctionInJSX) {
     return
   }
   if (t.isIdentifier(id) && !id.name.startsWith(LOOP_STATE)) {
     const newId = scope.generateDeclaredUidIdentifier('$' + id.name)
     refIds.forEach((refId) => {
       if (refId.name === variableName && !variableName.startsWith('_$')) {
         refIds.delete(refId)
       }
     })
     variableName = newId.name
     if (Adapter.type === Adapters.quickapp && variableName.startsWith('_$')) {
       const newVarName = variableName.slice(2)
       scope.rename(variableName, newVarName)
       variableName = newVarName
     }
     refIds.add(t.identifier(variableName))
     blockStatement.scope.rename(id.name, newId.name)
     path.parentPath.replaceWith(
       template('ID = INIT;')({ ID: newId, INIT: init })
     )
   }
 }
开发者ID:YangShaoQun,项目名称:taro,代码行数:31,代码来源:utils.ts


示例9: 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


示例10: if

    scannedMethod.params = (value.params || []).map((nodeParam) => {
      let name;
      let defaultValue;
      let rest;

      if (babel.isIdentifier(nodeParam)) {
        // Basic parameter: method(param)
        name = nodeParam.name;

      } else if (
          babel.isRestElement(nodeParam) &&
          babel.isIdentifier(nodeParam.argument)) {
        // Rest parameter: method(...param)
        name = nodeParam.argument.name;
        rest = true;

      } else if (
          babel.isAssignmentPattern(nodeParam) &&
          babel.isIdentifier(nodeParam.left) &&
          babel.isLiteral(nodeParam.right)) {
        // Parameter with a default: method(param = "default")
        name = nodeParam.left.name;
        defaultValue = generate(nodeParam.right).code;

      } else {
        // Some AST pattern we don't recognize. Hope the code generator does
        // something reasonable.
        name = generate(nodeParam).code;
      }

      let type;
      let description;
      const tag = paramTags.get(name);
      if (tag) {
        if (tag.type) {
          type = doctrine.type.stringify(tag.type);
        }
        if (tag.description) {
          description = tag.description;
        }
      }

      const param: MethodParam = {name, type, defaultValue, rest, description};
      return param;
    });
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:45,代码来源:esutil.ts



注:本文中的babel-types.isIdentifier函数示例由纯净天空整理自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