Skip to content

Based on ast, a babel plugin that automatically adds try/catch to functions.(基于ast,为函数自动添加 try/catch 的 babel 插件)

Notifications You must be signed in to change notification settings

xsf0105/babel-plugin-function-try-catch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-function-try-catch

Babel plugin that can add try/catch to function automatically.

Usage

Install:

yarn add babel-plugin-function-try-catch
or
npm install babel-plugin-function-try-catch

Example

before:

var fn = function(){
  console.log('hello world');
}

after:

var fn = function () {
  try {
    console.log(2);
  } catch (error) {
    // you can do some stuff here, for example, report this error with monitor sdk.
    console.log(error);
  }
};

How to config

webpack:

rules: [{
  test: /\.js$/,
  exclude: /node_modules/,
  use: [
+    "babel-plugin-function-try-catch",
    "babel-loader",
  ]
}]

About

Based on ast, a babel plugin that automatically adds try/catch to functions.(基于ast,为函数自动添加 try/catch 的 babel 插件)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published