Skip to content

/v RegExp flag is not recognized in Vitest #5220

@Y3drk

Description

@Y3drk

Describe the bug

When writing a TypeScript (version 5.3.3) library I need a function using RegExp, which has to use the /v flag (trimmed example in test reproduction).

According to MDN docs it should be supported in node 20.0.0+

The function on its own works all right, but when I want to test it with Vitest I receive an error:

 FAIL  tests/index.test.ts [ tests/index.test.ts ]
Error: Unknown regular expression flags.
 ❯ error node_modules/rollup/dist/es/shared/parseAst.js:337:30
 ❯ parseError node_modules/rollup/dist/es/shared/parseAst.js:972:9
 ❯ convertNode node_modules/rollup/dist/es/shared/parseAst.js:2057:12
 ❯ convertProgram node_modules/rollup/dist/es/shared/parseAst.js:965:12
 ❯ parseAstAsync node_modules/rollup/dist/es/shared/parseAst.js:2108:12
 ❯ ssrTransformScript node_modules/vite/dist/node/chunks/dep-stQc5rCc.js:54036:15
 ❯ loadAndTransform node_modules/vite/dist/node/chunks/dep-stQc5rCc.js:53632:11

Reproduction

In a function use regex with /v flag:

export function showcaseVFlag(name: string): string[] {
    const regexp = /(?:\p{RGI_Emoji})|(?:\P{Mark}(?:\p{Mark}*))/gv;
    return [...name.matchAll(regexp)].flat();
}

Then test it with Vitest:

describe("showcaseVFlag", () => {
    it("should separate graphemes correctly", () => {
       expect(showcaseVFlag("Hello 🌍! 👋")).toStrictEqual(["H", "e", "l", "l", "o", " ", "🌍", "!", " ", "👋"]);
    });
 });

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 AMD Ryzen 5 4600H with Radeon Graphics
    Memory: 2.52 GB / 15.37 GB
  Binaries:
    Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.1.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.9.2 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Chromium (121.0.2277.128)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    vite: ^5.1.3 => 5.1.3
    vitest: ^1.2.2 => 1.2.2

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-edge-caseBug, but has workaround or limited in scope (priority)upstream

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions