Inline a function which fulfills the requirements of
canInlineReferenceAsStatementBlock into the call site, replacing the
parent expression.
545696
private Node inlineFunction(Reference ref, Node fnNode, String fnName) {
    Node callNode = ref.callNode;
    Node parent = callNode.getParent();
    Node grandParent = parent.getParent();

    // TODO(johnlenz): Consider storing the callSite classification in the
    // reference object and passing it in here.
    CallSiteType callSiteType = classifyCallSite(ref);
    checkArgument(callSiteType != CallSiteType.UNSUPPORTED);

    // Store the name for the result. This will be used to
    // replace "return expr" statements with "resultName = expr"
    // to replace
    String resultName = null;
    boolean needsDefaultReturnResult = true;
    switch (callSiteType) {
      case SIMPLE_ASSIGNMENT:
        resultName = parent.getFirstChild().getString();
        removeConstantVarAnnotation(ref.scope, resultName);
        break;

      case VAR_DECL_SIMPLE_ASSIGNMENT:
        resultName = parent.getString();
        removeConstantVarAnnotation(ref.scope, resultName);
        break;

      case SIMPLE_CALL:
        resultName = null;  // "foo()" doesn't need a result.
        needsDefaultReturnResult = false;
        break;

      case EXPRESSION:
        throw new IllegalStateException(
            "Movable expressions must be moved before inlining.");

      case DECOMPOSABLE_EXPRESSION:
        throw new IllegalStateException(
            "Decomposable expressions must be decomposed before inlining.");

      default:
        throw new IllegalStateException("Unexpected call site type.");
    }

    FunctionToBlockMutator mutator = new FunctionToBlockMutator(compiler, this.safeNameIdSupplier);

    boolean isCallInLoop = NodeUtil.isWithinLoop(callNode);
    Node newBlock = mutator.mutate(
        fnName, fnNode, callNode, resultName,
        needsDefaultReturnResult, isCallInLoop);
    NodeUtil.markNewScopesChanged(newBlock, compiler);

    // TODO(nicksantos): Create a common mutation function that
    // can replace either a VAR name assignment, assignment expression or
    // a EXPR_RESULT.
    Node greatGrandParent = grandParent.getParent();
    switch (callSiteType) {
      case VAR_DECL_SIMPLE_ASSIGNMENT:
        // Remove the call from the name node.
        Node firstChild = parent.removeFirstChild();
        NodeUtil.markFunctionsDeleted(firstChild, compiler);
        Preconditions.checkState(parent.getFirstChild() == null);
        // Add the call, after the VAR.
        greatGrandParent.addChildAfter(newBlock, grandParent);
        break;

      case SIMPLE_ASSIGNMENT:
        // The assignment is now part of the inline function so
        // replace it completely.
        Preconditions.checkState(grandParent.isExprResult());
        greatGrandParent.replaceChild(grandParent, newBlock);
        NodeUtil.markFunctionsDeleted(grandParent, compiler);
        break;

      case SIMPLE_CALL:
        // If nothing is looking at the result just replace the call.
        Preconditions.checkState(parent.isExprResult());
        grandParent.replaceChild(parent, newBlock);
        NodeUtil.markFunctionsDeleted(parent, compiler);
        break;

      default:
        throw new IllegalStateException("Unexpected call site type.");
    }

    return newBlock;
  }
1160252
function canSwapBetweenExpressionAndStatement(replacement) {
  if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {
    return false;
  }

  if (this.isExpression()) {
    return t.isBlockStatement(replacement);
  } else if (this.isBlockStatement()) {
    return t.isExpression(replacement);
  }

  return false;
}
405913
private Node inlineReturnValue(Reference ref, Node fnNode) {
    Node callNode = ref.callNode;
    Node block = fnNode.getLastChild();
    Node callParentNode = callNode.getParent();

    // NOTE: As the normalize pass guarantees globals aren't being
    // shadowed and an expression can't introduce new names, there is
    // no need to check for conflicts.

    // Create an argName -> expression map, checking for side effects.
    Map<String, Node> argMap =
        FunctionArgumentInjector.getFunctionCallParameterMap(
            fnNode, callNode, this.safeNameIdSupplier);

    Node newExpression;
    if (!block.hasChildren()) {
      Node srcLocation = block;
      newExpression = NodeUtil.newUndefinedNode(srcLocation);
    } else {
      Node returnNode = block.getFirstChild();
      checkArgument(returnNode.isReturn(), returnNode);

      // Clone the return node first.
      Node safeReturnNode = returnNode.cloneTree();
      Node inlineResult = FunctionArgumentInjector.inject(
          null, safeReturnNode, null, argMap);
      checkArgument(safeReturnNode == inlineResult);
      newExpression = safeReturnNode.removeFirstChild();
      NodeUtil.markNewScopesChanged(newExpression, compiler);
    }

    // If the call site had a cast ensure it's persisted to the new expression that replaces it.
    JSType typeBeforeCast = callNode.getJSTypeBeforeCast();
    if (typeBeforeCast != null) {
      newExpression.setJSTypeBeforeCast(typeBeforeCast);
      newExpression.setJSType(callNode.getJSType());
    }
    callParentNode.replaceChild(callNode, newExpression);
    NodeUtil.markFunctionsDeleted(callNode, compiler);
    return newExpression;
  }
1122813
def compile_inline(str)
      op, arg = /\A@<(\w+)>\{(.*?)\}\z/.match(str).captures
      unless inline_defined?(op)
        raise CompileError, "no such inline op: #{op}"
      end
      unless @strategy.respond_to?("inline_#{op}")
        raise "strategy does not support inline op: @<#{op}>"
      end
      @strategy.__send__("inline_#{op}", arg)
    rescue => e
      error e.message
      @strategy.nofunc_text(str)
    end
1331552
Node inline(Reference ref, String fnName, Node fnNode) {
    checkState(compiler.getLifeCycleStage().isNormalized());
    return internalInline(ref, fnName, fnNode);
  }
1235435
function replaceSuperMethodCall(node, state, path, options) {
  // like super.foo()
  console.assert(node.type === "CallExpression");
  console.assert(node.callee.object.type === "Super");

  return funcCall(
            member(
              funcCall(
                member(options.functionNode, "_get"),
                replaceSuper(node.callee.object, state, path.concat(["callee", "object"]), options),
                literal(node.callee.property.value || node.callee.property.name),
                id("this")),
                "call"),
            id("this"), ...node.arguments);
}
224538
private Context translateWhile(WyilFile.Stmt.While stmt, Context context) {
		WyilFile.Decl.FunctionOrMethod declaration = (WyilFile.Decl.FunctionOrMethod) context.getEnvironment()
				.getParent().enclosingDeclaration;
		// Translate the loop invariant and generate appropriate macro
		translateLoopInvariantMacros(stmt, declaration, context.wyalFile);
		// Rule 1. Check loop invariant on entry
		checkLoopInvariant("loop invariant may not hold on entry", stmt, context);
		// Rule 2. Check loop invariant preserved. On entry to the loop body we
		// must havoc all modified variables. This is necessary as such
		// variables should retain their values from before the loop.
		LoopScope scope = new LoopScope();
		Context beforeBodyContext = context.newLoopScope(scope).havoc(stmt.getModified());
		beforeBodyContext = assumeLoopInvariant(stmt, beforeBodyContext);
		Pair<Expr, Context> p = translateExpressionWithChecks(stmt.getCondition(), null, beforeBodyContext);
		Expr trueCondition = p.first();
		beforeBodyContext = p.second().assume(trueCondition);
		Context afterBodyContext = translateStatementBlock(stmt.getBody(), beforeBodyContext);
		// Join continue contexts together since they must also preserve the
		// loop invariant
		afterBodyContext = joinDescendants(beforeBodyContext, afterBodyContext, scope.continueContexts);
		checkLoopInvariant("loop invariant may not be restored", stmt, afterBodyContext);
		// Rule 3. Assume loop invariant holds.
		Context exitContext = context.havoc(stmt.getModified());
		exitContext = assumeLoopInvariant(stmt, exitContext);
		Expr falseCondition = invertCondition(
				translateExpression(stmt.getCondition(), null, exitContext.getEnvironment()), stmt.getCondition());
		exitContext = exitContext.assume(falseCondition);
		//
		// Finally, need to join any break contexts
		exitContext = joinDescendants(context, exitContext, scope.breakContexts);
		//
		return exitContext;
	}
1070083
def _add_inline_definition(item, statement):
    '''
    
    '''
    global _current_statement
    backup = _current_statement

    type_, options = _expand_one_key_dictionary(item)
    _current_statement = UnnamedStatement(type=type_)
    _parse_statement(options)
    statement.add_child(_current_statement)

    _current_statement = backup
303382
function isModifyingProp(reference) {
			var node = reference.identifier;
			var parent = node.parent;

			while (parent && !stopNodePattern.test(parent.type)) {
				switch (parent.type) {

					// e.g. foo.a = 0;
					case "AssignmentExpression":
						return parent.left === node;

					// e.g. ++foo.a;
					case "UpdateExpression":
						return true;

					// e.g. delete foo.a;
					case "UnaryExpression":
						if (parent.operator === "delete") {
							return true;
						}
						break;

					// EXCLUDES: e.g. cache.get(foo.a).b = 0;
					case "CallExpression":
						if (parent.callee !== node) {
							return false;
						}
						break;

					// EXCLUDES: e.g. cache[foo.a] = 0;
					case "MemberExpression":
						if (parent.property === node) {
							return false;
						}
						break;

					default:
						break;
				}

				node = parent;
				parent = node.parent;
			}

			return false;
		}
1319751
private CFG inlineAll() throws CFGBuilderException {
        CFG result = new CFG();

        Context rootContext = new Context(null, topLevelSubroutine, result);
        rootContext.mapBlock(topLevelSubroutine.getEntry(), result.getEntry());
        rootContext.mapBlock(topLevelSubroutine.getExit(), result.getExit());

        BasicBlock resultStartBlock = rootContext.getBlock(topLevelSubroutine.getStartBlock());
        result.createEdge(result.getEntry(), resultStartBlock, START_EDGE);

        inline(rootContext);

        return result;
    }
623312
function replaceDefine(code) {
    var defineList = getDefineBlock(code);
    var segments = [];
    var index = 0;
    defineList.forEach(function (block) {

        if (block.type === 'function') {
            segments.push(code.slice(index, block.defineRange[0]));
            index = block.factoryRange[0] + 1;

            block.returnRange.forEach(function (range) {
                segments.push(code.slice(index, range[0]));
                segments.push('module.exports =');
                segments.push(code.slice(range[0] + 6, range[1]));
                index = range[1];
            });
            segments.push(code.slice(index, block.factoryRange[1] - 1));

            index = block.defineRange[1];
        }
        else if (block.type === 'object') {
            segments.push(code.slice(index, block.defineRange[0]));
            segments.push('module.exports = ');
            segments.push(code.slice(block.factoryRange[0], block.factoryRange[1]) + ';');
            index = block.defineRange[1];
        }
    });

    segments.push(code.slice(index));

    code = segments.join('');

    return code;
}
566650
function filterTransform (args, math, scope) {
    let x, callback

    if (args[0]) {
      x = args[0].compile().evaluate(scope)
    }

    if (args[1]) {
      if (isSymbolNode(args[1]) || isFunctionAssignmentNode(args[1])) {
        // a function pointer, like filter([3, -2, 5], myTestFunction)
        callback = args[1].compile().evaluate(scope)
      } else {
        // an expression like filter([3, -2, 5], x > 0)
        callback = compileInlineExpression(args[1], math, scope)
      }
    }

    return filter(x, callback)
  }
966989
function Function(node, parent, scope, state) {
    // skip over functions as whatever `arguments` we reference inside will refer
    // to the wrong function
    var oldNoOptimise = state.noOptimise;
    state.noOptimise = true;
    this.traverse(memberExpressionOptimisationVisitor, state);
    state.noOptimise = oldNoOptimise;
    this.skip();
  }
527047
function rewriteEndCallback(j, path) {
    // calls to t.end()
    const containsCalls =
        j(path)
            .find(j.CallExpression, {
                callee: {
                    object: { name: 't' },
                    property: { name: 'end' },
                },
            })
            .filter(p => {
                // if t.end is in the scope of the test function we remove it
                const outerParent = p.parent.parent.parent.node;
                const inTestScope =
                    outerParent.params &&
                    outerParent.params[0] &&
                    outerParent.params[0].name === 't';
                if (inTestScope) {
                    p.prune();
                    return null;
                }

                // else it might be used for async testing. We rename it to
                // familiar Jasmine 'done()'
                p.node.callee = j.identifier('done');
                return true;
            })
            .size() > 0;

    // references to t.end
    const containsReference =
        j(path)
            .find(j.MemberExpression, {
                object: { name: 't' },
                property: { name: 'end' },
            })
            .replaceWith(j.identifier('done'))
            .size() > 0;

    return containsCalls || containsReference;
}
1246047
def call(self, fn, args, name='', cconv=None, tail=False, fastmath=()):
        
        inst = instructions.CallInstr(self.block, fn, args, name=name,
                                      cconv=cconv, tail=tail, fastmath=fastmath)
        self._insert(inst)
        return inst
778378
Rule inlineIfExpressionChaining() {
		return Sequence(
				conditionalOrExpressionChaining().label("head"),
				set(),
				Optional(
						Sequence(
								Sequence(Ch('?'), TestNot(FirstOf(Ch('.'), Ch(':'), Ch('?')))).label("operator1"),
								group.basics.optWS(),
								assignmentExpressionChaining().label("tail1"),
								Ch(':').label("operator2"),
								group.basics.optWS(),
								inlineIfExpressionChaining().label("tail2")
								)),
				set(actions.createInlineIfExpression(value("head"),
						node("Optional/Sequence/operator1"), node("Optional/Sequence/operator2"),
						value("Optional/Sequence/tail1"), value("Optional/Sequence/tail2"))),
				group.basics.optWS());
	}
360478
private boolean validateUnaliasablePrimitiveCall(NodeTraversal t, Node n, String methodName) {
    return validatePrimitiveCallWithMessage(t, n, methodName, CLOSURE_CALL_CANNOT_BE_ALIASED_ERROR);
  }