本文整理汇总了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;未经允许,请勿转载。 |
请发表评论