Skip to content

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

@morlay

Description

@morlay

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions