* @return a JsExpression representing all expressions that would have been
* evaluated by the statement
*/
private static JsExpression hoistedExpression(JsProgram program,
JsStatement statement, List<JsName> localVariableNames) {
JsExpression expression;
if (statement instanceof JsExprStmt) {
// Extract the expression
JsExprStmt exprStmt = (JsExprStmt) statement;
expression = exprStmt.getExpression();
} else if (statement instanceof JsReturn) {
// Extract the return value
JsReturn ret = (JsReturn) statement;
expression = ret.getExpr();
if (expression == null) {
expression = program.getUndefinedLiteral();
}
} else if (statement instanceof JsVars) {
// Create a comma expression for variable initializers
JsVars vars = (JsVars) statement;
// Rely on comma expression cleanup to remove this later.
expression = program.getNullLiteral();
for (JsVar var : vars) {
// Record the locally-defined variable
localVariableNames.add(var.getName());
// Extract the initialization expression
JsExpression init = var.getInitExpr();
if (init != null) {
SourceInfo sourceInfo = var.getSourceInfo().makeChild(
JsInliner.class, "Hoisted initializer into inline site");
JsBinaryOperation assignment = new JsBinaryOperation(sourceInfo,
JsBinaryOperator.ASG);