fix: Cyclic dependency not resolving in JS Editor (#8003)

This commit is contained in:
Hetu Nandu 2021-10-01 20:39:09 +05:30 committed by GitHub
parent 70c282da5a
commit 72f6ad8d99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -235,22 +235,28 @@ ctx.addEventListener(
}
case EVAL_WORKER_ACTIONS.PARSE_JS_FUNCTION_BODY: {
const { body, jsAction } = requestData;
if (!dataTreeEvaluator) {
return true;
}
/**
* In case of a cyclical dependency, the dataTreeEvaluator will not
* be present. This causes an issue because evalTree is needed to resolve
* the cyclical dependency in a JS Collection
*
* By setting evalTree to an empty object, the parsing can still take place
* and it would resolve the cyclical dependency
* **/
const currentEvalTree = dataTreeEvaluator
? dataTreeEvaluator.evalTree
: {};
try {
const { evalTree, result } = parseJSCollection(
body,
jsAction,
dataTreeEvaluator.evalTree,
currentEvalTree,
);
return {
evalTree,
result,
};
} catch (e) {
const evalTree = dataTreeEvaluator.evalTree;
const errors = [
{
errorType: PropertyEvaluationErrorType.PARSE,
@ -259,9 +265,13 @@ ctx.addEventListener(
errorMessage: e.message,
},
];
_.set(evalTree, `${jsAction.name}.${EVAL_ERROR_PATH}.body`, errors);
_.set(
currentEvalTree,
`${jsAction.name}.${EVAL_ERROR_PATH}.body`,
errors,
);
return {
evalTree,
currentEvalTree,
};
}
}