@ptolemy2002/rgx 13.3.2 → 13.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/resolve.js +33 -17
- package/dist/walker/base.d.ts +2 -2
- package/package.json +1 -1
package/dist/resolve.js
CHANGED
|
@@ -58,9 +58,39 @@ function localizableVanillaRegexFlagDiff(prev, next) {
|
|
|
58
58
|
return `${added}`;
|
|
59
59
|
return `${added}-${removed}`;
|
|
60
60
|
}
|
|
61
|
+
function hasParenErrors(pattern) {
|
|
62
|
+
let depth = 0;
|
|
63
|
+
let charClassDepth = 0;
|
|
64
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
65
|
+
const ch = pattern[i];
|
|
66
|
+
if (ch === '\\') {
|
|
67
|
+
i++;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (charClassDepth > 0) {
|
|
71
|
+
if (ch === '[')
|
|
72
|
+
charClassDepth++;
|
|
73
|
+
else if (ch === ']')
|
|
74
|
+
charClassDepth--;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (ch === '[') {
|
|
78
|
+
charClassDepth++;
|
|
79
|
+
}
|
|
80
|
+
else if (ch === '(') {
|
|
81
|
+
depth++;
|
|
82
|
+
}
|
|
83
|
+
else if (ch === ')') {
|
|
84
|
+
depth--;
|
|
85
|
+
if (depth < 0)
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return depth !== 0;
|
|
90
|
+
}
|
|
61
91
|
function resolveRGXToken(token, { groupWrap = true, topLevel = true, currentFlags = '' } = {}) {
|
|
62
92
|
(0, ExtRegExp_1.assertValidRegexFlags)(currentFlags);
|
|
63
|
-
let
|
|
93
|
+
let acceptParenErrors = false;
|
|
64
94
|
const innerResolve = () => {
|
|
65
95
|
if (tg.isRGXNoOpToken(token))
|
|
66
96
|
return '';
|
|
@@ -86,7 +116,7 @@ function resolveRGXToken(token, { groupWrap = true, topLevel = true, currentFlag
|
|
|
86
116
|
// will be caught by one of the checks that the entire resolved string
|
|
87
117
|
// is a valid regex string.
|
|
88
118
|
if (token.rgxInterpolate) {
|
|
89
|
-
|
|
119
|
+
acceptParenErrors = true;
|
|
90
120
|
return String(token.toRgx());
|
|
91
121
|
}
|
|
92
122
|
// The top-level group-wrapping preference propogates to a direct convertible token, but after that
|
|
@@ -113,21 +143,7 @@ function resolveRGXToken(token, { groupWrap = true, topLevel = true, currentFlag
|
|
|
113
143
|
throw new e.RGXInvalidTokenError(`Invalid RGX token: ${token}`, null, token);
|
|
114
144
|
};
|
|
115
145
|
const result = innerResolve();
|
|
116
|
-
|
|
146
|
+
if (!(acceptParenErrors && hasParenErrors(result)))
|
|
117
147
|
tg.assertValidRegexString(result);
|
|
118
|
-
}
|
|
119
|
-
catch (err) {
|
|
120
|
-
if (err instanceof e.RGXInvalidRegexStringError) {
|
|
121
|
-
if (acceptUnterminatedGroup &&
|
|
122
|
-
(err.cause.message.endsWith('Unterminated group') ||
|
|
123
|
-
err.cause.message.endsWith("Unmatched ')'"))) {
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// This is ignored because I don't know what kind of
|
|
128
|
-
// unexpected errors might happen.
|
|
129
|
-
/* istanbul ignore next */
|
|
130
|
-
throw err;
|
|
131
|
-
}
|
|
132
148
|
return result;
|
|
133
149
|
}
|
package/dist/walker/base.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type RGXTryWalkOptions = {
|
|
|
14
14
|
revertShare?: boolean;
|
|
15
15
|
revertCaptures?: boolean;
|
|
16
16
|
};
|
|
17
|
-
export type RGXTokenOrPart<R, S = unknown, T =
|
|
17
|
+
export type RGXTokenOrPart<R, S = unknown, T = any> = RGXToken | RGXPart<R, S, T>;
|
|
18
18
|
export type RGXWalkerStepDirective = "stop" | "skip" | "silent";
|
|
19
19
|
export declare class RGXWalker<R, S = unknown> {
|
|
20
20
|
readonly source: string;
|
|
@@ -45,7 +45,7 @@ export declare class RGXWalker<R, S = unknown> {
|
|
|
45
45
|
atSourceEnd(): boolean;
|
|
46
46
|
hasNextSource(predicate?: (rest: string) => boolean): boolean;
|
|
47
47
|
lastCapture(): RGXCapture | null;
|
|
48
|
-
currentToken(): RGXTokenOrPart<R, S,
|
|
48
|
+
currentToken(): RGXTokenOrPart<R, S, any>;
|
|
49
49
|
remainingSource(): string | null;
|
|
50
50
|
capture(token: RGXTokenOrPart<R, S>, includeMatch: true): RegExpExecArray;
|
|
51
51
|
capture(token: RGXTokenOrPart<R, S>, includeMatch?: false): string;
|