How to use the isVariableDeclarator function from @babel/types

Find comprehensive JavaScript @babel/types.isVariableDeclarator code examples handpicked from public code repositorys.

@babel/types.isVariableDeclarator is a function that determines if a given AST node represents a variable declarator.

77
78
79
80
81
82
83
84
85
86
if (t.isObjectExpression(node.argument)) {
    returnPath = matchProp("controller", (path.get && path.get("argument.properties") || node.argument.properties));
} else if (path.get && t.isIdentifier(path.get("argument"))) {
    var binding = path.scope.getBinding(node.argument.name);
    var bound = binding && binding.path;
    if (bound && t.isVariableDeclarator(bound)) {
        var init = bound.get("init");
        if (init && t.isObjectExpression(init)) {
            returnPath = matchProp("controller", init.get("properties"));
        }
fork icon156
star icon244
watch icon6

31
32
33
34
35
36
37
38
39
40
const comments = (path.node.leadingComments || []).filter(isJSDocComment);

if (!comments.length) {
  // If this is the first declarator we check for comments on the VariableDeclaration.
  if (
    t.isVariableDeclarator(path) &&
    path.parentPath.get('declarations')[0] === path
  ) {
    return getComments(data, path.parentPath);
  }
fork icon509
star icon4
watch icon1

+ 3 other calls in file

How does @babel/types.isVariableDeclarator work?

@babel/types.isVariableDeclarator is a function in the Babel Types library that checks if a given AST node represents a variable declarator, which is a variable declaration that includes an initialization value. It returns true if the given node is a variable declarator and false otherwise.

137
138
139
140
141
142
143
144
145
146
contextAST.body.push(types.emptyStatement()); // 加分号避免语法错误

// 加密函数
const decryptFunPath = path.scope.getBinding(path.node.id.name).referencePaths
    .map(p => p.parentPath.parentPath)
    .filter(p => types.isVariableDeclarator(p))[0]
    .parentPath.parentPath.parentPath
contextAST.body.push(decryptFunPath.node);

decryptName = decryptFunPath.node.id.name;
fork icon2
star icon1
watch icon1

+ 82 other calls in file

225
226
227
228
229
230
231
232
233
234
235
236
237
const getEnclosingMethod = path => path.findParent((path) => path.isMethod());


const getEnclosingProperty = path => path.findParent((path) => path.isProperty());


const isTopLevelDeclaredObject = (path) =>
  types.isVariableDeclarator(path.parentPath) &&
  types.isVariableDeclaration(path.parentPath.parentPath) &&
  types.isProgram(path.parentPath.parentPath.parentPath);


const handleCallExpressionEnter = (path) => {
fork icon0
star icon0
watch icon0

+ 21 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
const t = require("@babel/types");

const node = t.variableDeclarator(t.identifier("x"), t.numericLiteral(42));

if (t.isVariableDeclarator(node)) {
  console.log("This is a variable declarator node!");
} else {
  console.log("This is not a variable declarator node.");
}

In this example, t.isVariableDeclarator(node) will return true, since node is a variable declarator.

Other functions in @babel/types

Sorted by popularity

function icon

@babel/types.identifier is the most popular function in @babel/types (20936 examples)