@babel/types#isAssignmentExpression TypeScript Examples

The following examples show how to use @babel/types#isAssignmentExpression. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: cleanReturns.ts    From react-native-decompiler with GNU Affero General Public License v3.0 6 votes vote down vote up
getVisitor(): Visitor {
    return {
      ReturnStatement: (path) => {
        if (isAssignmentExpression(path.node.argument) && isIdentifier(path.node.argument.left)) {
          path.insertBefore(path.node.argument);
          path.get('argument').replaceWith(path.node.argument.left);
        }
      }
    };
  }
Example #2
Source File: webpackParser.ts    From react-native-decompiler with GNU Affero General Public License v3.0 6 votes vote down vote up
protected parseAst(ast: File, modules: Module[]): void {
    traverse(ast, {
      CallExpression: (nodePath) => {
        const firstArg = nodePath.get('arguments')[0];
        if (isFunctionExpression(nodePath.node.callee) && firstArg?.isArrayExpression()) { // entrypoint
          this.parseArray(ast, firstArg, modules);
        } else if (isMemberExpression(nodePath.node.callee) && isAssignmentExpression(nodePath.node.callee.object) && firstArg?.isArrayExpression()) { // chunked
          const assignment = nodePath.node.callee.object;
          if (isMemberExpression(assignment.left)) {
            let leftPropName = '';
            if (isIdentifier(assignment.left.property)) {
              leftPropName = assignment.left.property.name;
            } else if (isStringLiteral(assignment.left.property)) {
              leftPropName = assignment.left.property.value;
            }
            if (leftPropName.startsWith('webpackJsonp')) {
              const modulesObject = firstArg.get('elements')[1];
              if (modulesObject.isArrayExpression()) {
                this.parseArray(ast, modulesObject, modules);
              } else {
                if (!modulesObject || !modulesObject.isObjectExpression()) throw new Error('Failed assertion');
                this.parseObject(ast, modulesObject, modules);
              }
            }
          }
        }
        nodePath.skip();
      },
    });
  }
Example #3
Source File: cleanReturns.ts    From react-native-decompiler with GNU Affero General Public License v3.0 6 votes vote down vote up
getVisitor(): Visitor {
    return {
      ReturnStatement: (path) => {
        if (isAssignmentExpression(path.node.argument) && isIdentifier(path.node.argument.left)) {
          path.insertBefore(path.node.argument);
          path.get('argument').replaceWith(path.node.argument.left);
        }
      },
    };
  }
Example #4
Source File: webpackParser.ts    From react-native-decompiler with GNU Affero General Public License v3.0 6 votes vote down vote up
protected parseAst(ast: File, modules: Module[]): void {
    traverse(ast, {
      CallExpression: (nodePath) => {
        const firstArg = nodePath.get('arguments')[0];
        if (isFunctionExpression(nodePath.node.callee) && firstArg?.isArrayExpression()) { // entrypoint
          this.parseArray(ast, firstArg, modules);
        } else if (isMemberExpression(nodePath.node.callee) && isAssignmentExpression(nodePath.node.callee.object) && firstArg?.isArrayExpression()) { // chunked
          const assignment = nodePath.node.callee.object;
          if (isMemberExpression(assignment.left)) {
            let leftPropName = '';
            if (isIdentifier(assignment.left.property)) {
              leftPropName = assignment.left.property.name;
            } else if (isStringLiteral(assignment.left.property)) {
              leftPropName = assignment.left.property.value;
            }
            if (leftPropName.startsWith('webpackJsonp')) {
              const modulesObject = firstArg.get('elements')[1];
              if (modulesObject.isArrayExpression()) {
                this.parseArray(ast, modulesObject, modules);
              } else {
                if (!modulesObject || !modulesObject.isObjectExpression()) throw new Error('Failed assertion');
                this.parseObject(ast, modulesObject, modules);
              }
            }
          }
        }
        nodePath.skip();
      },
    });
  }