How to use the isVariableDeclaration function from babel-types
Find comprehensive JavaScript babel-types.isVariableDeclaration code examples handpicked from public code repositorys.
89 90 91 92 93 94 95 96 97 98
} path.traverse({ ThisExpression (thisPath) { 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'));
64
411
8
49 50 51 52 53 54 55 56 57 58
} } } continue; } else if ( t.isVariableDeclaration(binding.path.parent) && binding.path.parent.kind === 'const' ) { // pick out the right variable declarator const dec = binding.path.parent.declarations.find(
62
0
2
176 177 178 179 180 181 182 183 184 185
} // if we see `var foo = require('bar')` we can just inline the variable // representing `require('bar')` wherever `foo` was used. if ( t.isVariableDeclaration(path.node) && path.node.declarations.length === 1 && t.isIdentifier(path.node.declarations[0].id) && (r = getRequireValue(path.node.declarations[0].init, file)) ) {
59
89
10
+ 25 other calls in file
15 16 17 18 19 20 21 22 23 24
bodyPath.node.specifiers.length === 1 && isJSSThemeReactorImport(bodyPath.get('specifiers')[0]) ) { bodyPath.remove(); } else if ( t.isVariableDeclaration(bodyPath.node) && bodyPath.node.declarations.length === 1 && isJSSThemeReactorRequire(bodyPath.node.declarations[0].init) ) { bodyPath.remove();
12
28
5
+ 13 other calls in file
98 99 100 101 102 103 104 105 106 107
} function findSingleVariableDeclaration(ast, kind, name) { return ast.program.body.find( stmt => types.isVariableDeclaration(stmt) && stmt.kind === kind && stmt.declarations.length === 1 && types.isVariableDeclarator(stmt.declarations[0]) && stmt.declarations[0].id.name === name
0
2
1
+ 7 other calls in file
156 157 158 159 160 161 162 163 164 165
if(t.isExpressionStatement(path.parentPath.parent)){ candidates.unshift(path.parentPath.parent); } } if(t.isVariableDeclarator(path.parent) && t.isVariableDeclaration(path.parentPath.parent)){ candidates.unshift(path.parentPath.parent); } let annotateEverything = getAnnotations(candidates);
156
0
5
+ 31 other calls in file
293 294 295 296 297 298 299 300 301 302 303
const EmptyStatement = (next, ast, opts) => t.EmptyStatement(); const BlockStatement = (next, ast, opts) => { if (bt.isVariableDeclaration(ast.body[0])) { const [decls, rest] = utils.takeWhile( n => bt.isVariableDeclaration(n), ast.body ); const entries = utils.flatMap(d => { const { id, init } = d.declarations[0];
5
91
0
babel-types.identifier is the most popular function in babel-types (4076 examples)