Skip to content

Commit

Permalink
feat: Add builtins check for ES2021 to no-unsupported-features/es-bui…
Browse files Browse the repository at this point in the history
…ltins rule

the change was borrowed from mysticatea#284

credits goes to @ota-meshi. :)

Signed-off-by: 唯然 <[email protected]>
  • Loading branch information
aladdin-add committed Dec 20, 2023
1 parent 6409e34 commit 4175633
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/rules/no-unsupported-features/es-builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ The `"ignores"` option accepts an array of the following strings.

<details>

**ES2021:**

- `"AggregateError"`
- `"Promise.any"`
- `"WeakRef"`
- `"FinalizationRegistry"`

**ES2020:**

- `"BigInt"`
Expand Down
10 changes: 10 additions & 0 deletions lib/rules/no-unsupported-features/es-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ const getConfiguredNodeVersion = require("../../util/get-configured-node-version

const trackMap = {
globals: {
AggregateError: {
[READ]: { supported: "15.0.0" },
},
Array: {
from: { [READ]: { supported: "4.0.0" } },
of: { [READ]: { supported: "4.0.0" } },
},
BigInt: {
[READ]: { supported: "10.4.0" },
},
FinalizationRegistry: {
[READ]: { supported: "14.6.0" },
},
Map: {
[READ]: { supported: "0.12.0" },
},
Expand Down Expand Up @@ -67,6 +73,7 @@ const trackMap = {
Promise: {
[READ]: { supported: "0.12.0" },
allSettled: { [READ]: { supported: "12.9.0" } },
any: { [READ]: { supported: "15.0.0" } },
},
Proxy: {
[READ]: { supported: "6.0.0" },
Expand Down Expand Up @@ -123,6 +130,9 @@ const trackMap = {
WeakMap: {
[READ]: { supported: "0.12.0" },
},
WeakRef: {
[READ]: { supported: "14.6.0" },
},
WeakSet: {
[READ]: { supported: "0.12.0" },
},
Expand Down
136 changes: 136 additions & 0 deletions tests/lib/rules/no-unsupported-features/es-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ ruleTester.run(
"no-unsupported-features/es-builtins",
rule,
concat([
{
keyword: "AggregateError",
valid: [
{
code: "if (error instanceof AggregateError) {}",
options: [{ version: "15.0.0" }],
},
],
invalid: [
{
code: "if (error instanceof AggregateError) {}",
options: [{ version: "14.0.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "AggregateError",
supported: "15.0.0",
version: "14.0.0",
},
},
],
},
],
},
{
keyword: "Array.from",
valid: [
Expand Down Expand Up @@ -185,6 +210,31 @@ ruleTester.run(
},
],
},
{
keyword: "FinalizationRegistry",
valid: [
{
code: "new FinalizationRegistry(() => {})",
options: [{ version: "14.6.0" }],
},
],
invalid: [
{
code: "new FinalizationRegistry(() => {})",
options: [{ version: "14.5.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "FinalizationRegistry",
supported: "14.6.0",
version: "14.5.0",
},
},
],
},
],
},
{
keyword: "Map",
valid: [
Expand Down Expand Up @@ -1209,6 +1259,49 @@ ruleTester.run(
},
],
},
{
keyword: "Promise.any",
valid: [
{
code: "(function(Promise) { Promise.any }(a))",
options: [{ version: "14.0.0" }],
},
{
code: "Promise.any",
options: [{ version: "15.0.0" }],
},
],
invalid: [
{
code: "Promise.any",
options: [{ version: "14.0.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "Promise.any",
supported: "15.0.0",
version: "14.0.0",
},
},
],
},
{
code: "function wrap() { Promise.any }",
options: [{ version: "14.0.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "Promise.any",
supported: "15.0.0",
version: "14.0.0",
},
},
],
},
],
},
{
keyword: "Proxy",
valid: [
Expand Down Expand Up @@ -2006,6 +2099,49 @@ ruleTester.run(
},
],
},
{
keyword: "WeakRef",
valid: [
{
code: "(function(WeakRef) { WeakRef }(a))",
options: [{ version: "14.5.0" }],
},
{
code: "WeakRef",
options: [{ version: "14.6.0" }],
},
],
invalid: [
{
code: "WeakRef",
options: [{ version: "14.5.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "WeakRef",
supported: "14.6.0",
version: "14.5.0",
},
},
],
},
{
code: "function wrap() { WeakRef }",
options: [{ version: "14.5.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "WeakRef",
supported: "14.6.0",
version: "14.5.0",
},
},
],
},
],
},
{
keyword: "WeakSet",
valid: [
Expand Down

0 comments on commit 4175633

Please sign in to comment.