Skip to content

Commit

Permalink
Merge pull request #590 from nicolo-ribaudo/compat-remove-set-interse…
Browse files Browse the repository at this point in the history
…ction

[core-js-compat] Filter available modules without using an intermediate set
  • Loading branch information
zloirock authored Jul 4, 2019
2 parents 1508eb0 + bacd238 commit f8ad1c6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/core-js-compat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { coerce, lt, lte } = require('semver');
const browserslist = require('browserslist');
const data = require('./data');
const getModulesListForTargetVersion = require('./get-modules-list-for-target-version');
const intersection = require('core-js-pure/features/set/intersection');
const has = Function.call.bind({}.hasOwnProperty);

const mapping = new Map([
Expand Down Expand Up @@ -86,7 +85,8 @@ function compat({ targets, filter, version }) {
else if (typeof filter == 'string') modules = modules.filter(it => it.startsWith(filter));

if (version) {
modules = [...intersection(new Set(getModulesListForTargetVersion(version)), new Set(modules))];
const availableModules = new Set(getModulesListForTargetVersion(version));
modules = modules.filter(name => availableModules.has(name));
}

modules.forEach(key => {
Expand Down
1 change: 0 additions & 1 deletion packages/core-js-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"main": "index.js",
"dependencies": {
"browserslist": "^4.6.3",
"core-js-pure": "3.1.4",
"semver": "^6.1.3"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/core-js-compat/src/build-entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ const { readFileSync, writeFileSync } = require('fs');
const { dirname, resolve } = require('path');
const detective = require('detective');
const { sync: glob } = require('glob');
const intersection = require('core-js-pure/features/set/intersection');
const data = require('./data');
const order = new Set(Object.keys(data));
const order = Object.keys(data);

function getModulesForEntryPoint(entry) {
const match = entry.match(/\/modules\/([^/]+)$/);
Expand All @@ -19,7 +18,8 @@ function getModulesForEntryPoint(entry) {
const relative = resolve(dir, dependency);
result.push(...getModulesForEntryPoint(relative));
}
return [...intersection(new Set(result), order)];
const resultSet = new Set(result);
return order.filter(it => resultSet.has(it));
}

const entries = {};
Expand Down

0 comments on commit f8ad1c6

Please sign in to comment.