Skip to content

Commit 7f5f729

Browse files
committed
💥 Allow dynamic import for Node.js >=12.17 <13 || >=13.2
* Extend case.supported to support explicit Range instances * Update error string * Update tests to check around those constraints
1 parent f45c614 commit 7f5f729

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -383,24 +383,6 @@ const features = {
383383
},
384384
],
385385
},
386-
optionalChaining: {
387-
ruleId: "no-optional-chaining",
388-
cases: [
389-
{
390-
supported: "14.0.0",
391-
messageId: "no-optional-chaining",
392-
},
393-
],
394-
},
395-
nullishCoalescingOperators: {
396-
ruleId: "no-nullish-coalescing-operators",
397-
cases: [
398-
{
399-
supported: "14.0.0",
400-
messageId: "no-nullish-coalescing-operators",
401-
},
402-
],
403-
},
404386
}
405387
const keywords = Object.keys(features)
406388

@@ -646,7 +628,7 @@ module.exports = {
646628
"no-bigint-property-names":
647629
"Bigint literal property names are not supported yet.",
648630
"no-dynamic-import":
649-
"'import()' expressions are not supported yet.",
631+
"'import()' expressions are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
650632
"no-optional-chaining":
651633
"Optional chainings are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
652634
"no-nullish-coalescing-operators":

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
const path = require("path")
88
const { Linter, RuleTester } = require("eslint")
99
const { builtin } = require("globals")
10+
const { Range } = require("semver")
1011
const rule = require("../../../../lib/rules/no-unsupported-features/es-syntax")
1112

1213
const ES2020Supported = (() => {
@@ -2489,27 +2490,27 @@ ruleTester.run(
24892490
code: "obj.import(source)",
24902491
options: [{ version: "12.0.0" }],
24912492
},
2492-
{
2493+
...["12.17.0", "13.2.0"].map(v => ({
24932494
code: "import(source)",
2494-
options: [
2495-
{ version: "13.1.0", ignores: ["dynamicImport"] },
2496-
],
2497-
},
2495+
options: [{ version: v }],
2496+
})),
24982497
],
24992498
invalid: [
2500-
{
2499+
...["12.16.0", "13.0.0", "13.1.0"].map(v => ({
25012500
code: "import(source)",
2502-
options: [{ version: "13.3.0" }],
2501+
options: [{ version: v }],
25032502
errors: [
25042503
{
25052504
messageId: "no-dynamic-import",
25062505
data: {
2507-
supported: null,
2508-
version: "13.3.0",
2506+
supported: new Range(
2507+
">=12.17 <13 || >=13.2"
2508+
).toString(),
2509+
version: v,
25092510
},
25102511
},
25112512
],
2512-
},
2513+
})),
25132514
],
25142515
},
25152516
{

0 commit comments

Comments
 (0)