Skip to content

Commit

Permalink
throw a TypeError in core-js-compat / core-js-builder in case o…
Browse files Browse the repository at this point in the history
…f passing invalid module names / filters for avoiding unexpected result

related to #1115
  • Loading branch information
zloirock committed Aug 17, 2022
1 parent abd824d commit d357e57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
- Fixed some cases of Safari < 13 bug - silent on non-writable array `.length` setting
- Relaxed condition of re-usage native `WeakMap` for internal states with multiple `core-js` copies
- Some stylistic changes
- Throwing a `TypeError` in `core-js-compat` / `core-js-builder` in case of passing invalid module names / filters for avoiding unexpected result, related to [#1115](https://github.com/zloirock/core-js/issues/1115)
- Added Electron 21 compat data mapping

##### [3.24.1 - 2022.07.30](https://github.com/zloirock/core-js/releases/tag/v3.24.1)
Expand Down
15 changes: 12 additions & 3 deletions packages/core-js-compat/compat.js
Expand Up @@ -6,12 +6,21 @@ const getModulesListForTargetVersion = require('./get-modules-list-for-target-ve
const allModules = require('./modules');
const targetsParser = require('./targets-parser');

function throwInvalidFilter(filter) {
throw TypeError(`Specified invalid module name or pattern: ${ filter }`);
}

function atLeastSomeModules(modules, filter) {
if (!modules.length) throwInvalidFilter(filter);
return modules;
}

function getModules(filter) {
if (typeof filter == 'string') {
if (has(entries, filter)) return entries[filter];
return allModules.filter(it => it.startsWith(filter));
} else if (filter instanceof RegExp) return allModules.filter(it => filter.test(it));
throw TypeError('Wrong filter!');
return atLeastSomeModules(allModules.filter(it => it.startsWith(filter)), filter);
} else if (filter instanceof RegExp) return atLeastSomeModules(allModules.filter(it => filter.test(it)), filter);
throwInvalidFilter(filter);
}

function normalizeModules(option) {
Expand Down

0 comments on commit d357e57

Please sign in to comment.