Browse Source

fix: return wrong value when reference function

Ahmad Kholid 3 years ago
parent
commit
ebda825b54
1 changed files with 19 additions and 8 deletions
  1. 19 8
      src/utils/referenceData/mustacheReplacer.js

+ 19 - 8
src/utils/referenceData/mustacheReplacer.js

@@ -104,18 +104,29 @@ function replacer(str, { regex, tagLen, modifyPath, data }) {
     let key = match.slice(tagLen, -tagLen).trim();
     let key = match.slice(tagLen, -tagLen).trim();
 
 
     if (!key) return '';
     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);
       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 {
     } else {
       const { dataKey, path } = keyParser(key, data);
       const { dataKey, path } = keyParser(key, data);