Skip to content

Commit 96f5983

Browse files
authored
fix: correct ECMA version browserslist mapping (#301)
1 parent 1b905d8 commit 96f5983

File tree

6 files changed

+182
-129
lines changed

6 files changed

+182
-129
lines changed

packages/core/src/utils/syntax.ts

Lines changed: 76 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -56,112 +56,104 @@ export const ESX_TO_BROWSERSLIST: Record<
5656
> &
5757
Record<LatestEcmaVersions, (target: RsbuildConfigOutputTarget) => string[]> =
5858
{
59+
es5: {
60+
chrome: '5.0.0',
61+
edge: '12.0.0',
62+
firefox: '2.0.0',
63+
ie: '9.0.0',
64+
ios: '6.0.0',
65+
node: '0.4.0',
66+
opera: '10.10.0',
67+
safari: '3.1.0',
68+
},
5969
es6: {
60-
Chrome: '63.0.0',
61-
Edge: '79.0.0',
62-
Firefox: '67.0.0',
63-
iOS: '13.0.0',
64-
Node: ['node > 12.20.0 and node < 13.0.0', 'node > 13.2.0'],
65-
Opera: '50.0.0',
66-
Safari: '13.0.0',
70+
chrome: '63.0.0',
71+
edge: '79.0.0',
72+
firefox: '67.0.0',
73+
ios: '13.0.0',
74+
node: '13.2.0',
75+
opera: '50.0.0',
76+
safari: '13.0.0',
6777
},
6878
es2015: {
69-
Chrome: '63.0.0',
70-
Edge: '79.0.0',
71-
Firefox: '67.0.0',
72-
iOS: '13.0.0',
73-
Node: '10.0.0',
74-
Opera: '50.0.0',
75-
Safari: '13.0.0',
79+
chrome: '63.0.0',
80+
edge: '79.0.0',
81+
firefox: '67.0.0',
82+
ios: '13.0.0',
83+
node: '13.2.0',
84+
opera: '50.0.0',
85+
safari: '13.0.0',
7686
},
7787
es2016: {
78-
Chrome: '52.0.0',
79-
Edge: '14.0.0',
80-
Firefox: '52.0.0',
81-
iOS: '10.3.0',
82-
Node: '7.0.0',
83-
Opera: '39.0.0',
84-
Safari: '10.1.0',
88+
chrome: '63.0.0',
89+
edge: '79.0.0',
90+
firefox: '67.0.0',
91+
ios: '13.0.0',
92+
node: '13.2.0',
93+
opera: '50.0.0',
94+
safari: '13.0.0',
8595
},
8696
es2017: {
87-
Chrome: '55.0.0',
88-
Edge: '15.0.0',
89-
Firefox: '52.0.0',
90-
iOS: '11.0.0',
91-
Node: '7.6.0',
92-
Opera: '42.0.0',
93-
Safari: '11.0.0',
97+
chrome: '63.0.0',
98+
edge: '79.0.0',
99+
firefox: '67.0.0',
100+
ios: '13.0.0',
101+
node: '13.2.0',
102+
opera: '50.0.0',
103+
safari: '13.0.0',
94104
},
95105
es2018: {
96-
Chrome: '64.0.0',
97-
Edge: '79.0.0',
98-
Firefox: '78.0.0',
99-
iOS: '16.4.0',
100-
Node: [
101-
'node > 18.20.0 and node < 19.0.0',
102-
'node > 20.12.0 and node < 21.0.0',
103-
'node > 21.3.0',
104-
],
105-
Opera: '51.0.0',
106-
Safari: '16.4.0',
106+
chrome: '64.0.0',
107+
edge: '79.0.0',
108+
firefox: '78.0.0',
109+
ios: '16.4.0',
110+
node: '13.2.0',
111+
opera: '51.0.0',
112+
safari: '16.4.0',
107113
},
108114
es2019: {
109-
Chrome: '66.0.0',
110-
Edge: '79.0.0',
111-
Firefox: '58.0.0',
112-
iOS: '11.3.0',
113-
Node: '10.0.0',
114-
Opera: '53.0.0',
115-
Safari: '11.1.0',
115+
chrome: '66.0.0',
116+
edge: '79.0.0',
117+
firefox: '78.0.0',
118+
ios: '16.4.0',
119+
node: '13.2.0',
120+
opera: '53.0.0',
121+
safari: '16.4.0',
116122
},
117123
es2020: {
118-
Chrome: '91.0.0',
119-
Edge: '91.0.0',
120-
Firefox: '80.0.0',
121-
iOS: '14.5.0',
122-
Node: '16.1.0',
123-
Opera: '77.0.0',
124-
Safari: '14.1.0',
124+
chrome: '91.0.0',
125+
edge: '91.0.0',
126+
firefox: '80.0.0',
127+
ios: '16.4.0',
128+
node: '16.1.0',
129+
opera: '77.0.0',
130+
safari: '16.4.0',
125131
},
126132
es2021: {
127-
Chrome: '85.0.0',
128-
Edge: '85.0.0',
129-
Firefox: '79.0.0',
130-
iOS: '14.0.0',
131-
Node: '15.0.0',
132-
Opera: '71.0.0',
133-
Safari: '14.0.0',
133+
chrome: '91.0.0',
134+
edge: '91.0.0',
135+
firefox: '80.0.0',
136+
ios: '16.4.0',
137+
node: '16.1.0',
138+
opera: '77.0.0',
139+
safari: '16.4.0',
134140
},
135141
es2022: {
136-
Chrome: '91.0.0',
137-
Edge: '94.0.0',
138-
Firefox: '93.0.0',
139-
iOS: '16.4.0',
140-
Node: '16.11.0',
141-
Opera: '80.0.0',
142-
Safari: '16.4.0',
142+
chrome: '91.0.0',
143+
firefox: '93.0.0',
144+
ios: '16.4.0',
145+
node: '16.11.0',
146+
safari: '16.4.0',
143147
},
144148
es2023: {
145-
Chrome: '74.0.0',
146-
Edge: '79.0.0',
147-
Firefox: '67.0.0',
148-
iOS: '13.4.0',
149-
Node: '12.5.0',
150-
Opera: '62.0.0',
151-
Safari: '13.1.0',
149+
chrome: '91.0.0',
150+
firefox: '93.0.0',
151+
ios: '16.4.0',
152+
node: '16.11.0',
153+
safari: '16.4.0',
152154
},
153155
es2024: calcEsnextBrowserslistByTarget,
154156
esnext: calcEsnextBrowserslistByTarget,
155-
es5: {
156-
Chrome: '5.0.0',
157-
Edge: '12.0.0',
158-
Firefox: '2.0.0',
159-
ie: '9.0.0',
160-
iOS: '6.0.0',
161-
Node: '0.4.0',
162-
Opera: '10.10.0',
163-
Safari: '3.1.0',
164-
},
165157
} as const;
166158

167159
export function transformSyntaxToRspackTarget(

packages/core/tests/config.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ describe('syntax', () => {
303303
composedRsbuildConfig[0].config.output?.overrideBrowserslist,
304304
).toMatchInlineSnapshot(`
305305
[
306-
"Chrome >= 63.0.0",
307-
"Edge >= 79.0.0",
308-
"Firefox >= 67.0.0",
309-
"iOS >= 13.0.0",
310-
"Node >= 10.0.0",
311-
"Opera >= 50.0.0",
312-
"Safari >= 13.0.0",
306+
"chrome >= 63.0.0",
307+
"edge >= 79.0.0",
308+
"firefox >= 67.0.0",
309+
"ios >= 13.0.0",
310+
"node >= 13.2.0",
311+
"opera >= 50.0.0",
312+
"safari >= 13.0.0",
313313
]
314314
`);
315315
});

packages/core/tests/syntax.test.ts

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,85 @@
11
import { describe, expect, test } from 'vitest';
22
import {
3+
ESX_TO_BROWSERSLIST,
34
transformSyntaxToBrowserslist,
45
transformSyntaxToRspackTarget,
56
} from '../src/utils/syntax';
67

8+
const compareSemver = (a: string, b: string) => {
9+
const [aMajor, aMinor, aPatch] = a.split('.').map(Number);
10+
const [bMajor, bMinor, bPatch] = b.split('.').map(Number);
11+
12+
if (aMajor !== bMajor) {
13+
return aMajor - bMajor;
14+
}
15+
if (aMinor !== bMinor) {
16+
return aMinor - bMinor;
17+
}
18+
return aPatch - bPatch;
19+
};
20+
21+
describe('ESX_TO_BROWSERSLIST', () => {
22+
test('some ECMA version queries should be the same', () => {
23+
expect(ESX_TO_BROWSERSLIST.es6).toStrictEqual(ESX_TO_BROWSERSLIST.es2015);
24+
expect(ESX_TO_BROWSERSLIST.esnext).toStrictEqual(
25+
ESX_TO_BROWSERSLIST.es2024,
26+
);
27+
});
28+
29+
test('ECMA version mapped browserslist queries should increments', () => {
30+
const sortedVersions = [
31+
'es5',
32+
'es6',
33+
'es2015',
34+
'es2016',
35+
'es2017',
36+
'es2018',
37+
'es2019',
38+
'es2020',
39+
'es2021',
40+
'es2022',
41+
'es2023',
42+
'es2024',
43+
'esnext',
44+
];
45+
46+
for (let i = 1; i < sortedVersions.length; i++) {
47+
const prev = sortedVersions[i - 1];
48+
const current = sortedVersions[i];
49+
for (const query of Object.keys(ESX_TO_BROWSERSLIST[current])) {
50+
const prevQuery = ESX_TO_BROWSERSLIST[prev][query];
51+
const currQuery = ESX_TO_BROWSERSLIST[current][query];
52+
if (prevQuery && currQuery) {
53+
expect(compareSemver(currQuery, prevQuery)).toBeGreaterThanOrEqual(0);
54+
}
55+
}
56+
}
57+
});
58+
});
59+
760
describe('transformSyntaxToBrowserslist', () => {
861
test('esX', () => {
9-
expect(transformSyntaxToBrowserslist('es6')).toMatchInlineSnapshot(`
62+
expect(transformSyntaxToBrowserslist('es2015')).toMatchInlineSnapshot(`
1063
[
11-
"Chrome >= 63.0.0",
12-
"Edge >= 79.0.0",
13-
"Firefox >= 67.0.0",
14-
"iOS >= 13.0.0",
15-
"node > 12.20.0 and node < 13.0.0",
16-
"node > 13.2.0",
17-
"Opera >= 50.0.0",
18-
"Safari >= 13.0.0",
64+
"chrome >= 63.0.0",
65+
"edge >= 79.0.0",
66+
"firefox >= 67.0.0",
67+
"ios >= 13.0.0",
68+
"node >= 13.2.0",
69+
"opera >= 50.0.0",
70+
"safari >= 13.0.0",
1971
]
2072
`);
2173

2274
expect(transformSyntaxToBrowserslist('es2018')).toMatchInlineSnapshot(`
2375
[
24-
"Chrome >= 64.0.0",
25-
"Edge >= 79.0.0",
26-
"Firefox >= 78.0.0",
27-
"iOS >= 16.4.0",
28-
"node > 18.20.0 and node < 19.0.0",
29-
"node > 20.12.0 and node < 21.0.0",
30-
"node > 21.3.0",
31-
"Opera >= 51.0.0",
32-
"Safari >= 16.4.0",
76+
"chrome >= 64.0.0",
77+
"edge >= 79.0.0",
78+
"firefox >= 78.0.0",
79+
"ios >= 16.4.0",
80+
"node >= 13.2.0",
81+
"opera >= 51.0.0",
82+
"safari >= 16.4.0",
3383
]
3484
`);
3585

@@ -84,14 +134,14 @@ describe('transformSyntaxToBrowserslist', () => {
84134
).toMatchInlineSnapshot(`
85135
[
86136
"Chrome 123",
87-
"Chrome >= 5.0.0",
88-
"Edge >= 12.0.0",
89-
"Firefox >= 2.0.0",
137+
"chrome >= 5.0.0",
138+
"edge >= 12.0.0",
139+
"firefox >= 2.0.0",
90140
"ie >= 9.0.0",
91-
"iOS >= 6.0.0",
92-
"Node >= 0.4.0",
93-
"Opera >= 10.10.0",
94-
"Safari >= 3.1.0",
141+
"ios >= 6.0.0",
142+
"node >= 0.4.0",
143+
"opera >= 10.10.0",
144+
"safari >= 3.1.0",
95145
]
96146
`);
97147

tests/integration/syntax/__fixtures__/src/foo.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
export { Foo } from './foo';
1+
export class Foo {
2+
constructor() {
3+
this.#bar();
4+
}
5+
6+
#bar() {}
7+
}
8+
9+
export function foo(options: unknown = {}): void {
10+
console.log(options);
11+
}

tests/integration/syntax/__snapshots__/index.test.ts.snap

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ exports[`should downgrade class private method by default 1`] = `
77
}
88
#bar() {}
99
}
10-
export { Foo };
10+
function foo(options = {}) {
11+
console.log(options);
12+
}
13+
export { Foo, foo };
1114
"
1215
`;
1316

@@ -31,7 +34,11 @@ class Foo {
3134
}
3235
}
3336
function bar() {}
34-
export { Foo };
37+
function foo() {
38+
let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
39+
console.log(options);
40+
}
41+
export { Foo, foo };
3542
"
3643
`;
3744

@@ -42,6 +49,9 @@ exports[`should downgrade class private method with output.syntax config 2`] = `
4249
}
4350
#bar() {}
4451
}
45-
export { Foo };
52+
function foo(options = {}) {
53+
console.log(options);
54+
}
55+
export { Foo, foo };
4656
"
4757
`;

0 commit comments

Comments
 (0)