Repository: solidjs/solid
File: packages/solid/store/src/mutable.ts (TypeScript)

Code before:
    if (property === $PROXY) return receiver;
    if (property === $TRACK) return trackSelf(target);
    const nodes = getDataNodes(target);
    const tracked = nodes[property];
    let value = tracked ? tracked() : target[property];
    if (property === $NODE || property === "__proto__") return value;

    if (!tracked) {
      const desc = Object.getOwnPropertyDescriptor(target, property);
      const isFunction = typeof value === "function";
      if (getListener() && (!isFunction || target.hasOwnProperty(property)) && !(desc && desc.get))
        value = getDataNode(nodes, property, value)();
      else if (value != null && isFunction && value === Array.prototype[property as any]) {
        return (...args: unknown[]) =>
          batch(() => Array.prototype[property as any].apply(receiver, args));
      }
    }
    return isWrappable(value)
      ? wrap(value, "_SOLID_DEV_" && target[$NAME] && `${target[$NAME]}:${property.toString()}`)
      : value;
  },

  has(target, property) {
    if (property === $RAW || property === $PROXY || property === $TRACK ||
        property === $NODE || property === "__proto__") return true;
    getDataNodes(target)[property]?.(); // track
    return property in target;
  },

  set(target, property, value) {
    batch(() => setProperty(target, property, unwrap(value)));
    return true;
  },

  deleteProperty(target, property) {
    batch(() => setProperty(target, property, undefined));
    return true;
  },

  ownKeys: ownKeys,

  getOwnPropertyDescriptor: proxyDescriptor
};

function wrap<T extends StoreNode>(value: T, name?: string): T {
  let p = value[$PROXY];
  if (!p) {
    Object.defineProperty(value, $PROXY, { value: (p = new Proxy(value, proxyTraps)) });
    const keys = Object.keys(value),
      desc = Object.getOwnPropertyDescriptors(value);
    for (let i = 0, l = keys.length; i < l; i++) {

Review comment (suggestion):
In general, I've avoid optional chaining in the code base as we don't do any transforms on the code base and in some environments it die. Every time one slips in something breaks something. As annoying as it is, that's why all the others are written the way they are.

Code after:
    if (property === $PROXY) return receiver;
    if (property === $TRACK) return trackSelf(target);
    const nodes = getDataNodes(target);
    const tracked = nodes[property];
    let value = tracked ? tracked() : target[property];
    if (property === $NODE || property === "__proto__") return value;

    if (!tracked) {
      const desc = Object.getOwnPropertyDescriptor(target, property);
      const isFunction = typeof value === "function";
      if (getListener() && (!isFunction || target.hasOwnProperty(property)) && !(desc && desc.get))
        value = getDataNode(nodes, property, value)();
      else if (value != null && isFunction && value === Array.prototype[property as any]) {
        return (...args: unknown[]) =>
          batch(() => Array.prototype[property as any].apply(receiver, args));
      }
    }
    return isWrappable(value)
      ? wrap(value, "_SOLID_DEV_" && target[$NAME] && `${target[$NAME]}:${property.toString()}`)
      : value;
  },

  has(target, property) {
    if (property === $RAW || property === $PROXY || property === $TRACK ||
        property === $NODE || property === "__proto__") return true;
    const tracked = getDataNodes(target)[property];
    tracked && tracked();
    return property in target;
  },

  set(target, property, value) {
    batch(() => setProperty(target, property, unwrap(value)));
    return true;
  },

  deleteProperty(target, property) {
    batch(() => setProperty(target, property, undefined));
    return true;
  },

  ownKeys: ownKeys,

  getOwnPropertyDescriptor: proxyDescriptor
};

function wrap<T extends StoreNode>(value: T, name?: string): T {
  let p = value[$PROXY];
  if (!p) {
    Object.defineProperty(value, $PROXY, { value: (p = new Proxy(value, proxyTraps)) });
    const keys = Object.keys(value),
      desc = Object.getOwnPropertyDescriptors(value);