How to use the isCallExpression function from @babel/types
Find comprehensive JavaScript @babel/types.isCallExpression code examples handpicked from public code repositorys.
@babel/types.isCallExpression is a function in the Babel Types package that checks if a node in an Abstract Syntax Tree (AST) represents a call expression.
16 17 18 19 20 21 22 23 24
const chainedRegular = 4; function match(path, ctx, explicitOnly) { const node = path.node; const isMethodCall = ( t.isCallExpression(node) && t.isMemberExpression(node.callee) && node.callee.computed === false );
GitHub: baidu/wx2
75 76 77 78 79 80 81 82 83 84
}; function isAopBlock(path, block, AOP, cb) { t.isExpressionStatement(block) && t.isCallExpression(block.expression) && t.isMemberExpression(get(block, 'expression.callee')) && get(block, 'expression.callee.property.name') === 'after' && cb(path, block, AOP); }
+ 7 other calls in file
How does @babel/types.isCallExpression work?
@babel/types.isCallExpression is a function in the @babel/types package that takes a node object as input and checks whether it represents a CallExpression node in an Abstract Syntax Tree (AST) by comparing its type with the CallExpression node type.
1 2 3 4 5 6 7 8 9 10
var moduleDetails = require('./get-module-function'); var nodeResolve = require('resolve'); var browserResolve = require('browser-resolve'); function isRequireResolve (path) { return t.isCallExpression(path.node) && t.isMemberExpression(path.node.callee) && path.node.callee.object.name === 'require' && path.node.callee.property.name === 'resolve'; }
+ 19 other calls in file
GitHub: yandex/reselector
126 127 128 129 130 131 132 133 134 135
return argsMap.get(componentNode) } } const isExtended = props => ( t.isCallExpression(props) && (props.callee.name === '_extends' || props.callee.name === '_objectSpread') ) module.exports = () => { const addDataProp = createAddDataProp()
+ 9 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9
const t = require("@babel/types"); const node = t.callExpression(t.identifier("foo"), [t.stringLiteral("bar")]); if (t.isCallExpression(node)) { console.log("Node is a CallExpression!"); } else { console.log("Node is not a CallExpression!"); }
In this example, the t.isCallExpression function checks whether the node variable is a CallExpression, which it is. If it were not, the else branch would execute instead.
GitHub: yandex/reselector
45 46 47 48 49 50 51 52 53 54
const isReturned = (p) => { const { parent } = p if ( t.isCallExpression(parent) || t.isConditionalExpression(parent) || t.isSequenceExpression(parent) || t.isLogicalExpression(parent) ) {
+ 17 other calls in file
GitHub: 94cstyles/rax
213 214 215 216 217 218 219
`Only EventHandlers are supported in Mini Program, eg: onClick/onChange, instead of "${attributeName}".`, ); const callExp = expression.body; const args = callExp.arguments; const { attributes } = parentPath.parentPath.node; const fnExpression = t.isCallExpression(callExp) ? callExp.callee : expression; const name = dynamicEvents.add({
+ 3 other calls in file
GitHub: msojocs/wcc.js
197 198 199 200 201 202 203 204 205 206
* 1. 对象成员访问 var a = this.x; * 2. 函数调用参数 console.log(a, b, c, this) * 合法的场景,需要把this替换为(this.constructor === Window ? {} : this) */ if (path.isThisExpression()) { if (!(babelTypes.isMemberExpression(path.parent) || babelTypes.isCallExpression(path.parent))) { let message = `${filePath}:${path.node.loc.start.line + startLine - 1}:${path.node.loc.start.column}: SyntaxError: invalid usage of identifier \`this\`\n`; wccError = new error.WccError(error.CODE.INVALID_THIS, message); path.stop(); return;
+ 5 other calls in file
113 114 115 116 117 118 119 120 121 122
return { moduleName, bindings: [] }; } function isRequire(declarator) { return ( t.isCallExpression(declarator.init) && t.isIdentifier(declarator.init.callee) && declarator.init.callee.name === 'require' ); } module.exports = {
93 94 95 96 97 98 99 100 101 102
}; case isValue(node): return { type: 'value' }; case types.isCallExpression(node): return createDescriptor({ node: await getReturnValue({ node: node.callee, ast, cwd }), ast, cwd,
+ 7 other calls in file
15 16 17 18 19 20 21 22 23 24
}); }, ExpressionStatement(path) { const expression = path.node.expression; if ( t.isCallExpression(expression) && !t.isThisExpression(expression.callee.object) ) { path.traverse( {
97 98 99 100 101 102 103 104 105 106
} else if ( t.isLogicalExpression(path.node.init) ){ // No handling for ^^ right now } else if ( t.isObjectExpression(path.node.init) ) { // No handling for ^^ right now - i think this is fine generally actually - if objects // are being built up, leaving this will be clearer } else if ( t.isCallExpression(path.node.init) ) { // No handling for ^^ right now // One example is var U2 = document.createElement("canvas"); // could be good to make that clearer later } else if ( t.isMemberExpression(path.node.init) ){
276 277 278 279 280 281 282 283 284 285
t.isMemberExpression(node.left) && (node.left.property.value || node.left.property.name) && node.right.body.body.length === 1 && t.isReturnStatement(node.right.body.body[0]) && (t.isBinaryExpression(node.right.body.body[0].argument) || t.isCallExpression(node.right.body.body[0].argument)) ) { // We find proxy function and fill in scopeIdToBinaryOpPath(scopeUID -> Map<key, pathToBinaryNode>). // Key is created using the ID name and the property value(n['xyz'] = function ... -> key = n_xyz). // In this way we get a structure where each scope is mapped to a bindings.
+ 36 other calls in file
8 9 10 11 12 13 14 15 16 17
/** * todo text解析模板都在js里面处理,在js里去合并?统一babel parse入口 */ function prevent$tRecursive(fn) { return (path) => { if (path.parent && t.isCallExpression(path.parent) && t.isIdentifier(path.parent.callee, { name: '$t' })) { const firstArgNode = path.parent.arguments[0]; if (firstArgNode.type === 'StringLiteral') { addI18nKeys(firstArgNode.value); } else if (firstArgNode.type === 'TemplateLiteral') {
93 94 95 96 97 98 99 100 101 102
const parentNode = thisPath.parentPath.parentPath.parent; const isValid = t.isExpressionStatement(parentNode) || t.isVariableDeclaration(parentNode) || t.isBlockStatement(parentNode) || t.isJSXElement(parentNode) || t.isCallExpression(parentNode) || (t.isJSXAttribute(parentNode) && !parentNode.name.name.startsWith('on')); if (isValid) { // prop
GitHub: dangolbeeker/fbt
261 262 263 264 265 266 267 268 269 270
/** * Returns the Babel node from this FbtNode only if it's a BabelNodeCallExpression */ getCallNode(): ?BabelNodeCallExpression { return isCallExpression(this.node) ? this.node : null; } /** * Returns the list of BabelNode arguments of this fbt node
251 252 253 254 255 256 257 258 259 260
referencePath.replaceInline(variableValue); } catch (e) { debugger } referencePath.scope.crawl(); } else if (types.isFunction(variableValue) && types.isCallExpression(referencePath.parentPath)) { // 函数里的表达式只有一个return, 直接替换 const callPath = referencePath.parentPath; const returnStatement = variableValue.body.body[0].argument; const nodeArguments = callPath.node.arguments;
+ 82 other calls in file
89 90 91 92 93 94 95 96 97 98
if (t.isStringLiteral(node) || t.isPlaceholder(node, { expectedNode: "StringLiteral" })) { type = "string"; } else if (t.isNewExpression(parent) && key === "arguments" || t.isCallExpression(parent) && key === "arguments" || t.isFunction(parent) && key === "params") { type = "param"; } else if (t.isExpressionStatement(parent) && !t.isPlaceholder(node)) { type = "statement"; ancestors = ancestors.slice(0, -1);
+ 26 other calls in file
450 451 452 453 454 455 456 457 458 459
} } const children = traverseExpr(forReturnStatementArgument, state) // 支付宝小程序在 block 标签上使用 key 时顺序不能保障 if (state.options.platform.name === 'mp-alipay' && t.isCallExpression(forReturnStatementArgument) && children && children.type) { children.attr = children.attr || {} Object.assign(children.attr, attr) return children
+ 11 other calls in file
229 230 231 232 233 234 235 236 237 238
} } break } } else if ( t.isCallExpression(callee) && t.isIdentifier(callee.callee) && callee.callee.name === METHOD_RESOLVE_FILTER ) { // multi filter
277 278 279 280 281 282 283 284 285 286 287 288
const isExpect = path => btypes.isMemberExpression(path.node.callee) && btypes.isIdentifier(path.node.callee.object.callee, isIdExpectOpts) const isRequire = declaration => btypes.isCallExpression(declaration.init) && declaration.init.callee.name === 'require' const argZeroEquals = (args, shouldEq) => args ? args[0].value === shouldEq : false
+ 4 other calls in file
@babel/types.identifier is the most popular function in @babel/types (20936 examples)