intl macro: Support raw hash

This commit is contained in:
Nuckyz 2024-11-06 21:52:26 -03:00
parent 9d4e859a0a
commit 2270b88a98
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -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;
}