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;
46
35
0
GitHub: fecym/ast-share
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]); }, },
2
12
1
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 ); }
0
1
0
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)
0
0
0
@babel/types.identifier is the most popular function in @babel/types (20936 examples)