Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 59 additions & 70 deletions packages/core/src/utils/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,94 +50,83 @@ export const ESX_TO_BROWSERSLIST: Record<
Record<LatestEcmaVersions, (target: RsbuildConfigOutputTarget) => string[]> =
{
es5: {
chrome: '5.0.0',
edge: '12.0.0',
firefox: '2.0.0',
ie: '9.0.0',
ios: '6.0.0',
node: '0.4.0',
opera: '10.10.0',
safari: '3.1.0',
chrome: '13',
edge: '12',
firefox: '2',
ios: '6',
node: '0.6',
safari: '5.1',
},
es6: {
chrome: '51.0.0',
edge: '15.0.0',
firefox: '54.0.0',
safari: '10.0.0',
opera: '38.0.0',
samsung: '5.0.0',
get es6() {
return ESX_TO_BROWSERSLIST.es2015;
},
es2015: {
chrome: '51.0.0',
edge: '15.0.0',
firefox: '54.0.0',
safari: '10.0.0',
opera: '38.0.0',
samsung: '5.0.0',
chrome: '51',
edge: '79',
firefox: '53',
ios: '16.3',
node: '6.5',
safari: '16.3',
},
es2016: {
chrome: '52.0.0',
edge: '15.0.0',
firefox: '54.0.0',
safari: '10.3.0',
opera: '39.0.0',
samsung: '6.2.0',
chrome: '52',
edge: '79',
firefox: '53',
ios: '16.3',
node: '7',
safari: '16.3',
},
es2017: {
chrome: '57.0.0',
edge: '15.0.0',
firefox: '54.0.0',
safari: '11.0.0',
opera: '44.0.0',
samsung: '6.2.0',
chrome: '55',
edge: '79',
firefox: '53',
ios: '16.3',
node: '7.6',
safari: '16.3',
},
es2018: {
chrome: '64.0.0',
edge: '79.0.0',
firefox: '78.0.0',
safari: '16.4.0',
opera: '51.0.0',
samsung: '8.2.0',
chrome: '64',
edge: '79',
firefox: '78',
ios: '16.3',
node: '10',
safari: '16.3',
},
es2019: {
chrome: '73.0.0',
edge: '79.0.0',
firefox: '78.0.0',
safari: '17.0.0',
opera: '60.0.0',
samsung: '11.1.0',
chrome: '66',
edge: '79',
firefox: '78',
ios: '16.3',
node: '10',
safari: '16.3',
},
es2020: {
chrome: '80.0.0',
edge: '80.0.0',
firefox: '80.0.0',
safari: '17.0.0',
opera: '67.0.0',
samsung: '13.0.0',
chrome: '91',
edge: '91',
firefox: '80',
ios: '16.3',
node: '16.9',
safari: '16.3',
},
es2021: {
chrome: '85.0.0',
edge: '85.0.0',
firefox: '80.0.0',
safari: '17.0.0',
opera: '71.0.0',
samsung: '14.0.0',
chrome: '91',
edge: '91',
firefox: '80',
ios: '16.3',
node: '16.9',
safari: '16.3',
},
es2022: {
chrome: '94.0.0',
edge: '94.0.0',
firefox: '93.0.0',
safari: '17.0.0',
opera: '80.0.0',
samsung: '17.0.0',
chrome: '94',
edge: '94',
firefox: '93',
ios: '16.4',
node: '16.11',
safari: '16.4',
},
es2023: {
chrome: '110.0.0',
edge: '110.0.0',
firefox: '115.0.0',
safari: '17.0.0',
opera: '96.0.0',
samsung: '21.0.0',
// ES2023 did not introduce new ECMA syntax, so map it to ES2022.
get es2023() {
return ESX_TO_BROWSERSLIST.es2022;
},
es2024: calcEsnextBrowserslistByTarget,
esnext: calcEsnextBrowserslistByTarget,
Expand Down
12 changes: 6 additions & 6 deletions packages/core/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,12 @@ describe('syntax', () => {
composedRsbuildConfig[0]!.config.output?.overrideBrowserslist,
).toMatchInlineSnapshot(`
[
"chrome >= 51.0.0",
"edge >= 15.0.0",
"firefox >= 54.0.0",
"safari >= 10.0.0",
"opera >= 38.0.0",
"samsung >= 5.0.0",
"chrome >= 51",
"edge >= 79",
"firefox >= 53",
"ios >= 16.3",
"node >= 6.5",
"safari >= 16.3",
]
`);
});
Expand Down
70 changes: 33 additions & 37 deletions packages/core/tests/syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ import {
} from '../src/utils/syntax';

const compareSemver = (a: string, b: string) => {
const [aMajor, aMinor, aPatch] = a.split('.').map(Number) as [
number,
number,
number,
];
const [bMajor, bMinor, bPatch] = b.split('.').map(Number) as [
number,
number,
number,
];

if (aMajor !== bMajor) {
return aMajor - bMajor;
}
if (aMinor !== bMinor) {
return aMinor - bMinor;
}
const extract = (v: string) => {
const parts = String(v)
.split('.')
.map((p) => {
return Number(p);
});
while (parts.length < 3) parts.push(0);
return parts.slice(0, 3) as [number, number, number];
};

const [aMajor, aMinor, aPatch] = extract(a);
const [bMajor, bMinor, bPatch] = extract(b);

if (aMajor !== bMajor) return aMajor - bMajor;
if (aMinor !== bMinor) return aMinor - bMinor;
return aPatch - bPatch;
};

Expand Down Expand Up @@ -74,25 +72,25 @@ describe('transformSyntaxToBrowserslist', () => {
transformSyntaxToBrowserslist('es2015', 'web'),
).toMatchInlineSnapshot(`
[
"chrome >= 51.0.0",
"edge >= 15.0.0",
"firefox >= 54.0.0",
"safari >= 10.0.0",
"opera >= 38.0.0",
"samsung >= 5.0.0",
"chrome >= 51",
"edge >= 79",
"firefox >= 53",
"ios >= 16.3",
"node >= 6.5",
"safari >= 16.3",
]
`);

expect(
transformSyntaxToBrowserslist('es2018', 'web'),
).toMatchInlineSnapshot(`
[
"chrome >= 64.0.0",
"edge >= 79.0.0",
"firefox >= 78.0.0",
"safari >= 16.4.0",
"opera >= 51.0.0",
"samsung >= 8.2.0",
"chrome >= 64",
"edge >= 79",
"firefox >= 78",
"ios >= 16.3",
"node >= 10",
"safari >= 16.3",
]
`);

Expand Down Expand Up @@ -147,14 +145,12 @@ describe('transformSyntaxToBrowserslist', () => {
).toMatchInlineSnapshot(`
[
"Chrome 123",
"chrome >= 5.0.0",
"edge >= 12.0.0",
"firefox >= 2.0.0",
"ie >= 9.0.0",
"ios >= 6.0.0",
"node >= 0.4.0",
"opera >= 10.10.0",
"safari >= 3.1.0",
"chrome >= 13",
"edge >= 12",
"firefox >= 2",
"ios >= 6",
"node >= 0.6",
"safari >= 5.1",
]
`);

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cli/build/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('build command', async () => {
const files = await globContentJSON(path.join(fixturePath, 'dist'));
expect(files).toMatchInlineSnapshot(`
{
"<ROOT>/tests/integration/cli/build/no-config/dist/a/index.js": "var withoutConfig = 1000;
"<ROOT>/tests/integration/cli/build/no-config/dist/a/index.js": "const withoutConfig = 1000;
export { withoutConfig };
",
}
Expand Down
7 changes: 3 additions & 4 deletions tests/integration/syntax/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ class Foo {
}
}
function bar() {}
function foo() {
var options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
var a = {};
var b = _object_spread_props(_object_spread({}, a), {
function foo(options = {}) {
const a = {};
const b = _object_spread_props(_object_spread({}, a), {
b: 1
});
console.log(options, b);
Expand Down
Loading