From a3f62d3e009cd9a0c0f116db93078b32e79bd4d4 Mon Sep 17 00:00:00 2001 From: Steven Levithan Date: Thu, 19 Dec 2024 08:26:38 +0100 Subject: [PATCH] Don't add flag y if allowUnhandledGAnchors and has alts with and without leading \G --- src/transform.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/transform.js b/src/transform.js index 31ee3a0..9ee151d 100644 --- a/src/transform.js +++ b/src/transform.js @@ -323,11 +323,14 @@ const FirstPassVisitor = { hasAltWithoutLeadG = true; } } - if (hasAltWithLeadG && hasAltWithoutLeadG && !allowUnhandledGAnchors) { - throw new Error(r`Uses "\G" in a way that's unsupported`); + if (hasAltWithLeadG) { + if (!hasAltWithoutLeadG) { + // Supported `\G` nodes will be removed (and add flag y) when traversed; others will error + leadingGs.forEach(g => supportedGNodes.add(g)); + } else if (!allowUnhandledGAnchors) { + throw new Error(r`Uses "\G" in a way that's unsupported`); + } } - // Supported `\G` nodes will be removed when traversed; others will error - leadingGs.forEach(g => supportedGNodes.add(g)) }, Quantifier({node}) {