Skip to content

Expression parser unnecessary assignment #3707

Open

Description

@ACodingSeal

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

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);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions