JSPM

babel-plugin-transform-catch

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q26313F

Transforms .catch(..) to ['catch'](...)

Package Exports

  • babel-plugin-transform-catch

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-transform-catch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Motivation

catch in Google apps script is reserved word and this make it impossible to use with promises. And while you can easily overcome it by not using promises which in fact absent in GAS environment the problem become hard to solve if your project requires 3rd-party library. In example jsonwebtoken, which dependent on another library, which has .catch in its code.

At the end of the day it become simpler to roll-out babel transformation than any other option.

Example

In

performRequest.then(doSomething).catch(function() { handler() });

Out

performRequest.then(doSomething)["catch"](function () {
  handler();
});

Installation

$ npm install babel-plugin-transform-catch

Usage

.babelrc

{
  "plugins": ["babel-plugin-transform-catch"]
}

Via CLI

$ babel --plugins babel-plugin-transform-catch script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["babel-plugin-transform-catch"]
});