Skip to content

Commit 15a5850

Browse files
authoredDec 20, 2023
feat: Add builtins check for ES2021 to no-unsupported-features/es-builtins rule (#153)
the change was borrowed from mysticatea#284 credits goes to @ota-meshi. :) Signed-off-by: 唯然 <weiran.zsd@outlook.com>
1 parent 6835a10 commit 15a5850

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed
 

‎docs/rules/no-unsupported-features/es-builtins.md

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ The `"ignores"` option accepts an array of the following strings.
4848

4949
<details>
5050

51+
**ES2021:**
52+
53+
- `"AggregateError"`
54+
- `"Promise.any"`
55+
- `"WeakRef"`
56+
- `"FinalizationRegistry"`
57+
5158
**ES2020:**
5259

5360
- `"BigInt"`

‎lib/rules/no-unsupported-features/es-builtins.js

+10
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ const getConfiguredNodeVersion = require("../../util/get-configured-node-version
1414

1515
const trackMap = {
1616
globals: {
17+
AggregateError: {
18+
[READ]: { supported: "15.0.0" },
19+
},
1720
Array: {
1821
from: { [READ]: { supported: "4.0.0" } },
1922
of: { [READ]: { supported: "4.0.0" } },
2023
},
2124
BigInt: {
2225
[READ]: { supported: "10.4.0" },
2326
},
27+
FinalizationRegistry: {
28+
[READ]: { supported: "14.6.0" },
29+
},
2430
Map: {
2531
[READ]: { supported: "0.12.0" },
2632
},
@@ -67,6 +73,7 @@ const trackMap = {
6773
Promise: {
6874
[READ]: { supported: "0.12.0" },
6975
allSettled: { [READ]: { supported: "12.9.0" } },
76+
any: { [READ]: { supported: "15.0.0" } },
7077
},
7178
Proxy: {
7279
[READ]: { supported: "6.0.0" },
@@ -123,6 +130,9 @@ const trackMap = {
123130
WeakMap: {
124131
[READ]: { supported: "0.12.0" },
125132
},
133+
WeakRef: {
134+
[READ]: { supported: "14.6.0" },
135+
},
126136
WeakSet: {
127137
[READ]: { supported: "0.12.0" },
128138
},

‎tests/lib/rules/no-unsupported-features/es-builtins.js

+136
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,31 @@ ruleTester.run(
7272
"no-unsupported-features/es-builtins",
7373
rule,
7474
concat([
75+
{
76+
keyword: "AggregateError",
77+
valid: [
78+
{
79+
code: "if (error instanceof AggregateError) {}",
80+
options: [{ version: "15.0.0" }],
81+
},
82+
],
83+
invalid: [
84+
{
85+
code: "if (error instanceof AggregateError) {}",
86+
options: [{ version: "14.0.0" }],
87+
errors: [
88+
{
89+
messageId: "unsupported",
90+
data: {
91+
name: "AggregateError",
92+
supported: "15.0.0",
93+
version: "14.0.0",
94+
},
95+
},
96+
],
97+
},
98+
],
99+
},
75100
{
76101
keyword: "Array.from",
77102
valid: [
@@ -185,6 +210,31 @@ ruleTester.run(
185210
},
186211
],
187212
},
213+
{
214+
keyword: "FinalizationRegistry",
215+
valid: [
216+
{
217+
code: "new FinalizationRegistry(() => {})",
218+
options: [{ version: "14.6.0" }],
219+
},
220+
],
221+
invalid: [
222+
{
223+
code: "new FinalizationRegistry(() => {})",
224+
options: [{ version: "14.5.0" }],
225+
errors: [
226+
{
227+
messageId: "unsupported",
228+
data: {
229+
name: "FinalizationRegistry",
230+
supported: "14.6.0",
231+
version: "14.5.0",
232+
},
233+
},
234+
],
235+
},
236+
],
237+
},
188238
{
189239
keyword: "Map",
190240
valid: [
@@ -1209,6 +1259,49 @@ ruleTester.run(
12091259
},
12101260
],
12111261
},
1262+
{
1263+
keyword: "Promise.any",
1264+
valid: [
1265+
{
1266+
code: "(function(Promise) { Promise.any }(a))",
1267+
options: [{ version: "14.0.0" }],
1268+
},
1269+
{
1270+
code: "Promise.any",
1271+
options: [{ version: "15.0.0" }],
1272+
},
1273+
],
1274+
invalid: [
1275+
{
1276+
code: "Promise.any",
1277+
options: [{ version: "14.0.0" }],
1278+
errors: [
1279+
{
1280+
messageId: "unsupported",
1281+
data: {
1282+
name: "Promise.any",
1283+
supported: "15.0.0",
1284+
version: "14.0.0",
1285+
},
1286+
},
1287+
],
1288+
},
1289+
{
1290+
code: "function wrap() { Promise.any }",
1291+
options: [{ version: "14.0.0" }],
1292+
errors: [
1293+
{
1294+
messageId: "unsupported",
1295+
data: {
1296+
name: "Promise.any",
1297+
supported: "15.0.0",
1298+
version: "14.0.0",
1299+
},
1300+
},
1301+
],
1302+
},
1303+
],
1304+
},
12121305
{
12131306
keyword: "Proxy",
12141307
valid: [
@@ -2006,6 +2099,49 @@ ruleTester.run(
20062099
},
20072100
],
20082101
},
2102+
{
2103+
keyword: "WeakRef",
2104+
valid: [
2105+
{
2106+
code: "(function(WeakRef) { WeakRef }(a))",
2107+
options: [{ version: "14.5.0" }],
2108+
},
2109+
{
2110+
code: "WeakRef",
2111+
options: [{ version: "14.6.0" }],
2112+
},
2113+
],
2114+
invalid: [
2115+
{
2116+
code: "WeakRef",
2117+
options: [{ version: "14.5.0" }],
2118+
errors: [
2119+
{
2120+
messageId: "unsupported",
2121+
data: {
2122+
name: "WeakRef",
2123+
supported: "14.6.0",
2124+
version: "14.5.0",
2125+
},
2126+
},
2127+
],
2128+
},
2129+
{
2130+
code: "function wrap() { WeakRef }",
2131+
options: [{ version: "14.5.0" }],
2132+
errors: [
2133+
{
2134+
messageId: "unsupported",
2135+
data: {
2136+
name: "WeakRef",
2137+
supported: "14.6.0",
2138+
version: "14.5.0",
2139+
},
2140+
},
2141+
],
2142+
},
2143+
],
2144+
},
20092145
{
20102146
keyword: "WeakSet",
20112147
valid: [

0 commit comments

Comments
 (0)
Please sign in to comment.