- try {
- call(reExec, source, [""]); // throws if source not a RegExp
- } catch {
- return new RE(`${source}`, "u");
- }
- const unicode = call(getUnicode, source, []);
- if (!unicode) {
- // The provided regular expression does not have a unicode
- // flag.
- throw new TypeError(
- `Piscēs: Cannot create Matcher from non‐Unicode RegExp: ${source}`,
- );
+ if (completesNormally(() => call(reExec, source, [""]))) {
+ // The provided source is a `RegExp´.
+ if (
+ !call(getUnicode, source, [])
+ && !call(getUnicodeSets, source, [])
+ ) {
+ // The provided regular expression does not have a unicode
+ // flag or unicode sets flag.
+ throw new TypeError(
+ `${PISCĒS}: Cannot create Matcher from non‐Unicode RegExp: ${source}`,
+ );
+ } else {
+ // The provided regular expression has a unicode flag or
+ // unicode sets flag.
+ return new RE(source);
+ }