replace Promise with bluebird plugin.
npm install bluebird babel-plugin-transform-bluebird --saveIn
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)MemberExpressiononly built-in Promise methods (e.g.Promise.resolve->Bluebird.resolve)IdentifieronlyPromise(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))MemberExpressionnon built-inPromisemethods (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.jsrequire("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