Skip to content

Commit

Permalink
Fix escaping in nested classes in verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed Nov 22, 2024
1 parent 81c55f1 commit 65e254d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ One of `'default'` *(default)* or `'strict'`.

Sets the level of emulation rigor/strictness.

- `default`: Permits a few close approximations in order to support additional features.
- `strict`: Throw if the pattern can't be emulated with identical behavior (even in rare edge cases) for the given `target`.
- **Default:** Permits a few close approximations in order to support additional features.
- **Strict:** Error if the pattern can't be emulated with identical behavior (even in rare edge cases) for the given `target`.

<details>
<summary>More details</summary>
Expand Down
7 changes: 6 additions & 1 deletion src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,13 @@ function genCharacterClass({negate, parent, elements}, state, gen) {
if (!state.useFlagV && parent.type === AstTypes.CharacterClass) {
throw new Error('Use of nested character class requires min target ES2024');
}
const genClass = () => `[${negate ? '^' : ''}${elements.map(gen).join('')}]`;
if (state.inCharClass) {
return genClass();
}
// For the outermost char class, set state
state.inCharClass = true;
const result = `[${negate ? '^' : ''}${elements.map(gen).join('')}]`;
const result = genClass();
state.inCharClass = false;
return result;
}
Expand Down

0 comments on commit 65e254d

Please sign in to comment.