Prevent collapse from renaming Promise to Promise $ 1

Update: It turned out that this is not a problem with Babel, but with a Rollup that runs before. Thanks for your help anyway and sorry for the noise.

I am using rollup to bundle several modules, including the Promise polyfill (intentionally rewriting the global promise). However, the drive recognizes Promise

as a global name and converts

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 statement to hold:

expect(Promise.name).to.equal('Promise');

      

Is there a way to tell rollup to leave the constructor name intact?

+3


source to share


1 answer


Try using rollup-plugin-inject and configure it to add import Promise from 'your-promise-polyfill'

to any files referencing Promise

. This way Rollup won't think that it needs to rename the function declared in polyfill to avoid colliding with the global, because it won't know that there is a global that it collides with.



// rollup.config.js
import inject from 'rollup-plugin-inject';

export default {
  // ...
  plugins: [
    inject({
      Promise: 'your-promise-polyfill'
    })
  ]
};

      

+3


source







All Articles