intl macro: Support raw hash
This commit is contained in:
parent
9d4e859a0a
commit
2270b88a98
|
@ -21,8 +21,8 @@ import { Patch, PatchReplacement, ReplaceFn } from "./types";
|
|||
|
||||
export function canonicalizeMatch<T extends RegExp | string>(match: T): T {
|
||||
let partialCanon = typeof match === "string" ? match : match.source;
|
||||
partialCanon = partialCanon.replaceAll(/#{intl::([A-Za-z_$][\w$]*)}/g, (_, key) => {
|
||||
const hashed = runtimeHashMessageKey(key);
|
||||
partialCanon = partialCanon.replaceAll(/#{intl::([\w$+/]*)(?:::(\w+))?}/g, (_, key, modifier) => {
|
||||
const hashed = modifier === "raw" ? key : runtimeHashMessageKey(key);
|
||||
|
||||
const isString = typeof match === "string";
|
||||
const hasSpecialChars = !Number.isNaN(Number(hashed[0])) || hashed.includes("+") || hashed.includes("/");
|
||||
|
@ -40,7 +40,7 @@ export function canonicalizeMatch<T extends RegExp | string>(match: T): T {
|
|||
return partialCanon as T;
|
||||
}
|
||||
|
||||
const canonSource = partialCanon.replaceAll(String.raw`\i`, String.raw`(?:[A-Za-z_$][\w$]*)`);
|
||||
const canonSource = partialCanon.replaceAll("\\i", String.raw`(?:[A-Za-z_$][\w$]*)`);
|
||||
return new RegExp(canonSource, match.flags) as T;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue