function _getStateInitialization(node) {
    if (node.parent && node.parent.type === "ObjectExpression") {
      // Handle ES6 class property declaration
      const objectExpression = node.parent;
      const maybeState = objectExpression.parent;
      if (
        maybeState.type === "ClassProperty" &&
        maybeState.key.name === "state"
      ) {
        return node.key.name;
      }
      // Handle this.state = {} syntax (constructor initialization)
      if (objectExpression.parent.type === "AssignmentExpression") {
        const left = objectExpression.parent.left;
        if (
          left.object &&
          left.object.type === "ThisExpression" &&
          left.property.name === "state"
        ) {
          return node.key.name;
        }
      }
      // Handle getInitialState syntax
      let currNode = node.parent;
      while (currNode) {
        if (
          currNode.type === "FunctionExpression" &&
          currNode.parent &&
          currNode.parent.key &&
          currNode.parent.key.name === "getInitialState"
        ) {
          return node.key.name;
        }
        currNode = currNode.parent;
      }
    }
  }
/**
   * Checks for different ways of initializing state.
   */
Checks for different ways of initializing state.
Checks for different ways of initializing state .
function _getStateInitialization(node) {
    if (node.parent && node.parent.type === "ObjectExpression") {
      const objectExpression = node.parent;
      const maybeState = objectExpression.parent;
      if (
        maybeState.type === "ClassProperty" &&
        maybeState.key.name === "state"
      ) {
        return node.key.name;
      }
      if (objectExpression.parent.type === "AssignmentExpression") {
        const left = objectExpression.parent.left;
        if (
          left.object &&
          left.object.type === "ThisExpression" &&
          left.property.name === "state"
        ) {
          return node.key.name;
        }
      }
      let currNode = node.parent;
      while (currNode) {
        if (
          currNode.type === "FunctionExpression" &&
          currNode.parent &&
          currNode.parent.key &&
          currNode.parent.key.name === "getInitialState"
        ) {
          return node.key.name;
        }
        currNode = currNode.parent;
      }
    }
  }
function _getStateInitialization ( node ) { if ( node . parent && node . parent . type === "ObjectExpression" ) { const objectExpression = node . parent ; const maybeState = objectExpression . parent ; if ( maybeState . type === "ClassProperty" && maybeState . key . name === "state" ) { return node . key . name ; } if ( objectExpression . parent . type === "AssignmentExpression" ) { const left = objectExpression . parent . left ; if ( left . object && left . object . type === "ThisExpression" && left . property . name === "state" ) { return node . key . name ; } } let currNode = node . parent ; while ( currNode ) { if ( currNode . type === "FunctionExpression" && currNode . parent && currNode . parent . key && currNode . parent . key . name === "getInitialState" ) { return node . key . name ; } currNode = currNode . parent ; } } }
Checks for different ways of initializing state.
Checks for different ways of initializing state .
// Handle ES6 class property declaration // Handle this.state = {} syntax (constructor initialization) // Handle getInitialState syntax