Skip to content

Commit

Permalink
💥 Allow dynamic import for Node.js >=12.17 <13 || >=13.2
Browse files Browse the repository at this point in the history
* Extend case.supported to support explicit Range instances
* Update error string
* Update tests to check around those constraints
  • Loading branch information
nazrhyn committed Jun 12, 2021
1 parent f45c614 commit 7f5f729
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
20 changes: 1 addition & 19 deletions lib/rules/no-unsupported-features/es-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,24 +383,6 @@ const features = {
},
],
},
optionalChaining: {
ruleId: "no-optional-chaining",
cases: [
{
supported: "14.0.0",
messageId: "no-optional-chaining",
},
],
},
nullishCoalescingOperators: {
ruleId: "no-nullish-coalescing-operators",
cases: [
{
supported: "14.0.0",
messageId: "no-nullish-coalescing-operators",
},
],
},
}
const keywords = Object.keys(features)

Expand Down Expand Up @@ -646,7 +628,7 @@ module.exports = {
"no-bigint-property-names":
"Bigint literal property names are not supported yet.",
"no-dynamic-import":
"'import()' expressions are not supported yet.",
"'import()' expressions are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
"no-optional-chaining":
"Optional chainings are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
"no-nullish-coalescing-operators":
Expand Down
21 changes: 11 additions & 10 deletions tests/lib/rules/no-unsupported-features/es-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
const path = require("path")
const { Linter, RuleTester } = require("eslint")
const { builtin } = require("globals")
const { Range } = require("semver")
const rule = require("../../../../lib/rules/no-unsupported-features/es-syntax")

const ES2020Supported = (() => {
Expand Down Expand Up @@ -2489,27 +2490,27 @@ ruleTester.run(
code: "obj.import(source)",
options: [{ version: "12.0.0" }],
},
{
...["12.17.0", "13.2.0"].map(v => ({
code: "import(source)",
options: [
{ version: "13.1.0", ignores: ["dynamicImport"] },
],
},
options: [{ version: v }],
})),
],
invalid: [
{
...["12.16.0", "13.0.0", "13.1.0"].map(v => ({
code: "import(source)",
options: [{ version: "13.3.0" }],
options: [{ version: v }],
errors: [
{
messageId: "no-dynamic-import",
data: {
supported: null,
version: "13.3.0",
supported: new Range(
">=12.17 <13 || >=13.2"
).toString(),
version: v,
},
},
],
},
})),
],
},
{
Expand Down

0 comments on commit 7f5f729

Please sign in to comment.