babel-polyfills icon indicating copy to clipboard operation
babel-polyfills copied to clipboard

Function 'finally' on prototype shouldn't polyfill 'promise'

Open chenjianzhonglol opened this issue 3 years ago • 3 comments

When i define a 'finally' function on other function's prototype, why dist code includes "core-js/modules/es.promise.finally.js", "core-js/modules/es.promise.js".

ex:

image

chenjianzhonglol avatar Aug 20 '21 06:08 chenjianzhonglol

I think we can skip the MemberExpression path if the it is in the left of an AssignmentExpression whose operator is =?

https://github.com/babel/babel-polyfills/blob/615e5cd57a64eca434f9129e2a73d46af9223801/packages/babel-helper-define-polyfill-provider/src/visitors/usage.js#L27

JLHwung avatar Sep 07 '21 14:09 JLHwung

It would work, even if somewhere that .finally method is probably used so the es.promise.finally polyfill will be added anyway.

I wonder why we add the polyfill for

function Test() {}

Test.prototype.finally = function() {}

but not for

Test.prototype.finally = function() {}

nicolo-ribaudo avatar Sep 07 '21 14:09 nicolo-ribaudo

I think we can skip the MemberExpression path

It will break the monkey patching of built-in methods in some cases, for example testing.

zloirock avatar Sep 07 '21 14:09 zloirock