use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseWhileStatement.
// 12.6.2 The while Statement
private ParseTree parseWhileStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.WHILE);
eat(TokenType.OPEN_PAREN);
ParseTree condition = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new WhileStatementTree(getTreeLocation(start), condition, body);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseAsyncArrowFunction.
private ParseTree parseAsyncArrowFunction(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
eatPredefinedString(ASYNC);
if (peekImplicitSemiColon()) {
reportError("No newline allowed between `async` and arrow function parameter list");
}
FormalParameterListTree arrowParameterList = null;
if (peek(TokenType.OPEN_PAREN)) {
// async (...) =>
arrowParameterList = parseFormalParameterList();
} else {
// async arg =>
final IdentifierExpressionTree singleParameter = parseIdentifierExpression();
arrowParameterList = new FormalParameterListTree(singleParameter.location, ImmutableList.<ParseTree>of(singleParameter), /* hasTrailingComma= */
false, ImmutableList.<SourcePosition>of());
}
if (peekImplicitSemiColon()) {
reportError("No newline allowed before '=>'");
}
eat(TokenType.ARROW);
ParseTree arrowFunctionBody = parseArrowFunctionBody(expressionIn, FunctionFlavor.ASYNCHRONOUS);
FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.ARROW).setAsync(true).setFormalParameterList(arrowParameterList).setFunctionBody(arrowFunctionBody);
return builder.build(getTreeLocation(start));
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseVariableDeclaration.
private VariableDeclarationTree parseVariableDeclaration(final TokenType binding, Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree lvalue;
if (peekPatternStart()) {
lvalue = parsePattern(PatternKind.INITIALIZER);
} else {
lvalue = parseIdentifierExpression();
}
ParseTree initializer = null;
if (peek(TokenType.EQUAL)) {
initializer = parseInitializer(expressionIn);
} else if (expressionIn != Expression.NO_IN) {
// NOTE(blickly): this is a bit of a hack, declarations outside of for statements allow "in",
// and by chance, also must have initializers for const/destructuring. Vanilla for loops
// also require intializers, but are handled separately in checkVanillaForInitializers
maybeReportNoInitializer(binding, lvalue);
}
return new VariableDeclarationTree(getTreeLocation(start), lvalue, initializer);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseFieldDefinition.
private ParseTree parseFieldDefinition(PartialClassElement partial) {
ParseTree initializer = null;
if (peek(TokenType.EQUAL)) {
initializer = parseInitializer(Expression.NORMAL);
}
eatPossiblyImplicitSemiColon();
if (partial.getName() != null) {
checkState(partial.getNameExpr() == null);
return new FieldDeclarationTree(getTreeLocation(partial.start), partial.getName(), partial.isStatic, initializer);
} else {
return new ComputedPropertyFieldTree(getTreeLocation(partial.start), partial.getNameExpr(), partial.isStatic, initializer);
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseArrowFunctionBody.
private ParseTree parseArrowFunctionBody(Expression expressionIn, FunctionFlavor functionFlavor) {
functionContextStack.addLast(functionFlavor);
ParseTree arrowFunctionBody;
if (peek(TokenType.OPEN_CURLY)) {
arrowFunctionBody = parseFunctionBody();
} else {
arrowFunctionBody = parseAssignment(expressionIn);
}
functionContextStack.removeLast();
return arrowFunctionBody;
}
Aggregations