Update: Turned out that this is not a problem with Babel, but with Rollup, which is run before. Thanks for your help anyway and sorry for the noise.
I use rollup to bundle a number of modules including a Promise polyfill (deliberately overwriting the global Promise). However, rollup recognizes Promise
as a global name and transforms
export default function Promise(fn) { ... }
...
global.Promise = Promise;
to
function Promise$1(fn) { ... }
...
global.Promise = Promise$1;
The resulting code works, but I would like the following assertion to hold true:
expect(Promise.name).to.equal('Promise');
Is there any way to tell rollup to leave the constructor name intact?
Try using rollup-plugin-inject and configuring it to add import Promise from 'your-promise-polyfill'
to any files that reference Promise
. That way, Rollup won't think that it needs to rename the function declared in the polyfill to avoid clashing with the global, because it won't be aware that there is a global that it's clashing with.
// rollup.config.js
import inject from 'rollup-plugin-inject';
export default {
// ...
plugins: [
inject({
Promise: 'your-promise-polyfill'
})
]
};
来源:https://stackoverflow.com/questions/45549689/prevent-rollup-from-renaming-promise-to-promise1