Added 'intersect' support to esmodules targets (#1404)

This commit is contained in:
Sergey Nechaev
2025-04-02 03:31:56 +07:00
committed by GitHub
parent c0409fcbe5
commit 628ad55ecb
5 changed files with 28 additions and 10 deletions
+2
View File
@@ -2,6 +2,8 @@
##### Unreleased
- Validation order of [`WeakMap.prototype.getOrInsertComputed`](https://github.com/tc39/proposal-upsert) updated following [proposal-upsert/79](https://github.com/tc39/proposal-upsert/pull/79)
- Don't call well-known Symbol methods for RegExp on primitive values [tc39/ecma262#3009](https://github.com/tc39/ecma262/pull/3009)
- Added 'intersect' support for `targets.esmodules` (Babel v7 behavior)
- Fixed handling of `targets.esmodules: true` (Babel v7 behavior)
- Compat data improvements:
- [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management) features disabled (again) in V8 ~ Chromium 135 and re-added in 136
- [`RegExp.escape`](https://github.com/tc39/proposal-regex-escaping) marked as [shipped from V8 ~ Chromium 136](https://issues.chromium.org/issues/353856236#comment17)
+5 -1
View File
@@ -96,7 +96,11 @@ console.log(targets);
rhino: '1.7.13', // Rhino engine version
safari: '14.0', // Safari version
samsung: '14.0', // Samsung Internet version
esmodules: true, // That option set target to minimum supporting ES Modules versions of all browsers
/**
* true option set target to minimum supporting ES Modules versions of all browsers, ignoring `browsers` target.
* 'intersect' option intersects the `browsers` target and `browserslist`'s targets. The maximum version will be used.
*/
esmodules: true | 'intersect',
browsers: '> 0.25%', // Browserslist query or object with target browsers
});
```
+1 -1
View File
@@ -12,7 +12,7 @@ type Environments = {
type Targets = Environments & {
browsers?: Environments | BrowserslistQuery,
esmodules?: boolean,
esmodules?: boolean | 'intersect',
};
type CompatOptions = {
+9 -6
View File
@@ -53,14 +53,16 @@ module.exports = function (targets) {
const list = Object.entries(rest);
if (browsers) {
const normalizedESModules = esmodules === 'intersect' ? 'intersect' : !!esmodules;
if (browsers && normalizedESModules !== true) {
if (typeof browsers == 'string' || Array.isArray(browsers)) {
list.push(...browserslist(browsers).map(it => it.split(' ')));
} else {
list.push(...Object.entries(browsers));
}
}
if (esmodules) {
if (normalizedESModules === true) {
list.push(...Object.entries(external.modules));
}
if (node) {
@@ -81,12 +83,13 @@ module.exports = function (targets) {
return a < b ? -1 : a > b ? 1 : 0;
});
const reducedByMinVersion = new Map();
const reduced = new Map();
const operator = normalizedESModules === 'intersect' ? '>' : '<=';
for (const [engine, version] of normalized) {
if (!reducedByMinVersion.has(engine) || compare(version, '<=', reducedByMinVersion.get(engine))) {
reducedByMinVersion.set(engine, version);
if (!reduced.has(engine) || compare(version, operator, reduced.get(engine))) {
reduced.set(engine, version);
}
}
return reducedByMinVersion;
return reduced;
};
+11 -2
View File
@@ -89,7 +89,7 @@ deepEqual(targetsParser({
['chrome', '61'],
['chrome-android', '56'],
['deno', '1.0'],
['edge', '13'],
['edge', '16'],
['electron', '1'],
['firefox', '60'],
['firefox-android', '60'],
@@ -100,8 +100,17 @@ deepEqual(targetsParser({
['opera-android', '40'],
['quest', '4.0'],
['react-native', '0.70'],
['safari', '5.1'],
['safari', '10.1'],
['samsung', '4'],
]), 'mixed');
deepEqual(targetsParser({
esmodules: 'intersect',
browsers: 'ie 11, chrome 56',
chrome: 77,
}), new Map([
['chrome', '77'],
['ie', '11'],
]), 'targets.esmodules: intersect');
echo(chalk.green('targets parser tested'));