use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseReturnStatement.
// 12.9 The return Statement
private ParseTree parseReturnStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.RETURN);
ParseTree expression = null;
if (!peekImplicitSemiColon()) {
expression = parseExpression();
}
eatPossiblyImplicitSemiColon();
return new ReturnStatementTree(getTreeLocation(start), expression);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseSetAccessor.
private ParseTree parseSetAccessor(PartialClassElement partial) {
eatPredefinedString(PredefinedName.SET);
if (peekPropertyName(0)) {
Token propertyName = eatObjectLiteralPropertyName();
FormalParameterListTree parameter = parseSetterParameterList();
BlockTree body = parseFunctionBody();
recordFeatureUsed(Feature.SETTER);
return new SetAccessorTree(getTreeLocation(partial.start), propertyName, partial.isStatic, parameter, body);
} else {
ParseTree property = parseComputedPropertyName();
FormalParameterListTree parameter = parseSetterParameterList();
BlockTree body = parseFunctionBody();
recordFeatureUsed(Feature.SETTER);
return new ComputedPropertySetterTree(getTreeLocation(partial.start), property, partial.isStatic, parameter, body);
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseExponentiationExpression.
private ParseTree parseExponentiationExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseUnaryExpression();
if (peek(TokenType.STAR_STAR)) {
// -x**y is a syntax error
if (left.type == ParseTreeType.UNARY_EXPRESSION) {
reportError("Unary operator '%s' requires parentheses before '**'", left.asUnaryExpression().operator);
}
Token operator = nextToken();
ParseTree right = parseExponentiationExpression();
return new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
} else {
return left;
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parsePropertyAssignmentGenerator.
private ParseTree parsePropertyAssignmentGenerator() {
TokenType type = peekType(1);
if (type == TokenType.STRING || type == TokenType.NUMBER || type == TokenType.IDENTIFIER || Keywords.isKeyword(type)) {
// parseMethodDeclaration will consume the '*'.
return parseMethodDeclaration();
} else {
SourcePosition start = getTreeStartLocation();
eat(TokenType.STAR);
ParseTree name = parseComputedPropertyName();
FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.EXPRESSION);
parseFunctionTail(builder, FunctionFlavor.GENERATOR);
ParseTree value = builder.build(getTreeLocation(start));
return new ComputedPropertyMethodTree(getTreeLocation(start), name, value);
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method completeArrowFunctionParseAtArrow.
private ParseTree completeArrowFunctionParseAtArrow(ParseTree leftOfArrow, Expression expressionIn) {
FormalParameterListTree arrowFormalParameters = transformToArrowFormalParameters(leftOfArrow);
if (peekImplicitSemiColon()) {
reportError("No newline allowed before '=>'");
}
eat(TokenType.ARROW);
ParseTree arrowFunctionBody = parseArrowFunctionBody(expressionIn, FunctionFlavor.NORMAL);
FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.ARROW).setFormalParameterList(arrowFormalParameters).setFunctionBody(arrowFunctionBody);
return builder.build(getTreeLocation(arrowFormalParameters.location.start));
}
Aggregations