Skip to content

Commit

Permalink
fix: return wrong value when reference function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 committed May 18, 2022
1 parent ed698c6 commit ebda825
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/utils/referenceData/mustacheReplacer.js
Expand Up @@ -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);

Expand Down

0 comments on commit ebda825

Please sign in to comment.