Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/v RegExp flag is not recognized in Vitest #5220

Closed
6 tasks done
Y3drk opened this issue Feb 16, 2024 · 4 comments · Fixed by #4409
Closed
6 tasks done

/v RegExp flag is not recognized in Vitest #5220

Y3drk opened this issue Feb 16, 2024 · 4 comments · Fixed by #4409
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority) upstream

Comments

@Y3drk
Copy link

Y3drk commented Feb 16, 2024

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

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Feb 17, 2024

Interesting, it looks like this is such a new stuff and ecosystem hasn't caught up with it. Probably this needs to reported to upstream somewhere:

One relevant issue I found is typescript's lib.d.ts


Just in case, here is a quick repro https://stackblitz.com/edit/vitest-dev-vitest-sgd3av?file=test%2Fbasic.test.ts

import { test } from 'vitest'

test("repro", () => {
  console.log(/fooo/v)
})

Interestingly, syntax highlighting is also not working...

I think workaround for now is to use RegExp constructor instead:

$ node
> console.log(/fooo/v)
/fooo/v
> new RegExp(/fooo/.source, "v")
/fooo/v

@hi-ogawa hi-ogawa added upstream p2-edge-case Bug, but has workaround or limited in scope (priority) and removed pending triage labels Feb 17, 2024
@djstrong
Copy link

The v flag works in jest.

@hi-ogawa
Copy link
Contributor

Nice, I didn't know sapphi-red already reported there 👍
I don't know the detail but Rollup v4 uses swc internally rollup/rollup#5073

@github-actions github-actions bot locked and limited conversation to collaborators Jul 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority) upstream
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants