private static ParseTree findNearestNode(ParseTree tree) { while (true) { switch (tree.type) { case EXPRESSION_STATEMENT: tree = tree.asExpressionStatement().expression; continue; case CALL_EXPRESSION: tree = tree.asCallExpression().operand; continue; case BINARY_OPERATOR: tree = tree.asBinaryOperator().left; continue; case CONDITIONAL_EXPRESSION: tree = tree.asConditionalExpression().condition; continue; case MEMBER_EXPRESSION: tree = tree.asMemberExpression().operand; continue; case MEMBER_LOOKUP_EXPRESSION: tree = tree.asMemberLookupExpression().operand; continue; case UPDATE_EXPRESSION: tree = tree.asUpdateExpression().operand; continue; default: return tree; } } }
private static ParseTree findNearestNode(ParseTree tree) { while (true) { switch (tree.type) { case EXPRESSION_STATEMENT: tree = tree.asExpressionStatement().expression; continue; case CALL_EXPRESSION: tree = tree.asCallExpression().operand; continue; case BINARY_OPERATOR: tree = tree.asBinaryOperator().left; continue; case CONDITIONAL_EXPRESSION: tree = tree.asConditionalExpression().condition; continue; case MEMBER_EXPRESSION: tree = tree.asMemberExpression().operand; continue; case MEMBER_LOOKUP_EXPRESSION: tree = tree.asMemberLookupExpression().operand; continue; case POSTFIX_EXPRESSION: tree = tree.asPostfixExpression().operand; continue; default: return tree; } } }
public Node process(ParseTree node) { switch (node.type) { case BINARY_OPERATOR: return processBinaryExpression(node.asBinaryOperator()); case ARRAY_LITERAL_EXPRESSION: return processArrayLiteral(node.asArrayLiteralExpression()); case TEMPLATE_LITERAL_EXPRESSION: return processTemplateLiteral(node.asTemplateLiteralExpression()); case TEMPLATE_LITERAL_PORTION: return processTemplateLiteralPortion(node.asTemplateLiteralPortion()); case TEMPLATE_SUBSTITUTION: return processTemplateSubstitution(node.asTemplateSubstitution()); case UNARY_EXPRESSION: return processUnaryExpression(node.asUnaryExpression()); case BLOCK: return processBlock(node.asBlock()); case BREAK_STATEMENT: return processBreakStatement(node.asBreakStatement()); case CALL_EXPRESSION: return processFunctionCall(node.asCallExpression()); case CASE_CLAUSE: return processSwitchCase(node.asCaseClause()); case DEFAULT_CLAUSE: return processSwitchDefault(node.asDefaultClause()); case CATCH: return processCatchClause(node.asCatch()); case CONTINUE_STATEMENT: return processContinueStatement(node.asContinueStatement()); case DO_WHILE_STATEMENT: return processDoLoop(node.asDoWhileStatement());
private Node processObjectPatternElement(ParseTree child) { switch (child.type) { case DEFAULT_PARAMETER: // shorthand with a default value // let { /** inlineType */ name = default } = something; return processObjectPatternShorthandWithDefault(child.asDefaultParameter()); case PROPERTY_NAME_ASSIGNMENT: return processObjectPatternPropertyNameAssignment(child.asPropertyNameAssignment()); case COMPUTED_PROPERTY_DEFINITION: // let {[expression]: /** inlineType */ name} = something; ComputedPropertyDefinitionTree computedPropertyDefinition = child.asComputedPropertyDefinition(); return processObjectPatternComputedPropertyDefinition(computedPropertyDefinition); default: // let {...restObject} = someObject; checkState(child.type == ParseTreeType.ASSIGNMENT_REST_ELEMENT, child); maybeWarnForFeature(child, Feature.OBJECT_PATTERN_REST); return processAssignmentRestElement(child.asAssignmentRestElement()); } }
private boolean isStartOfAsyncArrowFunction(ParseTree partialExpression) { if (partialExpression.type == ParseTreeType.IDENTIFIER_EXPRESSION) { final IdentifierToken identifierToken = partialExpression.asIdentifierExpression().identifierToken; // partialExpression is `async` // followed by `[no newline] bindingIdentifier [no newline] =>` return identifierToken.value.equals(ASYNC) && !peekImplicitSemiColon(0) && peekId() && !peekImplicitSemiColon(1) && peek(1, TokenType.ARROW); } else if (partialExpression.type == ParseTreeType.CALL_EXPRESSION) { final CallExpressionTree callExpression = partialExpression.asCallExpression(); ParseTree callee = callExpression.operand; ParseTree arguments = callExpression.arguments; // partialExpression is `async [no newline] (parameters)` // followed by `[no newline] =>` return callee.type == ParseTreeType.IDENTIFIER_EXPRESSION && callee.asIdentifierExpression().identifierToken.value.equals(ASYNC) && callee.location.end.line == arguments.location.start.line && !peekImplicitSemiColon() && peek(TokenType.ARROW); } else { return false; } }
private ParseTree completeAssignmentExpressionParseAtArrow( ParseTree leftOfArrow, Expression expressionIn) { if (leftOfArrow.type == ParseTreeType.CALL_EXPRESSION) { // ... someAssignmentExpression // implicit semicolon // (args) => return completeAssignmentExpressionParseAtArrow(leftOfArrow.asCallExpression()); } else { return completeArrowFunctionParseAtArrow(leftOfArrow, expressionIn); } }
public Node process(ParseTree node) { switch (node.type) { case BINARY_OPERATOR: return processBinaryExpression(node.asBinaryOperator()); case ARRAY_LITERAL_EXPRESSION: return processArrayLiteral(node.asArrayLiteralExpression()); case TEMPLATE_LITERAL_EXPRESSION: return processTemplateLiteral(node.asTemplateLiteralExpression()); case TEMPLATE_LITERAL_PORTION: return processTemplateLiteralPortion(node.asTemplateLiteralPortion()); case TEMPLATE_SUBSTITUTION: return processTemplateSubstitution(node.asTemplateSubstitution()); case UNARY_EXPRESSION: return processUnaryExpression(node.asUnaryExpression()); case BLOCK: return processBlock(node.asBlock()); case BREAK_STATEMENT: return processBreakStatement(node.asBreakStatement()); case CALL_EXPRESSION: return processFunctionCall(node.asCallExpression()); case CASE_CLAUSE: return processSwitchCase(node.asCaseClause()); case DEFAULT_CLAUSE: return processSwitchDefault(node.asDefaultClause()); case CATCH: return processCatchClause(node.asCatch()); case CONTINUE_STATEMENT: return processContinueStatement(node.asContinueStatement()); case DO_WHILE_STATEMENT: return processDoLoop(node.asDoWhileStatement());