From 7f5f729db5d1f0383a05dbfddb0cc34867bdc508 Mon Sep 17 00:00:00 2001 From: Chris Harwood Date: Fri, 19 Feb 2021 14:03:56 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20Allow=20dynamic=20import=20for?= =?UTF-8?q?=20Node.js=20>=3D12.17=20<13=20||=20>=3D13.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Extend case.supported to support explicit Range instances * Update error string * Update tests to check around those constraints --- .../no-unsupported-features/es-syntax.js | 20 +----------------- .../no-unsupported-features/es-syntax.js | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/lib/rules/no-unsupported-features/es-syntax.js b/lib/rules/no-unsupported-features/es-syntax.js index 9cde512e..f73bc92a 100644 --- a/lib/rules/no-unsupported-features/es-syntax.js +++ b/lib/rules/no-unsupported-features/es-syntax.js @@ -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) @@ -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": diff --git a/tests/lib/rules/no-unsupported-features/es-syntax.js b/tests/lib/rules/no-unsupported-features/es-syntax.js index caef9858..b492970a 100644 --- a/tests/lib/rules/no-unsupported-features/es-syntax.js +++ b/tests/lib/rules/no-unsupported-features/es-syntax.js @@ -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 = (() => { @@ -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, }, }, ], - }, + })), ], }, {