Skip to content

Commit

Permalink
remove clone
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Feb 1, 2024
1 parent 253730a commit 89972be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cases/25-units-check/src/index.heta
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ p2 @Record {units: mM*h^7} := 23*s1/xx(k1, 3);
k1 @Const = 1e-3 {units: 1/h};
k2 @Const = 1.1 {units: UL};

xxx #defineFunction {arguments: [x, y], math: "sin(x)*pow(y*1.2, 3)cos(x)"};
xxx #defineFunction {arguments: [x, y], math: "sin(x)*pow(y*1.2, 3)*cos(x)"};
yyy #defineFunction {arguments: [x, y], math: "1 + sin(x) + y^3 + cos(x)"};
zzz #defineFunction {arguments: [x, y], math: "xxx(y,x)"};
k21 @Const = 1 {units: metre};
k22 @Const = 1 {units: mole};
y21 @Record {units: metre^3} := k21^3 + xxx(1.1*2.2, k21);
y22 @Record {units: metre^3} := k21^3 + zzz(k21, 3.1415);

// exports
#export { format: JSON, filepath: output };
Expand Down
4 changes: 3 additions & 1 deletion src/core/math-calc-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ function _calcUnit(_this, record) {
}
if (_this.fnObj && _this.fnObj.math) { // user-defined functions
// set units for internal FunctionDef arguments
let newNode = _this.fnObj.math.exprParsed.clone();
// TODO: need to rewrite with transform, because
// traverse mutates Symbol nodes in FunctionDef but cloneDeep losts the nameObj, fnObj properties
let newNode = _this.fnObj.math.exprParsed;
newNode.traverse((node, path) => {
if (node.isSymbolNode && path !== 'fn') {
let ind = _this.fnObj.arguments.indexOf(node.name); // [x, y].indexOf(y)
Expand Down

0 comments on commit 89972be

Please sign in to comment.