#3707·mathjs

Expression parser unnecessary assignment

Author: ACodingSealCreated Oct 1, 2026Updated Oct 1, 2026

In the expression parser, when referring to a nested object using brackets notation and performing an assignment operation, the parent's property that refers to the child object is set to itself, triggering setters. The property on the child is set first, as intended. I'm not sure why the parent is affected at all.

Now, of course, it's easy enough to just grab a direct reference to the child object and set on it as usual, avoiding this issue entirely. I'd still like to see it fixed, though, to avoid unnecessary declarations, or explained if it's a non-issue.

Code to reproduce

javascript
const parentHandler = {
  get:function() {
      const [t,p,r] = arguments;
      
      return Reflect.get(...arguments);
  },
  set:function() {
      console.log(`Parent setter triggered:`, ...arguments);
      return Reflect.set(...arguments);
  },
};
const childHandler = {
  set:function() {
      console.log(`Child setter triggered:`, ...arguments);
      return Reflect.set(...arguments);
  },
};
const child = new Proxy({
  x:4,
}, childHandler);
const parent = new Proxy({
  child:child,
}, parentHandler);

const scope = {
  parent:parent,
  child:child,
};
let expr = `
property = 'x';

parent.child[property] = 5; # Triggers parent and child setters
child[property] = 6; # Triggers child setter
`;
math.evaluate(expr, scope);