replace Promise with bluebird plugin.
npm install bluebird babel-plugin-transform-bluebird --save
In
Promise.resolve().then(() => new Promise((resolve) => resolve()))
Out
import _Promise from "bluebird";
_Promise.resolve().then(() => new _Promise(resolve => resolve()));
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();
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
.
.babelrc
{
"plugins": ["transform-bluebird"]
}
$ babel --plugins transform-bluebird script.js
require("babel-core").transform("code", {
plugins: ["transform-bluebird"]
});
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