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 ; }
Inline a function that fulfills the requirements of canInlineReferenceDirectly into the call site replacing only the CALL node .