unjs / magic-regexp

A compiled-away, type-safe, readable RegExp alternative

Home Page:https://regexp.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

$ Character gets escaped twice

Rigo-m opened this issue Β· comments

πŸ› The bug

exactly('$') gets compiled to \\$, it should be just \$

πŸ› οΈ To reproduce

https://stackblitz.com/edit/github-rujd5h?file=package-lock.json,index.mjs

🌈 Expected behaviour

exactly('$') should compile to \$

ℹ️ Additional context

No response

Ah. The issue here is that at.lineStart is a function:

- const DOLLAR_RE = createRegExp(exactly('$').at.lineStart);
+ const DOLLAR_RE = createRegExp(exactly('$').at.lineStart());

You should get a type error something like:

Argument of type '() => Input<"^\\$", never, []>' is not assignable to parameter of type 'string | Input<string, never, []>'.