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

Consider Ponyfill with core-js-pure instead of core-js to avoid pollute global environment. #5584

Open
morlay opened this issue Aug 22, 2022 · 6 comments

Comments

@morlay
Copy link

morlay commented Aug 22, 2022

Describe the feature

Array.from(new Set([1, 2, 3, 2, 1]));          // => [1, 2, 3]
[1, 2, 3, 4, 5].group(it => it % 2);           // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3]));           // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));

Could be

// core-js-prue is the version without global namespace pollution
// for easier to transform, we could has some rule of the importers. just like babel did
//  _<Class>$<static_method>
import _Array$from from 'core-js-pure/actual/array/from';
// _<instance_method><class>(instance, ...instance.method_args)
// need to wrap instance as first arg.
import _groupArray from 'core-js-pure/actual/array/group';
// _<Class>
import _Set from 'core-js-pure/actual/set';
import _Promise from 'core-js-pure/actual/promise';
// _<global_method>
import _structuredClone from 'core-js-pure/actual/structured-clone';
import _queueMicrotask from 'core-js-pure/actual/queue-microtask';

_Array$from(new Set([1, 2, 3, 2, 1]));                // => [1, 2, 3]
_groupArray([1, 2, 3, 4, 5], it => it % 2);          // => { 1: [1, 3, 5], 0: [2, 4] }
_Promise.resolve(42).then(x => console.log(x)); // => 42
_structuredClone(new Set([1, 2, 3]));           // => new Set([1, 2, 3])
_queueMicrotask(() => console.log('called as microtask'));

Babel plugin or link to the feature description

https://babeljs.io/docs/en/babel-plugin-transform-runtime#core-js-aliasing

Additional context

https://ponyfoo.com/articles/polyfills-or-ponyfills
https://github.com/zloirock/core-js/blob/master/README.md

it could be enable when corejs@3 and usage

@kdy1
Copy link
Member

kdy1 commented Aug 22, 2022

Your link to babel is something completely different, and I think this is a huge security risk

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 22, 2022
@kdy1
Copy link
Member

kdy1 commented Aug 22, 2022

Sorry I misread it

@kdy1 kdy1 reopened this Aug 22, 2022
@morlay
Copy link
Author

morlay commented Aug 22, 2022

Your link to babel is something completely different, and I think this is a huge security risk

@babel/runtime-corejs3/{core-js,core-js-stable} just a wrap of core-js-pure

image

@zloirock
Copy link

Note that the pure version / runtime transform has many limitations and many features are not available. However, it's the best option, for example, for libraries that should not pollute the global namespace.

babel-plugin-polyfill-corejs3 injects core-js-pure directly instead of @babel/runtime.

@dac09
Copy link

dac09 commented Sep 20, 2022

Hey wanted to mention that this would be an important feature to use swc to build libraries.

It's sort of fine to pollute the global scope when you're using SWC to build your app, but when building a library that someone uses in their app, it feels like a bad idea.

(or am I being too cautious here?)

@kdy1
Copy link
Member

kdy1 commented Sep 21, 2022

Don't leave comments like +1
It does not help at all

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

No branches or pull requests

4 participants