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
onlyPromise
(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-inPromise
methods (e.g.Promise.settle
)
the purpose of this plugin is to only transform a built-in Promise
to the Bluebird
.
Usage
.babelrc
(Recommended)
Via .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