patches: Make $self more robust
This commit is contained in:
parent
ab8c93fbac
commit
5e2ec368ad
|
@ -27,9 +27,13 @@ export function canonicalizeMatch(match: RegExp | string) {
|
||||||
return new RegExp(canonSource, match.flags);
|
return new RegExp(canonSource, match.flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function canonicalizeReplace(replace: string | ReplaceFn, pluginName: string) {
|
export function canonicalizeReplace(replace: string | ReplaceFn, pluginName: string): string | ReplaceFn {
|
||||||
if (typeof replace === "function") return replace;
|
const self = `Vencord.Plugins.plugins[${JSON.stringify(pluginName)}]`;
|
||||||
return replace.replaceAll("$self", `Vencord.Plugins.plugins.${pluginName}`);
|
|
||||||
|
if (typeof replace !== "function")
|
||||||
|
return replace.replaceAll("$self", self);
|
||||||
|
|
||||||
|
return (...args) => replace(...args).replaceAll("$self", self);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function canonicalizeDescriptor<T>(descriptor: TypedPropertyDescriptor<T>, canonicalize: (value: T) => T) {
|
export function canonicalizeDescriptor<T>(descriptor: TypedPropertyDescriptor<T>, canonicalize: (value: T) => T) {
|
||||||
|
|
Loading…
Reference in a new issue