diff --git a/conf/globals.js b/conf/globals.js index 076ffb2af94..6018b7af15c 100644 --- a/conf/globals.js +++ b/conf/globals.js @@ -124,6 +124,10 @@ const es2022 = { ...es2021 }; +const es2023 = { + ...es2022 +}; + //----------------------------------------------------------------------------- // Exports @@ -140,5 +144,6 @@ module.exports = { es2019, es2020, es2021, - es2022 + es2022, + es2023 }; diff --git a/docs/src/user-guide/configuring/language-options.md b/docs/src/user-guide/configuring/language-options.md index 4acc15c4d8c..1ec3233e4d6 100644 --- a/docs/src/user-guide/configuring/language-options.md +++ b/docs/src/user-guide/configuring/language-options.md @@ -194,7 +194,7 @@ For ES6 syntax, use `{ "parserOptions": { "ecmaVersion": 6 } }`; for new ES6 glo Parser options are set in your `.eslintrc.*` file by using the `parserOptions` property. The available options are: -* `ecmaVersion` - set to 3, 5 (default), 6, 7, 8, 9, 10, 11, 12, or 13 to specify the version of ECMAScript syntax you want to use. You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), 2021 (same as 12), or 2022 (same as 13) to use the year-based naming. You can also set "latest" to use the most recently supported version. +* `ecmaVersion` - set to 3, 5 (default), 6, 7, 8, 9, 10, 11, 12, 13, or 14 to specify the version of ECMAScript syntax you want to use. You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), 2021 (same as 12), 2022 (same as 13), or 2023 (same as 14) to use the year-based naming. You can also set "latest" to use the most recently supported version. * `sourceType` - set to `"script"` (default) or `"module"` if your code is in ECMAScript modules. * `allowReserved` - allow the use of reserved words as identifiers (if `ecmaVersion` is 3). * `ecmaFeatures` - an object indicating which additional language features you'd like to use: diff --git a/lib/rules/utils/ast-utils.js b/lib/rules/utils/ast-utils.js index f919f5a26c8..e6c4aaeca0a 100644 --- a/lib/rules/utils/ast-utils.js +++ b/lib/rules/utils/ast-utils.js @@ -1978,7 +1978,7 @@ module.exports = { if (comments.length) { const lastComment = comments[comments.length - 1]; - if (lastComment.range[0] > leftToken.range[0]) { + if (!leftToken || lastComment.range[0] > leftToken.range[0]) { leftToken = lastComment; } } @@ -1986,7 +1986,13 @@ module.exports = { leftToken = leftValue; } - if (leftToken.type === "Shebang") { + /* + * If a hashbang comment was passed as a token object from SourceCode, + * its type will be "Shebang" because of the way ESLint itself handles hashbangs. + * If a hashbang comment was passed in a string and then tokenized in this function, + * its type will be "Hashbang" because of the way Espree tokenizes hashbangs. + */ + if (leftToken.type === "Shebang" || leftToken.type === "Hashbang") { return false; } @@ -2007,7 +2013,7 @@ module.exports = { if (comments.length) { const firstComment = comments[0]; - if (firstComment.range[0] < rightToken.range[0]) { + if (!rightToken || firstComment.range[0] < rightToken.range[0]) { rightToken = firstComment; } } diff --git a/lib/shared/types.js b/lib/shared/types.js index 5d9a4e6cf26..60f9f1d6afe 100644 --- a/lib/shared/types.js +++ b/lib/shared/types.js @@ -21,7 +21,7 @@ module.exports = {}; /** * @typedef {Object} ParserOptions * @property {EcmaFeatures} [ecmaFeatures] The optional features. - * @property {3|5|6|7|8|9|10|11|12|13|2015|2016|2017|2018|2019|2020|2021|2022} [ecmaVersion] The ECMAScript version (or revision number). + * @property {3|5|6|7|8|9|10|11|12|13|14|2015|2016|2017|2018|2019|2020|2021|2022|2023} [ecmaVersion] The ECMAScript version (or revision number). * @property {"script"|"module"} [sourceType] The source code type. * @property {boolean} [allowReserved] Allowing the use of reserved words as identifiers in ES3. */ diff --git a/package.json b/package.json index 1c119318d6d..b276515cacf 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "eslint-scope": "^7.1.1", "eslint-utils": "^3.0.0", "eslint-visitor-keys": "^3.3.0", - "espree": "^9.3.3", + "espree": "^9.4.0", "esquery": "^1.4.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", diff --git a/tests/lib/rules/utils/ast-utils.js b/tests/lib/rules/utils/ast-utils.js index 1cd8727b46b..c36a9ac0e25 100644 --- a/tests/lib/rules/utils/ast-utils.js +++ b/tests/lib/rules/utils/ast-utils.js @@ -1486,10 +1486,14 @@ describe("ast-utils", () => { [["a/", "+b"], true], [["a+", "/^regex$/"], true], [["a/", "/^regex$/"], false], + [["a+", "/**/"], true], [["a+", "/**/b"], true], + [["//", "a"], false], [["a/", "/**/b"], false], + [["a+", "//"], true], [["a+", "//\nb"], true], [["a/", "//\nb"], false], + [["/**/", "b"], true], [["a/**/", "b"], true], [["/**/a", "b"], false], [["a", "/**/b"], true],