Skip to content

Commit

Permalink
fix: range matching fails (#31)
Browse files Browse the repository at this point in the history
* fix: range matching fails

fixes #22

* chore: add a test
  • Loading branch information
aladdin-add committed Jul 4, 2022
1 parent 793a48b commit 5a22112
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/rules/no-unsupported-features/es-syntax.js
Expand Up @@ -7,6 +7,7 @@
const { rules: esRules } = require("eslint-plugin-es")
const { getInnermostScope } = require("eslint-utils")
const { Range } = require("semver")
const rangeSubset = require("semver/ranges/subset")
const getConfiguredNodeVersion = require("../../util/get-configured-node-version")
const getSemverRange = require("../../util/get-semver-range")
const mergeVisitorsInPlace = require("../../util/merge-visitors-in-place")
Expand Down Expand Up @@ -457,11 +458,11 @@ function defineVisitor(context, options) {
return true
}

if (aCase.supported instanceof Range) {
return !options.version.intersects(aCase.supported)
}

return options.version.intersects(getSemverRange(`<${aCase.supported}`))
const supported =
typeof aCase.supported === "string"
? getSemverRange(`>=${aCase.supported}`)
: aCase.supported
return !rangeSubset(options.version, supported)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/no-unsupported-features/es-syntax.js
Expand Up @@ -2493,7 +2493,7 @@ ruleTester.run(
})),
],
invalid: [
...["12.16.0", "13.0.0", "13.1.0"].map(v => ({
...["12.16.0", "13.0.0", "13.1.0", ">=8.0.0"].map(v => ({
code: "import(source)",
options: [{ version: v }],
errors: [
Expand Down

0 comments on commit 5a22112

Please sign in to comment.