diff --git a/README.md b/README.md index c7da631..6305b97 100644 --- a/README.md +++ b/README.md @@ -554,6 +554,7 @@ Notice that nearly every feature below has at least subtle differences from Java ✔ Unescaped - outside of range is literal in some contexts (different than JS rules in any mode)
✔ Error for unescaped [ that doesn't form nested class
+ ✔ Allows leading unescaped ]
✔ Fewer chars require escaping than JS
@@ -564,7 +565,6 @@ Notice that nearly every feature below has at least subtle differences from Java ✅ ✔ Error
- ✔ Doesn't allow leading unescaped ]
@@ -921,7 +921,7 @@ The table above doesn't include all aspects that Oniguruma-To-ES emulates (inclu 3. With target `ES2018`, the specific POSIX classes `[:graph:]` and `[:print:]` use ASCII-based versions rather than the Unicode versions available for target `ES2024` and later, and they result in an error if using strict `accuracy`. 4. Target `ES2018` doesn't support nested *negated* character classes. 5. It's not an error for *numbered* backreferences to come before their referenced group in Oniguruma, but an error is the best path for Oniguruma-To-ES because (1) most placements are mistakes and can never match (based on the Oniguruma behavior for backreferences to nonparticipating groups), (2) erroring matches the behavior of named backreferences, and (3) the edge cases where they're matchable rely on rules for backreference resetting within quantified groups that are different in JavaScript and aren't emulatable. Note that it's not a backreference in the first place if using `\10` or higher and not as many capturing groups are defined to the left (it's an octal or identity escape). -6. The recursion depth limit is specified by option `maxRecursionDepth`. Use of backreferences with recursion isn't yet supported. Patterns that would error in Oniguruma due to triggering infinite recursion might find a match in Oniguruma-To-ES since recursion is bounded (future versions will detect this and error at transpilation time). +6. The recursion depth limit is specified by option `maxRecursionDepth`. Use of backreferences when the recursed subpattern contains captures isn't yet supported. Patterns that would error in Oniguruma due to triggering infinite recursion might find a match in Oniguruma-To-ES since recursion is bounded (future versions will detect this and error at transpilation time). ## ❌ Unsupported features diff --git a/package.json b/package.json index ccece05..c29b0c2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "dependencies": { "emoji-regex-xs": "^1.0.0", "regex": "^5.0.2", - "regex-recursion": "^4.2.1" + "regex-recursion": "^4.3.0" }, "devDependencies": { "esbuild": "^0.24.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f36192e..f064ca8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,8 +15,8 @@ importers: specifier: ^5.0.2 version: 5.0.2 regex-recursion: - specifier: ^4.2.1 - version: 4.2.1 + specifier: ^4.3.0 + version: 4.3.0 devDependencies: esbuild: specifier: ^0.24.0 @@ -282,8 +282,8 @@ packages: resolution: {integrity: sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==} engines: {node: '>=16 || 14 >=14.18'} - regex-recursion@4.2.1: - resolution: {integrity: sha512-QHNZyZAeKdndD1G3bKAbBEKOSSK4KOHQrAJ01N1LJeb0SoH4DJIeFhp0uUpETgONifS4+P3sOgoA1dhzgrQvhA==} + regex-recursion@4.3.0: + resolution: {integrity: sha512-5LcLnizwjcQ2ALfOj95MjcatxyqF5RPySx9yT+PaXu3Gox2vyAtLDjHB8NTJLtMGkvyau6nI3CfpwFCjPUIs/A==} regex-utilities@2.3.0: resolution: {integrity: sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng==} @@ -537,7 +537,7 @@ snapshots: lru-cache: 10.4.3 minipass: 7.1.2 - regex-recursion@4.2.1: + regex-recursion@4.3.0: dependencies: regex-utilities: 2.3.0 diff --git a/spec/match-recursion.spec.js b/spec/match-recursion.spec.js index a44fbd4..4d40a30 100644 --- a/spec/match-recursion.spec.js +++ b/spec/match-recursion.spec.js @@ -24,10 +24,16 @@ describe('Recursion', () => { }); // Documenting current behavior - it('should throw if recursion used with backref', () => { + it('should throw if backref used with recursion when the recursed subpattern contains captures', () => { expect(() => toDetails(r`(a)\1\g<0>?`)).toThrow(); - expect(() => toDetails(r`(a\g<1>?)\k<1>`)).toThrow(); - expect(() => toDetails(r`(?a\g?)(?)\k`)).toThrow(); + expect(() => toDetails(r`((a)\g<1>?)\k<1>`)).toThrow(); + expect(() => toDetails(r`((a)\g<1>?)()\k<3>`)).toThrow(); + }); + + it('should match backref used with recursion when the recursed subpattern contains no captures', () => { + expect('aaabaaa').toExactlyMatch(r`(a\g<1>?)b\k<1>`); + expect('aaabaaa').toExactlyMatch(r`(?a\g?)b\k`); + expect('aaabb').toExactlyMatch(r`(?a\g?)(?b)\k`); }); describe('global', () => {