Skip to content

Commit

Permalink
filter out stabilized proposals from the output
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Mar 29, 2022
1 parent 9bfded7 commit 3f1106a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Changelog
##### Unreleased
- Stabilized proposals are filtered out from the `core-js-compat` / `core-js-builder` / `core-js-bundle` output. That mean that if the output contains, for example, `es.object.has-own`, the legacy shortcut to it, `esnext.object.has-own`, will not be added.
- Fixed work of non-standard V8 `Error` features with wrapped `Error` constructors, [#1061](https:/zloirock/core-js/issues/1061)
- `null` and `undefined` allowed as the second argument of `structuredClone`, [#1056](https:/zloirock/core-js/issues/1056)
- Updated Electron 18.0 compat data mapping
Expand Down
3 changes: 2 additions & 1 deletion packages/core-js-builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const mkdirp = promisify(require('mkdirp'));
const webpack = promisify(require('webpack'));
const compat = require('core-js-compat/compat');
const modulesList = require('core-js-compat/modules');
const { filterOutStabilizedProposals } = require('core-js-compat/helpers');
const { banner } = require('./config');

function normalizeSummary(unit = {}) {
Expand Down Expand Up @@ -55,7 +56,7 @@ module.exports = async function ({
filter('delete', blacklist || exclude);

// eslint-disable-next-line sonarjs/no-empty-collection -- false positive
modules = modulesList.filter(it => set.has(it));
modules = filterOutStabilizedProposals(modulesList.filter(it => set.has(it)));

if (targets) {
const compatResult = compat({ targets, filter: modules });
Expand Down
4 changes: 3 additions & 1 deletion packages/core-js-compat/compat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const { compare, has, intersection } = require('./helpers');
const { compare, filterOutStabilizedProposals, has, intersection } = require('./helpers');
const data = require('./data');
const getModulesListForTargetVersion = require('./get-modules-list-for-target-version');
const modules = require('./modules');
Expand Down Expand Up @@ -40,6 +40,8 @@ module.exports = function ({ targets, filter, version }) {
$modules = $modules.filter(it => it.startsWith(filter));
}

$modules = filterOutStabilizedProposals($modules);

if (version) {
$modules = intersection($modules, getModulesListForTargetVersion(version));
}
Expand Down
13 changes: 13 additions & 0 deletions packages/core-js-compat/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ function compare(a, operator, b) {
return cmp(semver(a), operator, semver(b));
}

function filterOutStabilizedProposals(modules) {
const modulesSet = new Set(modules);

for (const $module of modulesSet) {
if ($module.startsWith('esnext.') && modulesSet.has($module.replace(/^esnext\./, 'es.'))) {
modulesSet.delete($module);
}
}

return [...modulesSet];
}

function intersection(list, order) {
const set = list instanceof Set ? list : new Set(list);
return order.filter(name => set.has(name));
Expand All @@ -22,6 +34,7 @@ function sortObjectByKey(object, fn) {

module.exports = {
compare,
filterOutStabilizedProposals,
has,
intersection,
semver,
Expand Down
6 changes: 0 additions & 6 deletions scripts/bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ bundle(DENO ? {
targets: { deno: '1.0' },
exclude: [
'esnext.array.filter-out', // obsolete
'esnext.aggregate-error', // moved to stable ES
'esnext.global-this', // moved to stable ES
'esnext.map.update-or-insert', // obsolete
'esnext.map.upsert', // obsolete
'esnext.math.iaddh', // withdrawn
Expand All @@ -63,11 +61,7 @@ bundle(DENO ? {
'esnext.object.iterate-entries', // withdrawn
'esnext.object.iterate-keys', // withdrawn
'esnext.object.iterate-values', // withdrawn
'esnext.promise.all-settled', // moved to stable ES
'esnext.promise.any', // moved to stable ES
'esnext.string.at', // withdrawn
'esnext.string.match-all', // moved to stable ES
'esnext.string.replace-all', // moved to stable ES
'esnext.symbol.pattern-match', // is not a part of actual proposal, replaced by esnext.symbol.matcher
'esnext.symbol.replace-all', // obsolete
'esnext.typed-array.filter-out', // obsolete
Expand Down

0 comments on commit 3f1106a

Please sign in to comment.