diff --git a/docs/rules/no-unsupported-features/es-syntax.md b/docs/rules/no-unsupported-features/es-syntax.md index 0b0652f7..f4eccaec 100644 --- a/docs/rules/no-unsupported-features/es-syntax.md +++ b/docs/rules/no-unsupported-features/es-syntax.md @@ -12,11 +12,11 @@ Editor integrations of ESLint would be useful to know it in real-time. ### Supported ECMAScript features -This rule supports ECMAScript 2019. +This rule supports ECMAScript 2019 and proposals that have been approved as Stage 4 by August 2019. See also [TC39 finished proposals](https://github.com/tc39/proposals/blob/master/finished-proposals.md). Please configure your `.eslintrc` file to succeed to succeed in parsing the syntax. -For example, set `2019` to `parserOptions.ecmaVersion`. +For example, set `2020` to `parserOptions.ecmaVersion`. ### Configured Node.js version range @@ -64,6 +64,11 @@ The `"ignores"` option accepts an array of the following strings.
+**ES2020:** + +- `"bigint"` +- `"dynamicImport"` + **ES2019:** - `"jsonSuperset"` diff --git a/lib/rules/no-unsupported-features/es-syntax.js b/lib/rules/no-unsupported-features/es-syntax.js index 3aa0d893..e4057212 100644 --- a/lib/rules/no-unsupported-features/es-syntax.js +++ b/lib/rules/no-unsupported-features/es-syntax.js @@ -349,6 +349,29 @@ const features = { }, ], }, + + //-------------------------------------------------------------------------- + // ES2020 + //-------------------------------------------------------------------------- + bigint: { + ruleId: "no-bigint", + cases: [ + { + supported: "10.4.0", + test: info => info.node.type === "Literal", + messageId: "no-bigint", + }, + ], + }, + dynamicImport: { + ruleId: "no-dynamic-import", + cases: [ + { + supported: null, + messageId: "no-dynamic-import", + }, + ], + }, } const keywords = Object.keys(features) @@ -620,6 +643,14 @@ module.exports = { "'\\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}}'.", + + //------------------------------------------------------------------ + // ES2020 + //------------------------------------------------------------------ + "no-bigint": + "Bigint literals are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.", + "no-dynamic-import": + "'import()' expressions are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.", }, }, create(context) { diff --git a/package.json b/package.json index f2908bbe..c0a2ffe9 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "eslint": ">=5.16.0" }, "dependencies": { - "eslint-plugin-es": "^1.4.1", + "eslint-plugin-es": "^2.0.0", "eslint-utils": "^1.4.2", "ignore": "^5.1.1", "minimatch": "^3.0.4", @@ -23,7 +23,7 @@ "devDependencies": { "@mysticatea/eslint-plugin": "^10.0.3", "codecov": "^3.3.0", - "eslint": "^5.16.0", + "eslint": "^6.3.0", "eslint-plugin-node": "file:.", "fast-glob": "^2.2.6", "globals": "^11.12.0", diff --git a/tests/lib/rules/no-unsupported-features/es-syntax.js b/tests/lib/rules/no-unsupported-features/es-syntax.js index ea0b12cc..5043ae38 100644 --- a/tests/lib/rules/no-unsupported-features/es-syntax.js +++ b/tests/lib/rules/no-unsupported-features/es-syntax.js @@ -5,10 +5,17 @@ "use strict" const path = require("path") -const { RuleTester } = require("eslint") -const globals = require("globals") +const { Linter, RuleTester } = require("eslint") +const { builtin } = require("globals") const rule = require("../../../../lib/rules/no-unsupported-features/es-syntax") +const ES2020Supported = (() => { + const config = { parserOptions: { ecmaVersion: 2020 } } + const messages = new Linter().verify("0n", config) + return messages.length === 0 +})() +const ecmaVersion = ES2020Supported ? 2020 : 2019 + /** * Makes a file path to a fixture. * @param {string} name - A name. @@ -57,7 +64,11 @@ function concat(patterns) { invalid: [], } - for (const { keyword, valid, invalid } of patterns) { + for (const { requiredEcmaVersion, keyword, valid, invalid } of patterns) { + if (requiredEcmaVersion && ecmaVersion < requiredEcmaVersion) { + continue + } + ret.valid.push(...valid) ret.invalid.push(...invalid) @@ -71,8 +82,8 @@ function concat(patterns) { } const ruleTester = new RuleTester({ - parserOptions: { ecmaVersion: 2019 }, - globals: globals.es2017, + parserOptions: { ecmaVersion }, + globals: builtin, }) ruleTester.run( "no-unsupported-features/es-syntax", @@ -2376,6 +2387,72 @@ ruleTester.run( ], }, + //---------------------------------------------------------------------- + // ES2020 + //---------------------------------------------------------------------- + { + keyword: "bigint", + requiredEcmaVersion: 2020, + valid: [ + { + code: "var n = 0n", + options: [{ version: "10.4.0" }], + }, + { + code: "var n = BigInt(0)", + options: [{ version: "10.3.0" }], + }, + { + code: "var n = new BigInt64Array()", + options: [{ version: "10.3.0" }], + }, + { + code: "var n = new BigUint64Array()", + options: [{ version: "10.3.0" }], + }, + ], + invalid: [ + { + code: "var n = 0n", + options: [{ version: "10.3.0" }], + errors: [ + { + messageId: "no-bigint", + data: { + supported: "10.4.0", + version: "10.3.0", + }, + }, + ], + }, + ], + }, + { + keyword: "dynamicImport", + requiredEcmaVersion: 2020, + valid: [ + { + code: "obj.import(source)", + options: [{ version: "12.0.0" }], + }, + ], + invalid: [ + { + code: "import(source)", + options: [{ version: "12.0.0" }], + errors: [ + { + messageId: "no-dynamic-import", + data: { + supported: null, + version: "12.0.0", + }, + }, + ], + }, + ], + }, + //---------------------------------------------------------------------- // MISC //----------------------------------------------------------------------