Skip to content

Commit f23264a

Browse files
authored
fix: updates browserlist to support newer js versions (#360)
1 parent e14cffa commit f23264a

File tree

3 files changed

+85
-12
lines changed

3 files changed

+85
-12
lines changed

lib/constants/versions.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ const BROWSER_TO_ES_VERSION = {
7777
18: 9,
7878
79: 10,
7979
80: 11,
80+
85: 12,
81+
93: 13,
82+
97: 14,
83+
117: 15,
84+
136: 16,
8085
},
8186
firefox: {
8287
52: 6,
@@ -85,6 +90,11 @@ const BROWSER_TO_ES_VERSION = {
8590
65: 9,
8691
70: 10,
8792
75: 11,
93+
79: 12,
94+
90: 13,
95+
104: 14,
96+
119: 15,
97+
134: 16,
8898
},
8999
chrome: {
90100
51: 6,
@@ -93,6 +103,11 @@ const BROWSER_TO_ES_VERSION = {
93103
70: 9,
94104
75: 10,
95105
80: 11,
106+
85: 12,
107+
93: 13,
108+
97: 14,
109+
117: 15,
110+
136: 16,
96111
},
97112
safari: {
98113
10: 6,
@@ -101,6 +116,11 @@ const BROWSER_TO_ES_VERSION = {
101116
12: 9,
102117
13: 10,
103118
13.1: 11,
119+
14: 12,
120+
14.1: 13,
121+
15.4: 14,
122+
17: 15,
123+
18.2: 16,
104124
},
105125
opera: {
106126
38: 6,
@@ -109,6 +129,11 @@ const BROWSER_TO_ES_VERSION = {
109129
57: 9,
110130
62: 10,
111131
67: 11,
132+
71: 12,
133+
79: 13,
134+
83: 14,
135+
103: 15,
136+
121: 16,
112137
},
113138
ios_saf: {
114139
10: 6,
@@ -117,14 +142,24 @@ const BROWSER_TO_ES_VERSION = {
117142
12: 9,
118143
13: 10,
119144
13.4: 11,
145+
14: 12,
146+
14.5: 13,
147+
15.4: 14,
148+
17: 15,
149+
18.2: 16,
120150
},
121151
android: {
122152
67: 6,
123153
76: 7,
124154
80: 8,
125-
85: 9,
126-
90: 10,
127-
95: 11,
155+
81: 9,
156+
85: 10,
157+
90: 11,
158+
92: 12,
159+
93: 13,
160+
97: 14,
161+
117: 15,
162+
136: 16,
128163
},
129164
};
130165

tests/unit/browserslist.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ describe("getESVersionFromBrowserslist", () => {
9797
);
9898
});
9999

100-
it("should determine correct ES version for Safari", () => {
100+
it("should determine ES12+ for Safari 14+", () => {
101101
const esVersion = getESVersionFromBrowserslist({
102102
browserslistQuery: "Safari >= 14",
103103
});
104-
assert.strictEqual(esVersion, 11, "ES version should be 11 for Safari 14+");
104+
assert(esVersion >= 12, "ES version should be 12 or higher for Safari 14+");
105105
});
106106

107107
it("should determine correct ES version for modern Chrome versions", () => {
@@ -114,11 +114,11 @@ describe("getESVersionFromBrowserslist", () => {
114114
);
115115
});
116116

117-
it("should determine correct ES version for specific Chrome version (issue #324)", () => {
117+
it("should determine ES14 for Chrome 111", () => {
118118
const esVersion = getESVersionFromBrowserslist({
119119
browserslistQuery: "chrome 111",
120120
});
121-
assert.strictEqual(esVersion, 11, "ES version should be 11 for Chrome 111");
121+
assert.strictEqual(esVersion, 14, "ES version should be 14 for Chrome 111");
122122
});
123123

124124
it("should return ES5 if browserslist throws an error", () => {
@@ -157,16 +157,16 @@ describe("getESVersionForBrowser", () => {
157157
assert.strictEqual(getESVersionForBrowser("firefox", "40"), 6);
158158
});
159159

160-
it("should return ES11 for Chrome 111", () => {
161-
assert.strictEqual(getESVersionForBrowser("chrome", "111"), 11);
160+
it("should return ES14 for Chrome 111", () => {
161+
assert.strictEqual(getESVersionForBrowser("chrome", "111"), 14);
162162
});
163163

164-
it("should return higher ES version for Chrome versions beyond defined mappings", () => {
164+
it("should return ES15 for Chrome 120", () => {
165165
const esVersion = getESVersionForBrowser("chrome", "120");
166166
assert.strictEqual(
167167
esVersion,
168-
11,
169-
"Chrome 120 should map to ES11 (highest defined)",
168+
15,
169+
"Chrome 120 should map to ES15",
170170
);
171171
});
172172
});

tests/unit/helpers/parsers.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,43 @@ describe("helpers/parsers.js", () => {
2222
assert(result.error);
2323
assert.strictEqual(result.ast, null);
2424
});
25+
26+
it("should parse nullish coalescing assignment with ES2021", () => {
27+
const acorn = require("acorn");
28+
const code = "let obj = {}; obj.key ??= 'default';";
29+
const result = parseCode(code, { ecmaVersion: 12 }, acorn, "test.js");
30+
31+
assert.strictEqual(result.error, null);
32+
assert(result.ast);
33+
assert.strictEqual(result.ast.type, "Program");
34+
});
35+
36+
it("should fail to parse nullish coalescing assignment with ES2020", () => {
37+
const acorn = require("acorn");
38+
const code = "let obj = {}; obj.key ??= 'default';";
39+
const result = parseCode(code, { ecmaVersion: 11 }, acorn, "test.js");
40+
41+
assert(result.error);
42+
assert.strictEqual(result.ast, null);
43+
});
44+
45+
it("should parse static initialization blocks with ES2022", () => {
46+
const acorn = require("acorn");
47+
const code = 'class App { static { console.log("hi"); } }';
48+
const result = parseCode(code, { ecmaVersion: 13 }, acorn, "test.js");
49+
50+
assert.strictEqual(result.error, null);
51+
assert(result.ast);
52+
assert.strictEqual(result.ast.type, "Program");
53+
});
54+
55+
it("should fail to parse static initialization blocks with ES2021", () => {
56+
const acorn = require("acorn");
57+
const code = 'class App { static { console.log("hi"); } }';
58+
const result = parseCode(code, { ecmaVersion: 12 }, acorn, "test.js");
59+
60+
assert(result.error);
61+
assert.strictEqual(result.ast, null);
62+
});
2563
});
2664
});

0 commit comments

Comments
 (0)