/** * Directive value or null if statement is not a directive. * * @param stmt Statement to be checked * @return Directive value if the given statement is a directive */ private String getDirective(final Node stmt) { if (stmt instanceof ExpressionStatement) { final Node expr = ((ExpressionStatement)stmt).getExpression(); if (expr instanceof LiteralNode) { final LiteralNode<?> lit = (LiteralNode<?>)expr; final long litToken = lit.getToken(); final TokenType tt = Token.descType(litToken); // A directive is either a string or an escape string if (tt == TokenType.STRING || tt == TokenType.ESCSTRING) { // Make sure that we don't unescape anything. Return as seen in source! return source.getString(lit.getStart(), Token.descLength(litToken)); } } } return null; }
@Override public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) { // handle debugger statement final Node expression = expressionStatement.getExpression(); if (expression instanceof RuntimeNode) { expression.accept(this); return false; } enterDefault(expressionStatement); type("ExpressionStatement"); comma(); property("expression"); expression.accept(this); return leave(); }
@Override public Node leaveExpressionStatement(final ExpressionStatement expressionStatement) { final Expression expr = expressionStatement.getExpression(); ExpressionStatement node = expressionStatement; final FunctionNode currentFunction = lc.getCurrentFunction(); if (currentFunction.isProgram()) { if (!isInternalExpression(expr) && !isEvalResultAssignment(expr)) { node = expressionStatement.setExpression( new BinaryNode( Token.recast( expressionStatement.getToken(), TokenType.ASSIGN), compilerConstant(RETURN), expr)); } } return addStatement(node); }
@Override public Node leaveBlock(final Block block) { if (!artificialBlock) { if (lc.isFunctionBody()) { // Prepend declaration-only var statements to the top of the statement list. lc.prependStatements(getCurrentFunctionState().varStatements); } else if (lc.isSplitBody()) { appendSplitReturn(FALLTHROUGH_STATE, NO_LINE_NUMBER); if (getCurrentFunctionState().fn.isProgram()) { // If we're splitting the program, make sure every shard ends with "return :return" and // begins with ":return = :return-in;". lc.prependStatement(new ExpressionStatement(NO_LINE_NUMBER, NO_TOKEN, NO_FINISH, new BinaryNode(Token.toDesc(TokenType.ASSIGN, 0, 0), createReturnIdent(), createReturnParamIdent()))); } } } return block; }
@Override public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) { // handle debugger statement final Node expression = expressionStatement.getExpression(); if (expression instanceof RuntimeNode) { assert false : "should not reach here: RuntimeNode"; return false; } enterDefault(expressionStatement); type("ExpressionStatement"); comma(); property("expression"); expression.accept(this); return leave(); }
@Override public Node leaveExpressionStatement(final ExpressionStatement expressionStatement) { final Expression expr = expressionStatement.getExpression(); ExpressionStatement node = expressionStatement; final FunctionNode currentFunction = lc.getCurrentFunction(); if (currentFunction.isProgram()) { if (!isInternalExpression(expr) && !isEvalResultAssignment(expr)) { node = expressionStatement.setExpression( new BinaryNode( Token.recast( expressionStatement.getToken(), TokenType.ASSIGN), compilerConstant(RETURN), expr)); } } if (es6 && expressionStatement.destructuringDeclarationType() != null) { throwNotImplementedYet("es6.destructuring", expressionStatement); } return addStatement(node); }
/** * DebuggerStatement : * debugger ; * * See 12.15 * * Parse debugger statement. */ private void debuggerStatement() { // Capture DEBUGGER token. final int debuggerLine = line; final long debuggerToken = token; // DEBUGGER tested in caller. next(); endOfLine(); appendStatement(new ExpressionStatement(debuggerLine, debuggerToken, finish, new RuntimeNode(debuggerToken, finish, RuntimeNode.Request.DEBUGGER, new ArrayList<Expression>()))); }
@Override public Node leaveVarNode(final VarNode varNode) { addStatement(varNode); if (varNode.getFlag(VarNode.IS_LAST_FUNCTION_DECLARATION) && lc.getCurrentFunction().isProgram()) { new ExpressionStatement(varNode.getLineNumber(), varNode.getToken(), varNode.getFinish(), new IdentNode(varNode.getName())).accept(this); } return varNode; }
@Override public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) { final Expression expr = expressionStatement.getExpression(); if(!expr.isSelfModifying()) { tagNeverOptimistic(expr); } return true; }