Regex roundtrip JS open

regexp-tree emits a leading ^ unescaped, turning [a^] into [^a]

Generator emits a leading ^ unescaped, inverting [a^] into [^a]

regexp-tree · DmitrySoshnikov/regexp-tree

Symptom

Optimizing or regenerating a character class can move a literal ^ to the front and emit it unescaped, flipping the meaning: [a^] round-trips to [^a] (a negated class).

Minimal repro
const rt = require('regexp-tree')
rt.optimize('/[a^]/').toString() // '/[^a]/'  <- now matches the negation
Fix

In the generator, escape a leading literal ^ in a non-negative character class so generate(parse(x)) preserves meaning.

Fix PR → #regexp-tree-leading-caret

Also in: JavaScript

← all 93 entries