Skip to content

59naga/babel-plugin-transform-bluebird

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-transform-bluebird

replace Promise with bluebird plugin.

Installation

npm install bluebird babel-plugin-transform-bluebird --save

Example

In

Promise.resolve().then(() => new Promise((resolve) => resolve()))

Out

import _Promise from "bluebird";
_Promise.resolve().then(() => new _Promise(resolve => resolve()));

Support expression

  • NewExpression (e.g. new Promise -> new Bluebird)
  • MemberExpression only built-in Promise methods (e.g. Promise.resolve -> Bluebird.resolve)
  • Identifier only Promise (e.g. fn(Promise) -> fn(Bluebird))

But, if the Promise is already import in file, the file does not transform.

// does not transform
import Promise from 'q';
Promise.resolve();

Unsupport expression

  • BinaryExpression (e.g. instanceof Promise, if(foo === Promise))
  • MemberExpression non built-in Promise methods (e.g. Promise.settle)

the purpose of this plugin is to only transform a built-in Promise to the Bluebird.

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["transform-bluebird"]
}

Via CLI

$ babel --plugins transform-bluebird script.js

Via Node API

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

Development

Requirement global

  • NodeJS v5.11.0
  • Npm v3.8.6
git clone https://github.com/59naga/babel-plugin-transform-bluebird
cd babel-plugin-transform-bluebird
npm install

npm test

License

MIT