<commit_before>import { ExecContext } from "../helperFunctions/ExecContext";
import {
  getLastOperationTrackingResultCall,
  ignoredStringLiteral,
  runIfIdentifierExists,
  ignoredArrayExpression,
  createGetMemoArray,
  getLastOpValueCall,
  ignoredIdentifier,
  getTrackingVarName,
  ignoreNode,
  createSetMemoValue,
  getLastOperationTrackingResultWithoutResettingCall,
  getTrackingIdentifier
} from "../babelPluginHelpers";
import traverseStringConcat from "../traverseStringConcat";
import mapInnerHTMLAssignment from "./domHelpers/mapInnerHTMLAssignment";
import addElOrigin, {
  addElAttributeValueOrigin,
  addElAttributeNameOrigin,
  trackSetElementStyle
} from "./domHelpers/addElOrigin";
import * as MemoValueNames from "../MemoValueNames";
import { consoleLog } from "../helperFunctions/logging";
import { safelyReadProperty } from "../util";
import * as OperationTypes from "../OperationTypes";

export default <any>{
  argNames: log => {
    if (log.astArgs.assignmentType === "MemberExpression") {
      return ["object", "propertyName", "argument"];
    } else {
      return ["currentValue", "newValue", "argument"];
    }
  },
  exec: (args, astArgs, ctx: ExecContext, logData: any) => {
    var ret;
    const assignmentType = astArgs.type;
    const operator = astArgs.operator;
    if (assignmentType === "MemberExpression") {
      const [objArg, propertyNameArg, argumentArg] = args;
      var obj = objArg[0];
      var propName = propertyNameArg[0];
      var objT = objArg[1];
      var propNameT = propertyNameArg[1];

      var currentValue = obj[propName];
      var currentValueT = ctx.createOperationLog({
        operation: "memexpAsLeftAssExp",
        args: {
          object: [obj, objT],
          propertyName: [propName, propNameT]
        },
        extraArgs: {
          propertyValue: [
            currentValue,
            ctx.getObjectPropertyTrackingValue(obj, propName)
          ]
        },
        astArgs: {},
        result: currentValue,
        loc: logData.loc
      });

      var argument = argumentArg[0];
      let newValue;
      switch (operator) {
        case "=":
          newValue = argument;
          break;
        case "+=":
          newValue = obj[propName] + argument;
          break;
        case "-=":
          newValue = obj[propName] - argument;
          break;
        case "*=":
          newValue = obj[propName] * argument;
          break;
        case "/=":
          newValue = obj[propName] / argument;
          break;
        case "|=":
          newValue = obj[propName] | argument;
          break;
        case "%=":
          newValue = obj[propName] % argument;
          break;
        case "&=":
          newValue = obj[propName] & argument;
          break;
        case "**=":
          newValue = obj[propName] ** argument;
          break;
        case "<<=":
          newValue = obj[propName] << argument;
          break;
        case ">>=":
          newValue = obj[propName] >> argument;
          break;
        case ">>>=":
          newValue = obj[propName] >>> argument;
          break;
        case "^=":
          newValue = obj[propName] ^ argument;
          break;
        default:
          throw Error("unknown operator " + operator);
      }
      obj[propName] = newValue;
      ret = newValue;

      ctx.trackObjectPropertyAssignment(
        obj,
        propName,
        ctx.createOperationLog({
          result: ret,
          operation: "assignmentExpression",
          args: {
            currentValue: [currentValue, currentValueT],
            argument: argumentArg
          },
          astArgs: {
            operator
          },
          loc: logData.loc
        }),
        propNameT
      );

      const objIsHTMLNode = typeof Node !== "undefined" && obj instanceof Node;
      if (objIsHTMLNode) {
        if (propName === "innerHTML") {
          mapInnerHTMLAssignment(obj, argumentArg, "assignInnerHTML", 0);
        } else if (["text", "textContent", "nodeValue"].includes(propName)) {
          if (obj.nodeType === Node.TEXT_NODE) {
            addElOrigin(obj, "textValue", {
              trackingValue: argumentArg[1]
            });
          } else if (obj.nodeType === Node.ELEMENT_NODE) {
            if (obj.childNodes.length > 0) {
              // can be 0 still if textValue is ""
              addElOrigin(obj.childNodes[0], "textValue", {
                trackingValue: argumentArg[1]
              });
            }
          } else {
            consoleLog("do i need to handle this? can this even happen?");
          }
        } else if (
          // This is overly broad (and will track "elOrigins" for arbitraty property names),
          // but at least it makes sure all attributes are tracked
          safelyReadProperty(obj, "nodeType") === Node.ELEMENT_NODE &&
          typeof propName === "string"
        ) {
          let attrName = propName;
          if (attrName === "className") {
            attrName = "class";
          }
          addElAttributeValueOrigin(obj, attrName, {
            trackingValue: argumentArg[1]
          });
          addElAttributeNameOrigin(obj, attrName, { trackingValue: propNameT });
        }
      } else if (
        typeof CSSStyleDeclaration !== "undefined" &&
        obj instanceof CSSStyleDeclaration &&
        obj["__element"]
      ) {
        trackSetElementStyle(
          obj["__element"],<commit_msg>Replace log with comment<commit_after>import { ExecContext } from "../helperFunctions/ExecContext";
import {
  getLastOperationTrackingResultCall,
  ignoredStringLiteral,
  runIfIdentifierExists,
  ignoredArrayExpression,
  createGetMemoArray,
  getLastOpValueCall,
  ignoredIdentifier,
  getTrackingVarName,
  ignoreNode,
  createSetMemoValue,
  getLastOperationTrackingResultWithoutResettingCall,
  getTrackingIdentifier
} from "../babelPluginHelpers";
import traverseStringConcat from "../traverseStringConcat";
import mapInnerHTMLAssignment from "./domHelpers/mapInnerHTMLAssignment";
import addElOrigin, {
  addElAttributeValueOrigin,
  addElAttributeNameOrigin,
  trackSetElementStyle
} from "./domHelpers/addElOrigin";
import * as MemoValueNames from "../MemoValueNames";
import { consoleLog } from "../helperFunctions/logging";
import { safelyReadProperty } from "../util";
import * as OperationTypes from "../OperationTypes";

export default <any>{
  argNames: log => {
    if (log.astArgs.assignmentType === "MemberExpression") {
      return ["object", "propertyName", "argument"];
    } else {
      return ["currentValue", "newValue", "argument"];
    }
  },
  exec: (args, astArgs, ctx: ExecContext, logData: any) => {
    var ret;
    const assignmentType = astArgs.type;
    const operator = astArgs.operator;
    if (assignmentType === "MemberExpression") {
      const [objArg, propertyNameArg, argumentArg] = args;
      var obj = objArg[0];
      var propName = propertyNameArg[0];
      var objT = objArg[1];
      var propNameT = propertyNameArg[1];

      var currentValue = obj[propName];
      var currentValueT = ctx.createOperationLog({
        operation: "memexpAsLeftAssExp",
        args: {
          object: [obj, objT],
          propertyName: [propName, propNameT]
        },
        extraArgs: {
          propertyValue: [
            currentValue,
            ctx.getObjectPropertyTrackingValue(obj, propName)
          ]
        },
        astArgs: {},
        result: currentValue,
        loc: logData.loc
      });

      var argument = argumentArg[0];
      let newValue;
      switch (operator) {
        case "=":
          newValue = argument;
          break;
        case "+=":
          newValue = obj[propName] + argument;
          break;
        case "-=":
          newValue = obj[propName] - argument;
          break;
        case "*=":
          newValue = obj[propName] * argument;
          break;
        case "/=":
          newValue = obj[propName] / argument;
          break;
        case "|=":
          newValue = obj[propName] | argument;
          break;
        case "%=":
          newValue = obj[propName] % argument;
          break;
        case "&=":
          newValue = obj[propName] & argument;
          break;
        case "**=":
          newValue = obj[propName] ** argument;
          break;
        case "<<=":
          newValue = obj[propName] << argument;
          break;
        case ">>=":
          newValue = obj[propName] >> argument;
          break;
        case ">>>=":
          newValue = obj[propName] >>> argument;
          break;
        case "^=":
          newValue = obj[propName] ^ argument;
          break;
        default:
          throw Error("unknown operator " + operator);
      }
      obj[propName] = newValue;
      ret = newValue;

      ctx.trackObjectPropertyAssignment(
        obj,
        propName,
        ctx.createOperationLog({
          result: ret,
          operation: "assignmentExpression",
          args: {
            currentValue: [currentValue, currentValueT],
            argument: argumentArg
          },
          astArgs: {
            operator
          },
          loc: logData.loc
        }),
        propNameT
      );

      const objIsHTMLNode = typeof Node !== "undefined" && obj instanceof Node;
      if (objIsHTMLNode) {
        if (propName === "innerHTML") {
          mapInnerHTMLAssignment(obj, argumentArg, "assignInnerHTML", 0);
        } else if (["text", "textContent", "nodeValue"].includes(propName)) {
          if (obj.nodeType === Node.TEXT_NODE) {
            addElOrigin(obj, "textValue", {
              trackingValue: argumentArg[1]
            });
          } else if (obj.nodeType === Node.ELEMENT_NODE) {
            if (obj.childNodes.length > 0) {
              // can be 0 still if textValue is ""
              addElOrigin(obj.childNodes[0], "textValue", {
                trackingValue: argumentArg[1]
              });
            }
          } else {
            // e.g. document fragments etc... should ideally handle this one day
          }
        } else if (
          // This is overly broad (and will track "elOrigins" for arbitraty property names),
          // but at least it makes sure all attributes are tracked
          safelyReadProperty(obj, "nodeType") === Node.ELEMENT_NODE &&
          typeof propName === "string"
        ) {
          let attrName = propName;
          if (attrName === "className") {
            attrName = "class";
          }
          addElAttributeValueOrigin(obj, attrName, {
            trackingValue: argumentArg[1]
          });
          addElAttributeNameOrigin(obj, attrName, { trackingValue: propNameT });
        }
      } else if (
        typeof CSSStyleDeclaration !== "undefined" &&
        obj instanceof CSSStyleDeclaration &&
        obj["__element"]
      ) {
        trackSetElementStyle(
          obj["__element"],
{'fraction_non_alphanumeric': 0.1149995407366584, 'fraction_numerical': 0.002204464039680353, 'mean_word_length': 2.0345596432552955, 'pattern_counts': {'":': 26, '<': 13, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4664733', 'n_tokens_mistral': 2958, 'n_tokens_neox': 2946, 'n_words': 688}