How to use the isIdentifier function from @babel/types
Find comprehensive JavaScript @babel/types.isIdentifier code examples handpicked from public code repositorys.
161 162 163 164 165 166 167 168 169 170
if (t.isBinaryExpression(retStmt.argument) && args.length === 2) { _path.replaceWith(t.binaryExpression(retStmt.argument.operator, args[0], args[1])) } else if (t.isLogicalExpression(retStmt.argument) && args.length == 2) { // 逻辑运算 _path.replaceWith(t.logicalExpression(retStmt.argument.operator, args[0], args[1])) } else if (t.isCallExpression(retStmt.argument) && t.isIdentifier(retStmt.argument.callee)) { // 函数调用 _path.replaceWith(t.callExpression(args[0], args.slice(1))) } },
43
73
5
+ 2 other calls in file
GitHub: Ntrashh/BossASTDecode
196 197 198 199 200 201 202 203 204 205
/** * var TEm = 14; while (!![]) { * */ } } else if (switchNode != undefined && types.isIdentifier(switchNode.discriminant)) { lastNode = path.getPrevSibling().node if (types.isVariableDeclaration(lastNode) && lastNode.declarations.length == 1 && lastNode.declarations[0].id.name == switchNode.discriminant.name) { let indexname = lastNode.declarations[0].id.name, index = lastNode.declarations[0].init.value;
6
18
1
+ 2 other calls in file
240 241 242 243 244 245 246 247 248 249
if (_path_binding != binding) //两者绑定对比(可删) return; let _node = _path.node; if (!t.isIdentifier(_node.object) || _node.object.name !== objName) //节点对象type|节点对象名验证 return; if (!(t.isStringLiteral(_node.property) || t.isIdentifier(_node.property))) //节点属性可迭代字符验证|标识符验证 return; if (!(_node.property.value == key || _node.property.name == key)) //节点属性值与名称等于指定值验证 return; if (!t.isStringLiteral(_node.property) || _node.property.value != key) //节点属性可迭代字符判定|节点属性值等于指定值验证
5
14
1
+ 8 other calls in file
440 441 442 443 444 445 446 447 448 449
const exported = ast.program.body[0]; if (t.isExportNamedDeclaration(exported) && t.isVariableDeclaration(exported.declaration) && exported.declaration.declarations.length === 1) { const declaration = exported.declaration.declarations[0]; if (t.isVariableDeclarator(declaration) && t.isIdentifier(declaration.id)) { const { name } = declaration.id; namedExports[name] = declaration.init;
1
2
1
727 728 729 730 731 732 733 734 735 736 737 738
await fs.writeFile(crieTestPath, codeParts.join('\n\n'), 'utf-8') } const isTTestAwaitSomething = path => btypes.isIdentifier(path.node.callee.object, avaTId) && path.node.arguments.length > 0 && (btypes.isAwaitExpression(path.node.arguments[0]) || (btypes.isMemberExpression(path.node.arguments[0]) && btypes.isAwaitExpression(path.node.arguments[0].object)))
0
15
1
+ 10 other calls in file
96 97 98 99 100 101 102 103 104 105
{ AssignmentExpression: (path) => { const { node } = path; if ( t.isIdentifier(node.left) && node.left.name === binding.identifier.name ) { resultPath = path; path.stop();
0
6
1
+ 184 other calls in file
207 208 209 210 211 212 213 214 215 216
function processArgument(argumentPath, statement) { if ( (statement && (t.isCallExpression(argumentPath.node) || t.isNewExpression(argumentPath.node) || t.isIdentifier(argumentPath.node))) || t.isMemberExpression(argumentPath.node) || t.isLiteral(argumentPath.node) || t.isObjectExpression(argumentPath.node) || t.isFunction(argumentPath.node) ||
0
3
3
+ 28 other calls in file
275 276 277 278 279 280 281 282 283 284
else if (t.isLogicalExpression(retStmt.argument) && args.length === 2)//与二元运算一样 { _path.replaceWith(t.logicalExpression(retStmt.argument.operator, args[0], args[1])); } // 函数调用 else if (t.isCallExpression(retStmt.argument) && t.isIdentifier(retStmt.argument.callee))//回调函数表达式判定及回调参数部分判定 { _path.replaceWith(t.callExpression(args[0], args.slice(1))) } paths_sums += 1;//删除计数标志
0
2
1
+ 44 other calls in file
325 326 327 328 329 330 331 332 333 334
if (!moduleBinding) { state.isCJS = true; return; } } else if ( t.isIdentifier(path.node.left.object) && path.node.left.object.name === "module" ) { if (!moduleBinding) { state.isCJS = true;
0
1
1
+ 117 other calls in file
217 218 219 220 221 222 223 224 225 226
EXPORTS: meta.exportName, EXPORT_NAME: exportName, NAMESPACE_IMPORT }; if (constantReexports || t.isIdentifier(NAMESPACE_IMPORT)) { if (stringSpecifiers.has(exportName)) { return ReexportTemplate.constantComputed(astNodes); } else { return ReexportTemplate.constant(astNodes);
0
1
1
+ 21 other calls in file
664 665 666 667 668 669 670 671 672
if ( path.node.returnType && t.isTSTypeReference(path.node.returnType.typeAnnotation) && t.isTSQualifiedName(path.node.returnType.typeAnnotation.typeName) && t.isIdentifier(path.node.returnType.typeAnnotation.typeName.left, {name: 'JSX'}) && t.isIdentifier(path.node.returnType.typeAnnotation.typeName.right, {name: 'Element'}) ) { return true; }
670
0
66
+ 107 other calls in file
265 266 267 268 269 270 271 272 273 274
callPath.scope.crawl(); } else if (types.isLogicalExpression(returnStatement) && nodeArguments.length === 2) { // 逻辑计算表达式 callPath.replaceInline(types.logicalExpression(returnStatement.operator, nodeArguments[0], nodeArguments[1])); callPath.scope.crawl(); } else if (types.isCallExpression(returnStatement) && types.isIdentifier(returnStatement.callee)) { // 函数调用 // if (nodeArguments.length == 1) { // referencePath.replaceWith(nodeArguments[0]) // } else {
1
0
1
+ 165 other calls in file
658 659 660 661 662 663 664 665 666 667
if (!t.isMemberExpression(callee)) { return calleePath.referencesImport(module, name); } if (calleePath.get('object').referencesImport(module, 'default')) { return t.isIdentifier(callee.property, {name}); } return false; }
680
0
66
+ 1385 other calls in file
166 167 168 169 170 171 172 173 174 175
try { // 如果解密函数中有变量参数 则不替换 let argumentList = p.parentPath.node.arguments // 实参中如果有变量则直接跳出不替换 let hasIdentifier = argumentList.some((a) => t.isIdentifier(a)) if (hasIdentifier) return let callCode = p.parentPath.toString() let decStr = eval(callCode)
43
79
5
+ 3 other calls in file
66 67 68 69 70 71 72 73 74 75
return { args: node.params.map(getArgument), type: 'function', }; case types.isIdentifier(node): try { return createDescriptor({ node: await findIdentifierNode({ name: node.name, ast, cwd }), ast,
2
11
222
+ 7 other calls in file
120 121 122 123 124 125 126 127 128 129
let updateFn; if (t.isArrayPattern(defineVarId.node)) { prevState = defineVarId.node.elements[0]; updateFn = defineVarId.node.elements[1]; canMerge = t.isIdentifier(prevState); } else if (t.isObjectPattern(defineVarId.node)) { const find = defineVarId.node.properties.find((n) => t.isNumericLiteral(n.key) && n.key.value === 1); if (find) { prevState = defineVarId.node.properties.find((n) => t.isNumericLiteral(n.key) && n.key.value === 0).value;
13
10
0
+ 7 other calls in file
GitHub: omarjuice/algo-viz
72 73 74 75 76 77 78 79 80 81
path.get("params").forEach(traverseParameters(path, params)) const isClassMethod = t.isClassMethod(path.node) let funcName; if (path.node.id) { funcName = path.node.id.name } else if (t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id)) { funcName = path.parent.id.name } else if (t.isObjectProperty(path.parent) && !path.parent.computed) { funcName = 'method:' + path.parent.key.name } else if (t.isCallExpression(path.parent) || t.isNewExpression(path.parent)) {
4
26
1
+ 21 other calls in file
8 9 10 11 12 13 14 15 16 17
function isModuleExport(node) { if (t.isMemberExpression(node)) { return ( t.isIdentifier(node.object) && node.object.name === 'module' && t.isIdentifier(node.property) && node.property.name === 'exports' ); } return false;
1
5
0
+ 3 other calls in file
40 41 42 43 44 45 46 47 48 49
if (t.isExpressionStatement(item)) { const expressionNode = item.expression; if (importDefaultSpecifier && t.isMemberExpression(expressionNode.callee) && t.isIdentifier(expressionNode.callee.object, { name: 'ReactDOM' }) && t.isIdentifier(expressionNode.callee.property, { name: 'render' })) { return item; } else if (importSpecifier && t.isIdentifier(expressionNode.callee, { name: 'render' })) { return item; }
3
3
11
+ 5 other calls in file
152 153 154 155 156 157 158 159 160 161
var {body} = path.node; var node = body.find(node => ( t.isVariableDeclaration(node) && (node = node.declarations[0]) && t.isIdentifier(node.id) && node.id.name === 'requireJSX' )); if (!node) return;
2
33
2
+ 67 other calls in file
@babel/types.identifier is the most popular function in @babel/types (20936 examples)