Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object spread causes polyfills even in modern language_out #4098

Open
L3P3 opened this issue Jun 7, 2023 · 3 comments
Open

Object spread causes polyfills even in modern language_out #4098

L3P3 opened this issue Jun 7, 2023 · 3 comments

Comments

@L3P3
Copy link

L3P3 commented Jun 7, 2023

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. 😉

@rishipal
Copy link
Contributor

rishipal commented Jun 9, 2023

How have you configured the compiler to run and how are you invoking it? In my IntegrationTest the polyfills are only getting injected if I set the language_out to ES3.

@L3P3
Copy link
Author

L3P3 commented Jun 10, 2023

Will post later, but can be found here: https://github.com/L3P3/lui/blob/master/build.js#L51

Also just noticed that the polyfill code has both defineProperty and defineProperties there, which seems very weird.

@L3P3
Copy link
Author

L3P3 commented Jun 10, 2023

Sorry, for ES2020, there are no polyfills, but for ES5, there is! My mistake in writing this issue! 😅

I am trying to nail it down. What I got so far is that the polyfill appears even with this code:

// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @language_out ECMASCRIPT5_STRICT
// @rewrite_polyfills false
// @output_file_name default.js
// ==/ClosureCompiler==

(() => {
  Object.assign;
  false ? { ...{} } : null;
})();

The polyfill code only appears when both lines inside the function are there. If you comment out one of those, it is not appearing. Note that I DISABLED polyfills explicitly but they still appear... 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants