From bf03daf86ce6f97ba8e2d68ab6e76bd680cab6c1 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Mon, 28 Oct 2024 07:55:23 +0900 Subject: [PATCH] fix: `d` should not be invalid in ES2021 --- src/validator.ts | 2 +- .../{flags-2021.json => flags-2022.json} | 0 .../parser/literal/flags-invalid-2017.json | 14 +++++++++++++ .../parser/literal/flags-invalid-2021.json | 14 +++++++++++++ .../parser/literal/flags-invalid-2023.json | 14 +++++++++++++ .../parser/literal/flags-invalid-5.json | 20 +++++++++++++++++++ 6 files changed, 63 insertions(+), 1 deletion(-) rename test/fixtures/parser/literal/{flags-2021.json => flags-2022.json} (100%) create mode 100644 test/fixtures/parser/literal/flags-invalid-2017.json create mode 100644 test/fixtures/parser/literal/flags-invalid-2021.json create mode 100644 test/fixtures/parser/literal/flags-invalid-2023.json create mode 100644 test/fixtures/parser/literal/flags-invalid-5.json diff --git a/src/validator.ts b/src/validator.ts index 6417ab5..c6c9574 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -3569,7 +3569,7 @@ export class RegExpValidator { validFlags.add(LATIN_SMALL_LETTER_Y) if (this.ecmaVersion >= 2018) { validFlags.add(LATIN_SMALL_LETTER_S) - if (this.ecmaVersion >= 2021) { + if (this.ecmaVersion >= 2022) { validFlags.add(LATIN_SMALL_LETTER_D) if (this.ecmaVersion >= 2024) { validFlags.add(LATIN_SMALL_LETTER_V) diff --git a/test/fixtures/parser/literal/flags-2021.json b/test/fixtures/parser/literal/flags-2022.json similarity index 100% rename from test/fixtures/parser/literal/flags-2021.json rename to test/fixtures/parser/literal/flags-2022.json diff --git a/test/fixtures/parser/literal/flags-invalid-2017.json b/test/fixtures/parser/literal/flags-invalid-2017.json new file mode 100644 index 0000000..2dc3b9c --- /dev/null +++ b/test/fixtures/parser/literal/flags-invalid-2017.json @@ -0,0 +1,14 @@ +{ + "options": { + "strict": true, + "ecmaVersion": 2017 + }, + "patterns": { + "/./s": { + "error": { + "message": "Invalid regular expression: /./s: Invalid flag 's'", + "index": 3 + } + } + } +} \ No newline at end of file diff --git a/test/fixtures/parser/literal/flags-invalid-2021.json b/test/fixtures/parser/literal/flags-invalid-2021.json new file mode 100644 index 0000000..1b45ea2 --- /dev/null +++ b/test/fixtures/parser/literal/flags-invalid-2021.json @@ -0,0 +1,14 @@ +{ + "options": { + "strict": true, + "ecmaVersion": 2021 + }, + "patterns": { + "/./d": { + "error": { + "message": "Invalid regular expression: /./d: Invalid flag 'd'", + "index": 3 + } + } + } +} \ No newline at end of file diff --git a/test/fixtures/parser/literal/flags-invalid-2023.json b/test/fixtures/parser/literal/flags-invalid-2023.json new file mode 100644 index 0000000..d15f2ce --- /dev/null +++ b/test/fixtures/parser/literal/flags-invalid-2023.json @@ -0,0 +1,14 @@ +{ + "options": { + "strict": true, + "ecmaVersion": 2023 + }, + "patterns": { + "/./v": { + "error": { + "message": "Invalid regular expression: /./v: Invalid flag 'v'", + "index": 3 + } + } + } +} \ No newline at end of file diff --git a/test/fixtures/parser/literal/flags-invalid-5.json b/test/fixtures/parser/literal/flags-invalid-5.json new file mode 100644 index 0000000..72cec20 --- /dev/null +++ b/test/fixtures/parser/literal/flags-invalid-5.json @@ -0,0 +1,20 @@ +{ + "options": { + "strict": true, + "ecmaVersion": 5 + }, + "patterns": { + "/./u": { + "error": { + "message": "Invalid regular expression: /./u: Invalid flag 'u'", + "index": 3 + } + }, + "/./y": { + "error": { + "message": "Invalid regular expression: /./y: Invalid flag 'y'", + "index": 3 + } + } + } +} \ No newline at end of file