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


TypeScript babel-types.isMemberExpression函數代碼示例

本文整理匯總了TypeScript中babel-types.isMemberExpression函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isMemberExpression函數的具體用法?TypeScript isMemberExpression怎麽用?TypeScript isMemberExpression使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了isMemberExpression函數的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: 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

示例3: findFirstIdentifierFromMemberExpression

export function findFirstIdentifierFromMemberExpression (node: t.MemberExpression): t.Identifier {
  let id
  let object = node.object as any
  while (true) {
    if (t.identifier(object) && !t.isMemberExpression(object)) {
      id = object
      break
    }
    object = object.object
  }
  return id
}
開發者ID:ApolloRobot,項目名稱:taro,代碼行數:12,代碼來源:utils.ts

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

示例5: objectKeyToString

export function objectKeyToString(key: babel.Node): string|undefined {
  if (babel.isIdentifier(key)) {
    return key.name;
  }
  if (babel.isLiteral(key)) {
    return '' + astValue.expressionToValue(key);
  }
  if (babel.isMemberExpression(key)) {
    return objectKeyToString(key.object) + '.' +
        objectKeyToString(key.property);
  }
  return undefined;
}
開發者ID:asdfg9822,項目名稱:polymer-analyzer,代碼行數:13,代碼來源:esutil.ts

示例6: getArgumentName

export function getArgumentName (arg) {
  if (t.isThisExpression(arg)) {
    return 'this'
  } else if (t.isNullLiteral(arg)) {
    return 'null'
  } else if (t.isStringLiteral(arg)) {
    return arg.value
  } else if (t.isIdentifier(arg)) {
    return arg.name
  } else if (t.isMemberExpression(arg)) {
    return generate(arg).code
  }
  throw new Error(`bind 不支持傳入該參數: ${arg}`)
}
開發者ID:teachat8,項目名稱:taro,代碼行數:14,代碼來源:utils.ts

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

示例8: findParentLoops

export function findParentLoops (
  callee: NodePath<t.CallExpression>,
  names: Map<NodePath<t.CallExpression>, string>,
  loops: t.ArrayExpression
) {
  let indexId: t.Identifier | null = null
  let name: string | undefined
  const [ func ] = callee.node.arguments
  if (t.isFunctionExpression(func) || t.isArrowFunctionExpression(func)) {
    const params = func.params as t.Identifier[]
    indexId = params[1]
    name = names.get(callee)
  }

  if (indexId === null || !t.isIdentifier(indexId)) {
    indexId = t.identifier(callee.scope.generateUid('anonIdx'));
    (func as any).params = [(func as any).params[0], indexId]
  }

  if (!name) {
    throw codeFrameError(callee.node, '找不到循環對應的名稱')
  }

  loops.elements.unshift(t.objectExpression([
    t.objectProperty(t.identifier('indexId'), indexId),
    t.objectProperty(t.identifier('name'), t.stringLiteral(name))
  ]))

  const parentCallExpr = callee.findParent(p => p.isCallExpression())
  if (parentCallExpr && parentCallExpr.isCallExpression()) {
    const callee = parentCallExpr.node.callee
    if (
      t.isMemberExpression(callee) &&
      t.isIdentifier(callee.property) &&
      callee.property.name === 'map'
    ) {
      findParentLoops(parentCallExpr, names, loops)
    }
  }
}
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:40,代碼來源:utils.ts

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

示例10: it

it('should leave other apis untouched', function () {
  const code = `
    import Taro from '@tarojs/taro-h5'
    Taro.noop
  `
  const result = babel.transform(code, { plugins: [pluginOptions] })
  expect(result.code).toMatchSnapshot();

  const ast = result.ast as t.File
  const body = ast.program.body as [t.ImportDeclaration, t.ExpressionStatement]
  expect(t.isImportDeclaration(body[0])).toBeTruthy()
  expect(t.isExpressionStatement(body[1])).toBeTruthy()
  const defaultImport = body[0].specifiers.find(v => t.isImportDefaultSpecifier(v))
  expect(defaultImport).toBeTruthy()

  const taroName = defaultImport!.local.name
  const namedImports = getNamedImports(body[0].specifiers)
  expect(namedImports).toEqual(new Set())
  expect(t.isMemberExpression(body[1].expression)).toBeTruthy()
  expect((body[1].expression as t.MemberExpression)).toMatchObject(t.memberExpression(
    t.identifier(taroName),
    t.identifier('noop')
  ))
})
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:24,代碼來源:index-test.ts


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