From da036eafd6feab030568e0ec295954d879824098 Mon Sep 17 00:00:00 2001 From: Mate Pek Date: Fri, 29 Jul 2022 15:23:26 +0800 Subject: [PATCH] test fix --- src/util/ResolveRule.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/util/ResolveRule.ts b/src/util/ResolveRule.ts index 42a784ae..b78bf467 100644 --- a/src/util/ResolveRule.ts +++ b/src/util/ResolveRule.ts @@ -43,9 +43,9 @@ function _mapAllStrings( const _flatResolved = Symbol('special value which means that the veriable was flat resolved'); async function _mapAllStringsAsync( - value: Readonly /*eslint-disable-line*/, + value: unknown /*eslint-disable-line*/, parent: any /*eslint-disable-line*/, - mapperFunc: (s: string, parent: any) => Promise /*eslint-disable-line*/, + mapperFunc: (s: string, parent: unknown) => Promise /*eslint-disable-line*/, ): Promise /*eslint-disable-line*/ { if (value === null) return null; switch (typeof value) { @@ -61,10 +61,15 @@ async function _mapAllStringsAsync( /* this check is a hack. at this point we cannot assume that mapperFunc resolves variables only with '$'. * but good enough for now. Should saves some resources. https://xkcd.com/1691/ */ if (typeof prevMappedValue === 'string' && prevMappedValue.indexOf('$') === -1) return prevMappedValue; - let nextMappedValue = await mapperFunc(prevMappedValue, parent); - while (prevMappedValue !== (nextMappedValue = await mapperFunc(prevMappedValue, parent))) { + + let nextMappedValue = await _mapAllStringsAsync(prevMappedValue, parent, mapperFunc); + while ( + typeof prevMappedValue === 'string' /*this limits to string but object comparison is more complicated*/ && + prevMappedValue !== (nextMappedValue = await _mapAllStringsAsync(prevMappedValue, parent, mapperFunc)) + ) { prevMappedValue = nextMappedValue; } + return nextMappedValue; } case 'object': { @@ -79,7 +84,7 @@ async function _mapAllStringsAsync( const newValue = Object.create(Object.getPrototypeOf(value)); Object.defineProperties(newValue, Object.getOwnPropertyDescriptors(value)); for (const prop in value) { - const res = await _mapAllStringsAsync(value[prop], newValue, mapperFunc); + const res = await _mapAllStringsAsync((value as Record)[prop], newValue, mapperFunc); if (res !== _flatResolved) newValue[prop] = res; else delete newValue[prop]; }