@ptolemy2002/rgx 13.2.1 → 13.3.1
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/constants.d.ts +5 -0
- package/dist/constants.js +8 -0
- package/dist/resolve.js +22 -4
- package/dist/typeGuards.js +1 -1
- package/package.json +1 -1
package/dist/constants.d.ts
CHANGED
|
@@ -140,6 +140,11 @@ export declare const RGX_PREDEFINED_CONSTANTS: {
|
|
|
140
140
|
readonly rgxIsRepeatable: false;
|
|
141
141
|
readonly toRgx: () => RegExp;
|
|
142
142
|
};
|
|
143
|
+
readonly never: {
|
|
144
|
+
readonly rgxGroupWrap: false;
|
|
145
|
+
readonly rgxIsRepeatable: false;
|
|
146
|
+
readonly toRgx: () => RegExp;
|
|
147
|
+
};
|
|
143
148
|
};
|
|
144
149
|
export type RGXPredefinedConstant = keyof typeof RGX_PREDEFINED_CONSTANTS;
|
|
145
150
|
export type RGXConstantName = RGXPredefinedConstant | (string & {});
|
package/dist/constants.js
CHANGED
|
@@ -169,6 +169,14 @@ exports.RGX_PREDEFINED_CONSTANTS = {
|
|
|
169
169
|
return /(?<=(?<!\\)(?:\\\\)*)/;
|
|
170
170
|
}
|
|
171
171
|
},
|
|
172
|
+
"never": {
|
|
173
|
+
rgxGroupWrap: false,
|
|
174
|
+
rgxIsRepeatable: false,
|
|
175
|
+
toRgx() {
|
|
176
|
+
// Never succeed
|
|
177
|
+
return /(?!)/;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
172
180
|
};
|
|
173
181
|
function listRGXConstants() {
|
|
174
182
|
return Object.keys(rgxConstants);
|
package/dist/resolve.js
CHANGED
|
@@ -60,6 +60,7 @@ function localizableVanillaRegexFlagDiff(prev, next) {
|
|
|
60
60
|
}
|
|
61
61
|
function resolveRGXToken(token, { groupWrap = true, topLevel = true, currentFlags = '' } = {}) {
|
|
62
62
|
(0, ExtRegExp_1.assertValidRegexFlags)(currentFlags);
|
|
63
|
+
let acceptUnterminatedGroup = false;
|
|
63
64
|
const innerResolve = () => {
|
|
64
65
|
if (tg.isRGXNoOpToken(token))
|
|
65
66
|
return '';
|
|
@@ -80,10 +81,14 @@ function resolveRGXToken(token, { groupWrap = true, topLevel = true, currentFlag
|
|
|
80
81
|
return escapeRegex(String(token));
|
|
81
82
|
if (tg.isRGXConvertibleToken(token)) {
|
|
82
83
|
// If it's an interpolation, we want to just return it as-is.
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
|
|
84
|
+
// It might have an unterminated group, but that's okay,
|
|
85
|
+
// since a future token might terminate it, and if it doesn't, that
|
|
86
|
+
// will be caught by one of the checks that the entire resolved string
|
|
87
|
+
// is a valid regex string.
|
|
88
|
+
if (token.rgxInterpolate) {
|
|
89
|
+
acceptUnterminatedGroup = true;
|
|
86
90
|
return String(token.toRgx());
|
|
91
|
+
}
|
|
87
92
|
// The top-level group-wrapping preference propogates to a direct convertible token, but after that
|
|
88
93
|
// the preference falls back to true whenever a token doesn't explicitly specify a preference.
|
|
89
94
|
return resolveRGXToken(token.toRgx(), { groupWrap: token.rgxGroupWrap ?? (topLevel ? groupWrap : true), topLevel: false, currentFlags });
|
|
@@ -108,6 +113,19 @@ function resolveRGXToken(token, { groupWrap = true, topLevel = true, currentFlag
|
|
|
108
113
|
throw new e.RGXInvalidTokenError(`Invalid RGX token: ${token}`, null, token);
|
|
109
114
|
};
|
|
110
115
|
const result = innerResolve();
|
|
111
|
-
|
|
116
|
+
try {
|
|
117
|
+
tg.assertValidRegexString(result);
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
if (err instanceof e.RGXInvalidRegexStringError) {
|
|
121
|
+
if (acceptUnterminatedGroup && err.cause.message.endsWith('Unterminated group')) {
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// This is ignored because I don't know what kind of
|
|
126
|
+
// unexpected errors might happen.
|
|
127
|
+
/* istanbul ignore next */
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
112
130
|
return result;
|
|
113
131
|
}
|
package/dist/typeGuards.js
CHANGED
|
@@ -266,7 +266,7 @@ function assertValidRegexString(value) {
|
|
|
266
266
|
if (err instanceof SyntaxError) {
|
|
267
267
|
throw new e.RGXInvalidRegexStringError("Invalid regex string", value, err);
|
|
268
268
|
}
|
|
269
|
-
// This is ignored because I don't know what
|
|
269
|
+
// This is ignored because I don't know what kind of
|
|
270
270
|
// unexpected errors might happen.
|
|
271
271
|
/* istanbul ignore next */
|
|
272
272
|
throw err;
|