Skip to content

Commit

Permalink
Update: add ES2019 support in 'no-unsupported-features/es-syntax'
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jul 16, 2018
1 parent 3d79333 commit cb8f504
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/rules/no-unsupported-features/es-syntax.md
Expand Up @@ -64,7 +64,8 @@ The `"ignores"` option accepts an array of the following strings.

**ES2019:**

(nothing)
- `"jsonSuperset"`
- `"optionalCatchBinding"`

**ES2018:**

Expand Down
30 changes: 30 additions & 0 deletions lib/rules/no-unsupported-features/es-syntax.js
Expand Up @@ -326,6 +326,28 @@ const features = {
},
],
},

//--------------------------------------------------------------------------
// ES2019
//--------------------------------------------------------------------------
jsonSuperset: {
ruleId: "no-json-superset",
cases: [
{
supported: "10.0.0",
messageId: "no-json-superset",
},
],
},
optionalCatchBinding: {
ruleId: "no-optional-catch-binding",
cases: [
{
supported: "10.0.0",
messageId: "no-optional-catch-binding",
},
],
},
}
const keywords = Object.keys(features)

Expand Down Expand Up @@ -595,6 +617,14 @@ module.exports = {
"RegExp Unicode property escapes are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
"no-rest-spread-properties":
"Rest/spread properties are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",

//------------------------------------------------------------------
// ES2019
//------------------------------------------------------------------
"no-json-superset":
"'\\u{{code}}' in string literals is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
"no-optional-catch-binding":
"The omission of 'catch' binding is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
},
},
create(context) {
Expand Down
86 changes: 85 additions & 1 deletion tests/lib/rules/no-unsupported-features/es-syntax.js
Expand Up @@ -71,7 +71,7 @@ function concat(patterns) {
}

const ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 2018 },
parserOptions: { ecmaVersion: 2019 },
globals: Object.assign({}, configs.es2015.globals, configs.es2017.globals),
})
ruleTester.run(
Expand Down Expand Up @@ -2292,6 +2292,90 @@ ruleTester.run(
],
},

//----------------------------------------------------------------------
// ES2019
//----------------------------------------------------------------------
{
keyword: "jsonSuperset",
valid: [
{
code: "var s = 'foo'",
options: [{ version: "9.99.99" }],
},
{
code: "var s = '\\\u2028'",
options: [{ version: "9.99.99" }],
},
{
code: "var s = '\\\u2029'",
options: [{ version: "9.99.99" }],
},
{
code: "var s = '\u2028'",
options: [{ version: "10.0.0" }],
},
{
code: "var s = '\u2029'",
options: [{ version: "10.0.0" }],
},
],
invalid: [
{
code: "var s = '\u2028'",
options: [{ version: "9.99.99" }],
errors: [
{
messageId: "no-json-superset",
data: {
code: "2028",
supported: "10.0.0",
version: "9.99.99",
},
},
],
},
{
code: "var s = '\u2029'",
options: [{ version: "9.99.99" }],
errors: [
{
messageId: "no-json-superset",
data: {
code: "2029",
supported: "10.0.0",
version: "9.99.99",
},
},
],
},
],
},
{
keyword: "optionalCatchBinding",
valid: [
{
code: "try {} catch {}",
options: [{ version: "10.0.0" }],
},
{
code: "try {} catch (error) {}",
options: [{ version: "9.99.99" }],
},
],
invalid: [
{
code: "try {} catch {}",
options: [{ version: "9.99.99" }],
errors: [
{
messageId: "no-optional-catch-binding",
data: { supported: "10.0.0", version: "9.99.99" },
},
],
},
],
},

//----------------------------------------------------------------------
// MISC
//----------------------------------------------------------------------
Expand Down

0 comments on commit cb8f504

Please sign in to comment.