From ebda825b5493d9382c0eab9220f0906c79be2b85 Mon Sep 17 00:00:00 2001 From: Ahmad Kholid Date: Wed, 18 May 2022 13:42:20 +0800 Subject: [PATCH] fix: return wrong value when reference function --- src/utils/referenceData/mustacheReplacer.js | 27 +++++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/utils/referenceData/mustacheReplacer.js b/src/utils/referenceData/mustacheReplacer.js index 28be34355..cbb7f9a7c 100644 --- a/src/utils/referenceData/mustacheReplacer.js +++ b/src/utils/referenceData/mustacheReplacer.js @@ -104,18 +104,29 @@ function replacer(str, { regex, tagLen, modifyPath, data }) { let key = match.slice(tagLen, -tagLen).trim(); if (!key) return ''; - if (modifyPath && typeof modifyPath === 'function') { + + let result = ''; + const isFunction = extractStrFunction(key); + const funcRef = isFunction && data.functions[isFunction.name]; + + if (modifyPath && !funcRef) { key = modifyPath(key); } - let result = ''; - const funcRef = extractStrFunction(key); + if (funcRef) { + const funcParams = isFunction.params.map((param) => { + const { value, list } = replacer(param, { + data, + tagLen: 1, + regex: /\[(.*?)\]/, + }); + + Object.assign(replaceResult.list, list); + + return value; + }); - if (funcRef && data.functions[funcRef.name]) { - result = data.functions[funcRef.name]?.apply( - { refData: data }, - funcRef.params - ); + result = funcRef.apply({ refData: data }, funcParams); } else { const { dataKey, path } = keyParser(key, data);