How to use the isProgram function from @babel/types

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

21
22
23
24
25
26
27
28
29
30
        }
    }
},
ExpressionStatement: {
    exit(path) {
        if (first && t.isProgram(path.parent)) {
            first = false;
            path.replaceWithMultiple(newSource);
        }
    }
fork icon17
star icon65
watch icon8

434
435
436
437
438
439
440
441
442
443
  sourceType: 'module',
  plugins: ['jsx'] // FIXME!!! presets: ['env]

});

if (t.isFile(ast) && t.isProgram(ast.program) && ast.program.body.length === 1) {
  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];
fork icon1
star icon2
watch icon1

94
95
96
97
98
99
100
101
102
103

function hasBinding(node, name) {
  if (Array.isArray(node)) {
    return node.some(ancestor => hasBinding(ancestor, name));
  } else if (
    types.isProgram(node) ||
    types.isBlockStatement(node) ||
    types.isBlock(node)
  ) {
    return node.body.some(statement => hasBinding(statement, name));
fork icon0
star icon2
watch icon2

+ 3 other calls in file

23
24
25
26
27
28
29
30
31
  // Ignore block statements.
  if (t.isBlockStatement(cursor.scope.path)) {
    continue;
  }

  if (t.isFunction(cursor.scope.path) || t.isProgram(cursor.scope.path)) {
    break;
  }
} while ((cursor = cursor.scope.path.parentPath));
fork icon0
star icon1
watch icon1

+ 10 other calls in file

227
228
229
230
231
232
233
234
235
236
237
238
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) => {
  if (path.node.callee.type !== 'MemberExpression' ||
    path.node.callee.object.type !== 'Super') {
fork icon0
star icon0
watch icon0

+ 21 other calls in file

Other functions in @babel/types

Sorted by popularity

function icon

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