本文整理汇总了TypeScript中babel-types.isAssignmentExpression函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isAssignmentExpression函数的具体用法?TypeScript isAssignmentExpression怎么用?TypeScript isAssignmentExpression使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isAssignmentExpression函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
}
}
}
}
}
}
示例2: 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
})
示例3: parseLoopBody
//.........这里部分代码省略.........
t.stringLiteral('__item')
)
}
if (t.isIdentifier(index)) {
setJSXAttr(
jsxElementPath.node,
Adapter.forIndex,
t.stringLiteral(index.name)
)
loopScopes.add(index.name)
}
caller.replaceWith(jsxElementPath.node)
if (statementParent) {
const name = findIdentifierFromStatement(
statementParent.node as t.VariableDeclaration
)
// setTemplate(name, path, templates)
name && templates.set(name, jsxElementPath.node)
}
}
}
}
} else {
const ifStatement = parentPath.findParent(p => p.isIfStatement())
const blockStatement = parentPath.findParent(p => p.isBlockStatement())
const block = finalReturnElement || buildBlockElement()
if (isBlockIfStatement(ifStatement, blockStatement)) {
const { test, alternate, consequent } = ifStatement.node
if (alternate === blockStatement.node) {
throw codeFrameError(parentNode.loc, '不必要的 else 分支,请遵从 ESLint consistent-return: https://eslint.org/docs/rules/consistent-return')
} else if (consequent === blockStatement.node) {
const parentIfStatement = ifStatement.findParent(p => p.isIfStatement())
if (parentIfStatement) {
setJSXAttr(
jsxElementPath.node,
Adapter.elseif,
t.jSXExpressionContainer(test)
)
} else {
newJSXIfAttr(jsxElementPath.node, test)
}
}
} else if (block.children.length !== 0) {
setJSXAttr(jsxElementPath.node, Adapter.else)
}
block.children.push(jsxElementPath.node)
finalReturnElement = block
returnedPaths.push(parentPath)
}
} else if (t.isArrowFunctionExpression(parentNode)) {
//
} else if (t.isAssignmentExpression(parentNode)) {
if (t.isIdentifier(parentNode.left)) {
const name = parentNode.left.name
const bindingNode = bodyScope.getOwnBinding(name)!.path.node
const block = templates.get(name) || buildBlockElement()
if (isEmptyDeclarator(bindingNode)) {
const ifStatement = parentPath.findParent(p => p.isIfStatement())
const blockStatement = parentPath.findParent(p =>
p.isBlockStatement()
)
if (isBlockIfStatement(ifStatement, blockStatement)) {
const { test, alternate, consequent } = ifStatement.node
if (alternate === blockStatement.node) {
setJSXAttr(jsxElementPath.node, Adapter.else)
} else if (consequent === blockStatement.node) {
const parentIfStatement = ifStatement.findParent(p =>
p.isIfStatement()
) as NodePath<t.IfStatement>
if (parentIfStatement && parentIfStatement.get('alternate') === ifStatement) {
setJSXAttr(
jsxElementPath.node,
Adapter.elseif,
t.jSXExpressionContainer(test)
)
} else {
if (parentIfStatement) {
newJSXIfAttr(block, parentIfStatement.node.test)
}
newJSXIfAttr(jsxElementPath.node, test)
}
}
block.children.push(jsxElementPath.node)
// setTemplate(name, path, templates)
name && templates.set(name, block)
}
} else {
throw codeFrameError(
jsxElementPath.node.loc,
'请将 JSX 赋值表达式初始化为 null,然后再进行 if 条件表达式赋值。'
)
}
}
} else if (!t.isJSXElement(parentNode)) {
// throwError(path, '考虑只对 JSX 元素赋值一次。')
}
}
}
})
}