From 2270b88a98baf31cdd6fb5db429304048bc15515 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 6 Nov 2024 21:52:26 -0300 Subject: [PATCH] intl macro: Support raw hash --- src/utils/patches.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/patches.ts b/src/utils/patches.ts index 3812acd9..097c6456 100644 --- a/src/utils/patches.ts +++ b/src/utils/patches.ts @@ -21,8 +21,8 @@ import { Patch, PatchReplacement, ReplaceFn } from "./types"; export function canonicalizeMatch(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(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; }