How to use the catchClause function from @babel/types

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

120
121
122
123
124
125
126
127
128
129
const statements = variables.map(prettyPrintStatement);
statements.unshift(printCaught());
statements.unshift(printHash());
const statement = babelTypes.tryStatement(
    babelTypes.blockStatement(statements),
    babelTypes.catchClause(
        babelTypes.identifier('e'),
        babelTypes.blockStatement([])));
this.annotate(statement, 'Print variables and exceptions from section');
return statement;
fork icon46
star icon35
watch icon0

27
28
29
30
31
32
33
34
35
36
    // console.log("AwaitExpression -> replacePath", replacePath)
    const tryBlock = t.blockStatement([replacePath.node]);
    // 生成 catch --> new Error(e)
    const paramsE = t.identifier('e');
    const throwStatement = t.throwStatement(t.newExpression(t.identifier('Error'), [paramsE]));
    const catchClause = t.catchClause(paramsE, t.blockStatement([throwStatement]));
    const tryStatement = t.tryStatement(tryBlock, catchClause);
    replacePath.replaceWithMultiple([tryStatement]);
  },
},
fork icon2
star icon12
watch icon1

106
107
108
109
110
111
112
113
114
    this.mapIfAlternates(catchBody);
  }

  return t.tryStatement(
    t.blockStatement(tryBody),
    t.catchClause(expIdentifier, t.blockStatement(flatten([catchBody[0]]))),
    finallyBody ? t.blockStatement(finallyBody) : undefined
  );
}
fork icon0
star icon1
watch icon0

59
60
61
62
63
64
65
66
67
68
    t.isBlockStatement(path.node) &&
    isAsyncFuncNode(parentPath.node)
) {
    let tryCatchAst = t.tryStatement(
        path.node,
        t.catchClause(
            t.identifier(options.identifier),
            t.blockStatement(catchNode)
        ),
        finallyNode && t.blockStatement(finallyNode)
fork icon0
star icon0
watch icon0

Other functions in @babel/types

Sorted by popularity

function icon

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