How to use the ast-types.namedTypes.MemberExpression function in ast-types

To help you get started, we’ve selected a few ast-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reactjs / react-docgen / src / utils / isReactBuiltinCall.js View on Github external
if (t.ExpressionStatement.check(path.node)) {
    path = path.get('expression');
  }

  if (match(path.node, { callee: { property: { name } } })) {
    const module = resolveToModule(path.get('callee', 'object'));
    return Boolean(module && isReactModuleName(module));
  }

  if (t.CallExpression.check(path.node)) {
    const value = resolveToValue(path.get('callee'));
    if (value === path.get('callee')) return false;

    if (
      // `require('react').createElement`
      (t.MemberExpression.check(value.node) &&
        t.Identifier.check(value.get('property').node) &&
        value.get('property').node.name === name) ||
      // `import { createElement } from 'react'`
      (t.ImportDeclaration.check(value.node) &&
        value.node.specifiers.some(
          specifier => specifier.imported && specifier.imported.name === name,
        ))
    ) {
      const module = resolveToModule(value);
      return Boolean(module && isReactModuleName(module));
    }
  }

  return false;
}
github reactjs / react-docgen / src / utils / getMembers.js View on Github external
export default function getMembers(
  path: NodePath,
  includeRoot: boolean = false,
): Array {
  const result = [];
  let argumentsPath = null;
  // eslint-disable-next-line no-constant-condition
  loop: while (true) {
    switch (true) {
      case t.MemberExpression.check(path.node):
        result.push({
          path: path.get('property'),
          computed: path.node.computed,
          argumentsPath: argumentsPath,
        });
        argumentsPath = null;
        path = path.get('object');
        break;
      case t.CallExpression.check(path.node):
        argumentsPath = path.get('arguments');
        path = path.get('callee');
        break;
      default:
        break loop;
    }
  }
github probmods / webppl / src / analysis / main.js View on Github external
})));
    case Syntax.BinaryExpression:
      if (expr.operator === '+' ||
          expr.operator === '-') {
        return Set.of(new Num({}));
      }
      else if (expr.operator === '==') {
        return Set.of(true, false);
      }
      else {
        console.log(Au(store, environment, expr.left));
        console.log(Au(store, environment, expr.right));
        throw new Error('Au: unhandled binary operator ' + expr.operator);
      }
    case Syntax.CallExpression:
      if (types.MemberExpression.check(expr.callee) &&
          ! expr.callee.computed &&
          expr.callee.property.name === 'concat') {
        console.log(Au(store, environment, expr.callee.object));
        console.log(Au(store, environment, expr.callee.object));
        throw 23;
      }
      else {
        console.log(expr);
        console.log(require('escodegen').generate(expr));
        throw 12;
      }
    case Syntax.FunctionExpression:
      return Set.of(expr);
    case Syntax.Identifier:
      var value = environment.get(expr.name, false) || store.get(expr.name, false);
github rainforestapp / decaf / src / parser.js View on Github external
.find(jsc.AssignmentExpression, node =>
    n.MemberExpression.check(node.left) !== true &&
    get(node, 'operator') === '='
  )
github reactjs / react-docgen / src / utils / resolveObjectValuesToArray.js View on Github external
function isObjectValuesCall(node: ASTNode): boolean {
  return (
    t.CallExpression.check(node) &&
    node.arguments.length === 1 &&
    t.MemberExpression.check(node.callee) &&
    t.Identifier.check(node.callee.object) &&
    node.callee.object.name === 'Object' &&
    t.Identifier.check(node.callee.property) &&
    node.callee.property.name === 'values'
  );
}
github reactjs / react-docgen / src / handlers / defaultPropsHandler.js View on Github external
} else {
      path = resolveToValue(path);
    }
    if (t.ImportDeclaration.check(path.node)) {
      defaultValue = node.name;
    } else {
      node = path.node;
      defaultValue = printValue(path);
    }
  }
  if (typeof defaultValue !== 'undefined') {
    return {
      value: defaultValue,
      computed:
        t.CallExpression.check(node) ||
        t.MemberExpression.check(node) ||
        t.Identifier.check(node),
    };
  }

  return null;
}
github reactjs / react-docgen / src / utils / resolveToModule.js View on Github external
if (match(node.callee, { type: t.Identifier.name, name: 'require' })) {
        return node.arguments[0].value;
      }
      return resolveToModule(path.get('callee'));
    case t.Identifier.name:
    case t.JSXIdentifier.name: {
      const valuePath = resolveToValue(path);
      if (valuePath !== path) {
        return resolveToModule(valuePath);
      }
      break;
    }
    case t.ImportDeclaration.name:
      return node.source.value;
    case t.MemberExpression.name:
      while (path && t.MemberExpression.check(path.node)) {
        path = path.get('object');
      }
      if (path) {
        return resolveToModule(path);
      }
  }

  return null;
}
github reactjs / react-docgen / src / utils / isStatelessComponent.js View on Github external
if (returnsJSXElementOrReactCall(calleeValue, seen)) {
      return true;
    }

    let resolvedValue;

    const namesToResolve = [calleeValue.get('property')];

    if (calleeValue.node.type === 'MemberExpression') {
      if (calleeValue.get('object').node.type === 'Identifier') {
        resolvedValue = resolveToValue(calleeValue.get('object'));
      } else if (t.MemberExpression.check(calleeValue.node)) {
        do {
          calleeValue = calleeValue.get('object');
          namesToResolve.unshift(calleeValue.get('property'));
        } while (t.MemberExpression.check(calleeValue.node));

        resolvedValue = resolveToValue(calleeValue.get('object'));
      }
    }

    if (resolvedValue && t.ObjectExpression.check(resolvedValue.node)) {
      const resolvedMemberExpression = namesToResolve.reduce(
        (result, nodePath) => {
          if (!nodePath) {
            return result;
          }

          if (result) {
            result = getPropertyValuePath(result, nodePath.node.name);
            if (result && t.Identifier.check(result.node)) {
              return resolveToValue(result);
github reactjs / react-docgen / src / utils / resolveObjectKeysToArray.js View on Github external
function isObjectKeysCall(node: ASTNode): boolean {
  return (
    t.CallExpression.check(node) &&
    node.arguments.length === 1 &&
    t.MemberExpression.check(node.callee) &&
    t.Identifier.check(node.callee.object) &&
    node.callee.object.name === 'Object' &&
    t.Identifier.check(node.callee.property) &&
    node.callee.property.name === 'keys'
  );
}
github reactjs / react-docgen / src / utils / resolveToModule.js View on Github external
case t.CallExpression.name:
      if (match(node.callee, { type: t.Identifier.name, name: 'require' })) {
        return node.arguments[0].value;
      }
      return resolveToModule(path.get('callee'));
    case t.Identifier.name:
    case t.JSXIdentifier.name: {
      const valuePath = resolveToValue(path);
      if (valuePath !== path) {
        return resolveToModule(valuePath);
      }
      break;
    }
    case t.ImportDeclaration.name:
      return node.source.value;
    case t.MemberExpression.name:
      while (path && t.MemberExpression.check(path.node)) {
        path = path.get('object');
      }
      if (path) {
        return resolveToModule(path);
      }
  }

  return null;
}