Kaynağa Gözat

fix: condition block (#1406)

Ahmad Kholid 1 yıl önce
ebeveyn
işleme
936cbee3bf

+ 8 - 3
src/workflowEngine/templating/mustacheReplacer.js

@@ -61,7 +61,10 @@ export function keyParser(key, data) {
   return { dataKey: 'table', path };
 }
 
-function replacer(str, { regex, tagLen, modifyPath, data }) {
+function replacer(
+  str,
+  { regex, tagLen, modifyPath, data, disableStringify = false }
+) {
   const replaceResult = {
     list: {},
     value: str,
@@ -113,7 +116,7 @@ function replacer(str, { regex, tagLen, modifyPath, data }) {
     }
 
     const finalResult =
-      typeof result === 'string' && !stringify
+      disableStringify || (typeof result === 'string' && !stringify)
         ? result
         : JSON.stringify(result);
 
@@ -125,7 +128,7 @@ function replacer(str, { regex, tagLen, modifyPath, data }) {
   return replaceResult;
 }
 
-export default function (str, refData) {
+export default function (str, refData, options = {}) {
   if (!str || typeof str !== 'string') return '';
 
   const data = { ...refData, functions: templatingFunctions };
@@ -140,11 +143,13 @@ export default function (str, refData) {
         data,
         tagLen: 1,
         regex: /\[(.*?)\]/g,
+        ...options,
       });
       Object.assign(replacedList, list);
 
       return value;
     },
+    ...options,
   });
 
   Object.assign(replacedStr.list, replacedList);

+ 2 - 2
src/workflowEngine/templating/renderString.js

@@ -5,7 +5,7 @@ import mustacheReplacer from './mustacheReplacer';
 const isFirefox = BROWSER_TYPE === 'firefox';
 const isMV2 = browser.runtime.getManifest().manifest_version === 2;
 
-export default async function (str, data, isPopup = true) {
+export default async function (str, data, isPopup = true, options = {}) {
   if (!str || typeof str !== 'string') return '';
 
   const hasMustacheTag = /\{\{(.*?)\}\}/.test(str);
@@ -32,7 +32,7 @@ export default async function (str, data, isPopup = true) {
     let copyStr = `${str}`;
     if (evaluateJS) copyStr = copyStr.slice(2);
 
-    renderedValue = mustacheReplacer(copyStr, data);
+    renderedValue = mustacheReplacer(copyStr, data, options);
   }
 
   return renderedValue;

+ 1 - 1
src/workflowEngine/utils/testConditions.js

@@ -71,7 +71,7 @@ export default async function (conditionsArr, workflowData) {
         workflowData.isPopup
       );
 
-      copyData[key] = parseJSON(value, value);
+      copyData[key] = value ?? '';
       Object.assign(result.replacedValue, list);
     }