closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Object spread causes polyfills even in modern language_out

Open L3P3 opened this issue 1 year ago • 3 comments

Version: From at least mid 2022 up to latest.

compilation_level ADVANCED language_out ECMASCRIPT_2020 rewrite_polyfills false

With ES2020 and up, using {x:foo, ...bar} causes this to be added to the head:

var ba="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a};function ca(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");}var da=ca(this);
function ea(a,b){if(b)a:{for(var c=da,d=a.split("."),f=0;f<d.length-1;f++){var e=d[f];if(!(e in c))break a;c=c[e]}d=d[d.length-1];f=c[d];e=b(f);e!=f&&null!=e&&ba(c,d,{configurable:!0,writable:!0,value:e})}}var fa="function"==typeof Object.assign?Object.assign:function(a,b){for(var c=1;c<arguments.length;c++){var d=arguments[c];if(d)for(var f in d)Object.prototype.hasOwnProperty.call(d,f)&&(a[f]=d[f])}return a};ea("Object.assign",function(a){return a||fa});

Summary: Abstract polyfill support, single Object.assign polyfill.

When I use Object.assign({x:foo}, bar), this disabled + useless polyfill stuff is not in there. sus Since this adds almost a kilobyte, I deem this worth fixable. In ES2020, there is no point in having an Object.assign polyfill. :wink:

L3P3 avatar Jun 07 '23 22:06 L3P3