From bff8a137de791d455c23ee437ff25f4436825b90 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Wed, 24 May 2023 19:06:29 +0900 Subject: [PATCH 1/2] feat: Support ES2024 and regexp v flag --- README.md | 10 +- lib/options.js | 3 +- ...alid-regexp-class-set-expression.result.js | 6 + ...invalid-regexp-class-set-expression.src.js | 1 + .../invalid-regexp-string-negate.result.js | 6 + .../invalid-regexp-string-negate.src.js | 1 + .../invalid-regexp-unicode-property.result.js | 6 + .../invalid-regexp-unicode-property.src.js | 1 + .../invalid-regexp-v-flag.result.js | 6 + .../invalid-regexp-v-flag.src.js | 1 + .../valid-regexp-v-flag.result.js | 458 ++++++++++++++++++ .../regexp-v-flag/valid-regexp-v-flag.src.js | 6 + tests/lib/supported-ecmaversions.js | 4 +- 13 files changed, 501 insertions(+), 8 deletions(-) create mode 100644 tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-class-set-expression.result.js create mode 100644 tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-class-set-expression.src.js create mode 100644 tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-string-negate.result.js create mode 100644 tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-string-negate.src.js create mode 100644 tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-unicode-property.result.js create mode 100644 tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-unicode-property.src.js create mode 100644 tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-v-flag.result.js create mode 100644 tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-v-flag.src.js create mode 100644 tests/fixtures/ecma-version/15/regexp-v-flag/valid-regexp-v-flag.result.js create mode 100644 tests/fixtures/ecma-version/15/regexp-v-flag/valid-regexp-v-flag.src.js diff --git a/README.md b/README.md index 8a38f247..87ace4c1 100644 --- a/README.md +++ b/README.md @@ -140,8 +140,8 @@ const options = { // create a top-level tokens array containing all tokens tokens: false, - // Set to 3, 5 (the 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. + // Set to 3, 5 (the default), 6, 7, 8, 9, 10, 11, 12, 13, 14 or 15 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), 2023 (same as 14) or 2024 (same as 15) to use the year-based naming. // You can also set "latest" to use the most recently supported version. ecmaVersion: 3, @@ -231,11 +231,11 @@ We are building on top of Acorn, however, so that we can contribute back and hel ### What ECMAScript features do you support? -Espree supports all ECMAScript 2022 features and partially supports ECMAScript 2023 features. +Espree supports all ECMAScript 2023 features and partially supports ECMAScript 2024 features. -Because ECMAScript 2023 is still under development, we are implementing features as they are finalized. Currently, Espree supports: +Because ECMAScript 2024 is still under development, we are implementing features as they are finalized. Currently, Espree supports: -* [Hashbang grammar](https://github.com/tc39/proposal-hashbang) +* [RegExp v flag with set notation + properties of strings](https://github.com/tc39/proposal-regexp-v-flag) See [finished-proposals.md](https://github.com/tc39/proposals/blob/master/finished-proposals.md) to know what features are finalized. diff --git a/lib/options.js b/lib/options.js index d2848072..1460ac27 100644 --- a/lib/options.js +++ b/lib/options.js @@ -18,7 +18,8 @@ const SUPPORTED_VERSIONS = [ 11, // 2020 12, // 2021 13, // 2022 - 14 // 2023 + 14, // 2023 + 15 // 2024 ]; /** diff --git a/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-class-set-expression.result.js b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-class-set-expression.result.js new file mode 100644 index 00000000..31178530 --- /dev/null +++ b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-class-set-expression.result.js @@ -0,0 +1,6 @@ +export default { + "index": 13, + "lineNumber": 1, + "column": 14, + "message": "Invalid regular expression: /[A&&&]/: Invalid character in character class" +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-class-set-expression.src.js b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-class-set-expression.src.js new file mode 100644 index 00000000..66746200 --- /dev/null +++ b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-class-set-expression.src.js @@ -0,0 +1 @@ +const re1 = /[A&&&]/v; diff --git a/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-string-negate.result.js b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-string-negate.result.js new file mode 100644 index 00000000..079d9d07 --- /dev/null +++ b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-string-negate.result.js @@ -0,0 +1,6 @@ +export default { + "index": 13, + "lineNumber": 1, + "column": 14, + "message": "Invalid regular expression: /[^\\q{abc}]/: Negated character class may contain strings" +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-string-negate.src.js b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-string-negate.src.js new file mode 100644 index 00000000..6bb08a58 --- /dev/null +++ b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-string-negate.src.js @@ -0,0 +1 @@ +const re1 = /[^\q{abc}]/v diff --git a/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-unicode-property.result.js b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-unicode-property.result.js new file mode 100644 index 00000000..61c54b96 --- /dev/null +++ b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-unicode-property.result.js @@ -0,0 +1,6 @@ +export default { + "index": 13, + "lineNumber": 1, + "column": 14, + "message": "Invalid regular expression: /\\P{Basic_Emoji}/: Invalid property name" +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-unicode-property.src.js b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-unicode-property.src.js new file mode 100644 index 00000000..3e1bbb10 --- /dev/null +++ b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-unicode-property.src.js @@ -0,0 +1 @@ +const re1 = /\P{Basic_Emoji}/v diff --git a/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-v-flag.result.js b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-v-flag.result.js new file mode 100644 index 00000000..f9595f33 --- /dev/null +++ b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-v-flag.result.js @@ -0,0 +1,6 @@ +export default { + "index": 13, + "lineNumber": 1, + "column": 14, + "message": "Invalid regular expression flag" +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-v-flag.src.js b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-v-flag.src.js new file mode 100644 index 00000000..4f1f84b1 --- /dev/null +++ b/tests/fixtures/ecma-version/15/regexp-v-flag/invalid-regexp-v-flag.src.js @@ -0,0 +1 @@ +const re1 = /[A&&B]/uv; diff --git a/tests/fixtures/ecma-version/15/regexp-v-flag/valid-regexp-v-flag.result.js b/tests/fixtures/ecma-version/15/regexp-v-flag/valid-regexp-v-flag.result.js new file mode 100644 index 00000000..c983a050 --- /dev/null +++ b/tests/fixtures/ecma-version/15/regexp-v-flag/valid-regexp-v-flag.result.js @@ -0,0 +1,458 @@ +import conditionalRegex from "../../../../lib/conditional-regex-value.js"; + +export default { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "range": [ + 0, + 99 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "range": [ + 0, + 99 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "range": [ + 6, + 98 + ], + "id": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 6, + 10 + ], + "name": "list" + }, + "init": { + "type": "ArrayExpression", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "range": [ + 13, + 98 + ], + "elements": [ + conditionalRegex({ + "type": "Literal", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 19, + 28 + ], + "value": null, + "raw": "/[A&&B]/v", + "regex": { + "pattern": "[A&&B]", + "flags": "v" + } + }), + conditionalRegex({ + "type": "Literal", + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "range": [ + 34, + 43 + ], + "value": null, + "raw": "/[A--B]/v", + "regex": { + "pattern": "[A--B]", + "flags": "v" + } + }), + conditionalRegex({ + "type": "Literal", + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "range": [ + 49, + 71 + ], + "value": null, + "raw": "/[\\q{abc|d}&&[A--B]]/v", + "regex": { + "pattern": "[\\q{abc|d}&&[A--B]]", + "flags": "v" + } + }), + conditionalRegex({ + "type": "Literal", + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 22 + } + }, + "range": [ + 77, + 95 + ], + "value": null, + "raw": "/\\p{Basic_Emoji}/v", + "regex": { + "pattern": "\\p{Basic_Emoji}", + "flags": "v" + } + }) + ] + } + } + ], + "kind": "const" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "const", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 0, + 5 + ] + }, + { + "type": "Identifier", + "value": "list", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 6, + 10 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ] + }, + { + "type": "Punctuator", + "value": "[", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 13, + 14 + ] + }, + { + "type": "RegularExpression", + "value": "/[A&&B]/v", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 19, + 28 + ], + "regex": { + "flags": "v", + "pattern": "[A&&B]" + } + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "range": [ + 28, + 29 + ] + }, + { + "type": "RegularExpression", + "value": "/[A--B]/v", + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "range": [ + 34, + 43 + ], + "regex": { + "flags": "v", + "pattern": "[A--B]" + } + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "range": [ + 43, + 44 + ] + }, + { + "type": "RegularExpression", + "value": "/[\\q{abc|d}&&[A--B]]/v", + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "range": [ + 49, + 71 + ], + "regex": { + "flags": "v", + "pattern": "[\\q{abc|d}&&[A--B]]" + } + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 4, + "column": 26 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "range": [ + 71, + 72 + ] + }, + { + "type": "RegularExpression", + "value": "/\\p{Basic_Emoji}/v", + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 22 + } + }, + "range": [ + 77, + 95 + ], + "regex": { + "flags": "v", + "pattern": "\\p{Basic_Emoji}" + } + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "range": [ + 95, + 96 + ] + }, + { + "type": "Punctuator", + "value": "]", + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "range": [ + 97, + 98 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "range": [ + 98, + 99 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-version/15/regexp-v-flag/valid-regexp-v-flag.src.js b/tests/fixtures/ecma-version/15/regexp-v-flag/valid-regexp-v-flag.src.js new file mode 100644 index 00000000..332a988f --- /dev/null +++ b/tests/fixtures/ecma-version/15/regexp-v-flag/valid-regexp-v-flag.src.js @@ -0,0 +1,6 @@ +const list = [ + /[A&&B]/v, + /[A--B]/v, + /[\q{abc|d}&&[A--B]]/v, + /\p{Basic_Emoji}/v, +]; diff --git a/tests/lib/supported-ecmaversions.js b/tests/lib/supported-ecmaversions.js index 66b3ce86..2fe632fd 100644 --- a/tests/lib/supported-ecmaversions.js +++ b/tests/lib/supported-ecmaversions.js @@ -17,7 +17,7 @@ import * as espree from "../../espree.js"; describe("latestEcmaVersion", () => { it("should return the latest supported ecmaVersion", () => { - assert.strictEqual(espree.latestEcmaVersion, 14); + assert.strictEqual(espree.latestEcmaVersion, 15); }); }); @@ -25,7 +25,7 @@ describe("supportedEcmaVersions", () => { it("should return an array of all supported versions", () => { assert.deepStrictEqual( espree.supportedEcmaVersions, - [3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] + [3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] ); }); }); From 3809b5fb7f2f83db8ea51d7b58e3c9acb4f20fe7 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Sun, 18 Jun 2023 11:43:29 +0900 Subject: [PATCH 2/2] update acorn --- package.json | 2 +- .../11/dynamic-import/invalid-new-import.result.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 34732cd7..ef5664dd 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "funding": "https://opencollective.com/eslint", "license": "BSD-2-Clause", "dependencies": { - "acorn": "^8.8.0", + "acorn": "^8.9.0", "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^3.4.1" }, diff --git a/tests/fixtures/ecma-version/11/dynamic-import/invalid-new-import.result.js b/tests/fixtures/ecma-version/11/dynamic-import/invalid-new-import.result.js index 618f85f4..ea6dad33 100644 --- a/tests/fixtures/ecma-version/11/dynamic-import/invalid-new-import.result.js +++ b/tests/fixtures/ecma-version/11/dynamic-import/invalid-new-import.result.js @@ -1,6 +1,6 @@ export default { - "index": 4, + "index": 10, "lineNumber": 1, - "column": 5, - "message": "Cannot use new with import()" + "column": 11, + "message": "Unexpected token (" }; \ No newline at end of file