From c1f5ca66768b06d3f11c5659685a6062a5a2d40f Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 30 Aug 2021 18:05:37 +0800 Subject: [PATCH] [eslint] Allow `"latest"` as `ecmaVersion` (#13638) --- .../babel-eslint-parser/src/configuration.cjs | 2 +- .../test/integration/eslint/config.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/eslint/babel-eslint-parser/src/configuration.cjs b/eslint/babel-eslint-parser/src/configuration.cjs index 5cf2e5cc4fa4..11da9fc6c4bf 100644 --- a/eslint/babel-eslint-parser/src/configuration.cjs +++ b/eslint/babel-eslint-parser/src/configuration.cjs @@ -11,7 +11,7 @@ exports.normalizeESLintConfig = function (options) { return { babelOptions: { cwd: process.cwd(), ...babelOptions }, - ecmaVersion, + ecmaVersion: ecmaVersion === "latest" ? 1e8 : ecmaVersion, sourceType, allowImportExportEverywhere, requireConfigFile, diff --git a/eslint/babel-eslint-tests/test/integration/eslint/config.js b/eslint/babel-eslint-tests/test/integration/eslint/config.js index 989e9a8287d0..f0a406d251ee 100644 --- a/eslint/babel-eslint-tests/test/integration/eslint/config.js +++ b/eslint/babel-eslint-tests/test/integration/eslint/config.js @@ -21,4 +21,23 @@ describe("ESLint config", () => { }); expect(messages.length).toEqual(0); }); + + it('should allow ecmaVersion to be "latest"', () => { + const linter = new eslint.Linter(); + linter.defineParser("@babel/eslint-parser", parser); + // ImportDeclarations result in a parser error if ecmaVersion < 2015 and sourceType != "module". + const messages = linter.verify('import { hello } from "greetings"', { + parser: "@babel/eslint-parser", + parserOptions: { + ecmaVersion: "latest", + babelOptions: { + configFile: path.resolve( + path.dirname(fileURLToPath(import.meta.url)), + "../../../../babel-eslint-shared-fixtures/config/babel.config.js", + ), + }, + }, + }); + expect(messages.length).toEqual(0); + }); });