1.1.0 • Published 4 years ago

babel-plugin-function-try-catch v1.1.0

Weekly downloads
11
License
ISC
Repository
github
Last release
4 years ago

babel-plugin-function-try-catch

Babel plugin that can add try/catch to function automatically.(一个能为函数自动添加 try/catch 的 babel 插件)

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) {
    console.log(error);
  }
};

How to config

webpack:

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