Skip to content

Commit 97d9613

Browse files
authored
fix: align esX browserslist expression to caniuse (#1280)
1 parent 9d1e9ab commit 97d9613

File tree

7 files changed

+132
-84
lines changed

7 files changed

+132
-84
lines changed

packages/core/src/utils/syntax.ts

Lines changed: 52 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ const RSPACK_TARGET_UNLISTED_MODERN_ECMA_VERSIONS: EcmaScriptVersion[] = [
4040
] satisfies EcmaScriptVersion[];
4141

4242
/**
43-
* The esX to browserslist mapping is transformed from esbuild:
44-
* https://github.com/evanw/esbuild/blob/main/internal/compat/js_table.go
45-
* It does not completely align with the browserslist query of Rsbuild now:
43+
* The esX to browserslist mapping is transformed from
4644
* https://github.com/rspack-contrib/browserslist-to-es-version
47-
* TODO: align with Rsbuild, we may should align with SWC
4845
*/
4946
export const ESX_TO_BROWSERSLIST: Record<
5047
FixedEcmaVersions,
@@ -63,90 +60,84 @@ export const ESX_TO_BROWSERSLIST: Record<
6360
safari: '3.1.0',
6461
},
6562
es6: {
66-
chrome: '63.0.0',
67-
edge: '79.0.0',
68-
firefox: '67.0.0',
69-
ios: '13.0.0',
70-
node: '13.2.0',
71-
opera: '50.0.0',
72-
safari: '13.0.0',
63+
chrome: '51.0.0',
64+
edge: '15.0.0',
65+
firefox: '54.0.0',
66+
safari: '10.0.0',
67+
opera: '38.0.0',
68+
samsung: '5.0.0',
7369
},
7470
es2015: {
75-
chrome: '63.0.0',
76-
edge: '79.0.0',
77-
firefox: '67.0.0',
78-
ios: '13.0.0',
79-
node: '13.2.0',
80-
opera: '50.0.0',
81-
safari: '13.0.0',
71+
chrome: '51.0.0',
72+
edge: '15.0.0',
73+
firefox: '54.0.0',
74+
safari: '10.0.0',
75+
opera: '38.0.0',
76+
samsung: '5.0.0',
8277
},
8378
es2016: {
84-
chrome: '63.0.0',
85-
edge: '79.0.0',
86-
firefox: '67.0.0',
87-
ios: '13.0.0',
88-
node: '13.2.0',
89-
opera: '50.0.0',
90-
safari: '13.0.0',
79+
chrome: '52.0.0',
80+
edge: '15.0.0',
81+
firefox: '54.0.0',
82+
safari: '10.3.0',
83+
opera: '39.0.0',
84+
samsung: '6.2.0',
9185
},
9286
es2017: {
93-
chrome: '63.0.0',
94-
edge: '79.0.0',
95-
firefox: '67.0.0',
96-
ios: '13.0.0',
97-
node: '13.2.0',
98-
opera: '50.0.0',
99-
safari: '13.0.0',
87+
chrome: '57.0.0',
88+
edge: '15.0.0',
89+
firefox: '54.0.0',
90+
safari: '11.0.0',
91+
opera: '44.0.0',
92+
samsung: '6.2.0',
10093
},
10194
es2018: {
10295
chrome: '64.0.0',
10396
edge: '79.0.0',
10497
firefox: '78.0.0',
105-
ios: '16.4.0',
106-
node: '13.2.0',
107-
opera: '51.0.0',
10898
safari: '16.4.0',
99+
opera: '51.0.0',
100+
samsung: '8.2.0',
109101
},
110102
es2019: {
111-
chrome: '66.0.0',
103+
chrome: '73.0.0',
112104
edge: '79.0.0',
113105
firefox: '78.0.0',
114-
ios: '16.4.0',
115-
node: '13.2.0',
116-
opera: '53.0.0',
117-
safari: '16.4.0',
106+
safari: '17.0.0',
107+
opera: '60.0.0',
108+
samsung: '11.1.0',
118109
},
119110
es2020: {
120-
chrome: '91.0.0',
121-
edge: '91.0.0',
111+
chrome: '80.0.0',
112+
edge: '80.0.0',
122113
firefox: '80.0.0',
123-
ios: '16.4.0',
124-
node: '16.1.0',
125-
opera: '77.0.0',
126-
safari: '16.4.0',
114+
safari: '17.0.0',
115+
opera: '67.0.0',
116+
samsung: '13.0.0',
127117
},
128118
es2021: {
129-
chrome: '91.0.0',
130-
edge: '91.0.0',
119+
chrome: '85.0.0',
120+
edge: '85.0.0',
131121
firefox: '80.0.0',
132-
ios: '16.4.0',
133-
node: '16.1.0',
134-
opera: '77.0.0',
135-
safari: '16.4.0',
122+
safari: '17.0.0',
123+
opera: '71.0.0',
124+
samsung: '14.0.0',
136125
},
137126
es2022: {
138-
chrome: '91.0.0',
127+
chrome: '94.0.0',
128+
edge: '94.0.0',
139129
firefox: '93.0.0',
140-
ios: '16.4.0',
141-
node: '16.11.0',
142-
safari: '16.4.0',
130+
safari: '17.0.0',
131+
opera: '80.0.0',
132+
samsung: '17.0.0',
143133
},
144134
es2023: {
145-
chrome: '91.0.0',
146-
firefox: '93.0.0',
147-
ios: '16.4.0',
148-
node: '16.11.0',
149-
safari: '16.4.0',
135+
chrome: '110.0.0',
136+
edge: '110.0.0',
137+
firefox: '115.0.0',
138+
safari: '17.0.0',
139+
opera: '96.0.0',
140+
samsung: '21.0.0',
150141
},
151142
es2024: calcEsnextBrowserslistByTarget,
152143
esnext: calcEsnextBrowserslistByTarget,

packages/core/tests/config.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,12 @@ describe('syntax', () => {
419419
composedRsbuildConfig[0]!.config.output?.overrideBrowserslist,
420420
).toMatchInlineSnapshot(`
421421
[
422-
"chrome >= 63.0.0",
423-
"edge >= 79.0.0",
424-
"firefox >= 67.0.0",
425-
"ios >= 13.0.0",
426-
"node >= 13.2.0",
427-
"opera >= 50.0.0",
428-
"safari >= 13.0.0",
422+
"chrome >= 51.0.0",
423+
"edge >= 15.0.0",
424+
"firefox >= 54.0.0",
425+
"safari >= 10.0.0",
426+
"opera >= 38.0.0",
427+
"samsung >= 5.0.0",
429428
]
430429
`);
431430
});

packages/core/tests/syntax.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,12 @@ describe('transformSyntaxToBrowserslist', () => {
7474
transformSyntaxToBrowserslist('es2015', 'web'),
7575
).toMatchInlineSnapshot(`
7676
[
77-
"chrome >= 63.0.0",
78-
"edge >= 79.0.0",
79-
"firefox >= 67.0.0",
80-
"ios >= 13.0.0",
81-
"node >= 13.2.0",
82-
"opera >= 50.0.0",
83-
"safari >= 13.0.0",
77+
"chrome >= 51.0.0",
78+
"edge >= 15.0.0",
79+
"firefox >= 54.0.0",
80+
"safari >= 10.0.0",
81+
"opera >= 38.0.0",
82+
"samsung >= 5.0.0",
8483
]
8584
`);
8685

@@ -91,10 +90,9 @@ describe('transformSyntaxToBrowserslist', () => {
9190
"chrome >= 64.0.0",
9291
"edge >= 79.0.0",
9392
"firefox >= 78.0.0",
94-
"ios >= 16.4.0",
95-
"node >= 13.2.0",
96-
"opera >= 51.0.0",
9793
"safari >= 16.4.0",
94+
"opera >= 51.0.0",
95+
"samsung >= 8.2.0",
9896
]
9997
`);
10098

tests/integration/cli/build/build.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe('build command', async () => {
153153
const files = await globContentJSON(path.join(fixturePath, 'dist'));
154154
expect(files).toMatchInlineSnapshot(`
155155
{
156-
"<ROOT>/tests/integration/cli/build/no-config/dist/a/index.js": "const withoutConfig = 1000;
156+
"<ROOT>/tests/integration/cli/build/no-config/dist/a/index.js": "var withoutConfig = 1000;
157157
export { withoutConfig };
158158
",
159159
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ export class Foo {
77
}
88

99
export function foo(options: unknown = {}): void {
10-
console.log(options);
10+
const a = {};
11+
const b = { ...a, b: 1 };
12+
console.log(options, b);
1113
}

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

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ exports[`should downgrade class private method by default 1`] = `
88
#bar() {}
99
}
1010
function foo(options = {}) {
11-
console.log(options);
11+
const a = {};
12+
const b = {
13+
...a,
14+
b: 1
15+
};
16+
console.log(options, b);
1217
}
1318
export { Foo, foo };
1419
"
@@ -26,6 +31,48 @@ function _class_private_method_init(obj, privateSet) {
2631
_check_private_redeclaration(obj, privateSet);
2732
privateSet.add(obj);
2833
}
34+
function _define_property(obj, key, value) {
35+
if (key in obj) Object.defineProperty(obj, key, {
36+
value: value,
37+
enumerable: true,
38+
configurable: true,
39+
writable: true
40+
});
41+
else obj[key] = value;
42+
return obj;
43+
}
44+
function _object_spread(target) {
45+
for(var i = 1; i < arguments.length; i++){
46+
var source = null != arguments[i] ? arguments[i] : {};
47+
var ownKeys = Object.keys(source);
48+
if ("function" == typeof Object.getOwnPropertySymbols) ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50+
}));
51+
ownKeys.forEach(function(key) {
52+
_define_property(target, key, source[key]);
53+
});
54+
}
55+
return target;
56+
}
57+
function src_ownKeys(object, enumerableOnly) {
58+
var keys = Object.keys(object);
59+
if (Object.getOwnPropertySymbols) {
60+
var symbols = Object.getOwnPropertySymbols(object);
61+
if (enumerableOnly) symbols = symbols.filter(function(sym) {
62+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
63+
});
64+
keys.push.apply(keys, symbols);
65+
}
66+
return keys;
67+
}
68+
function _object_spread_props(target, source) {
69+
source = null != source ? source : {};
70+
if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
71+
else src_ownKeys(Object(source)).forEach(function(key) {
72+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
73+
});
74+
return target;
75+
}
2976
var _bar = /*#__PURE__*/ new WeakSet();
3077
class Foo {
3178
constructor(){
@@ -35,8 +82,12 @@ class Foo {
3582
}
3683
function bar() {}
3784
function foo() {
38-
let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
39-
console.log(options);
85+
var options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
86+
var a = {};
87+
var b = _object_spread_props(_object_spread({}, a), {
88+
b: 1
89+
});
90+
console.log(options, b);
4091
}
4192
export { Foo, foo };
4293
"
@@ -50,7 +101,12 @@ exports[`should downgrade class private method with output.syntax config 2`] = `
50101
#bar() {}
51102
}
52103
function foo(options = {}) {
53-
console.log(options);
104+
const a = {};
105+
const b = {
106+
...a,
107+
b: 1
108+
};
109+
console.log(options, b);
54110
}
55111
export { Foo, foo };
56112
"

tests/integration/syntax/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ test('should downgrade class private method with output.syntax config', async ()
1818

1919
expect(entries.esm0).toMatchSnapshot();
2020
expect(entries.esm0).not.toContain('#bar');
21+
expect(entries.esm0).not.toContain('...a');
2122

2223
expect(entries.esm1).toMatchSnapshot();
2324
expect(entries.esm1).toContain('#bar');
25+
expect(entries.esm1).toContain('...a');
2426

2527
expect(entries.cjs0).toContain('#bar');
2628
expect(entries.cjs0).toContain('()=>{'); // test webpack runtime arrow function

0 commit comments

Comments
 (0)