use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseParameter.
private ParseTree parseParameter(ParamContext context) {
SourcePosition start = getTreeStartLocation();
ParseTree parameter = null;
if (peek(TokenType.SPREAD)) {
parameter = parseRestParameter();
} else if (peekId()) {
parameter = parseIdentifierExpression();
if (peek(TokenType.QUESTION)) {
eat(TokenType.QUESTION);
parameter = new OptionalParameterTree(getTreeLocation(start), parameter);
}
} else if (context != ParamContext.TYPE_EXPRESSION && peekPatternStart()) {
parameter = parsePattern(PatternKind.INITIALIZER);
} else {
throw new IllegalStateException("parseParameterCalled() without confirming a parameter exists.");
}
ParseTree typeAnnotation = null;
SourceRange typeLocation = null;
if (peek(TokenType.COLON)) {
if (peek(1, TokenType.STRING)) {
eat(TokenType.COLON);
// Specialized Signature
typeAnnotation = parseLiteralExpression();
} else {
typeAnnotation = parseTypeAnnotation();
}
typeLocation = getTreeLocation(getTreeStartLocation());
}
if (context == ParamContext.IMPLEMENTATION && !parameter.isRestParameter() && peek(TokenType.EQUAL)) {
eat(TokenType.EQUAL);
ParseTree defaultValue = parseAssignmentExpression();
parameter = new DefaultParameterTree(getTreeLocation(start), parameter, defaultValue);
}
if (typeAnnotation != null) {
// Must be a direct child of the parameter list.
parameter = new TypedParameterTree(typeLocation, parameter, typeAnnotation);
}
return parameter;
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseTypeArgumentList.
private ParseTree parseTypeArgumentList(SourcePosition start, TypeNameTree typeName) {
// < TypeArgumentList >
// TypeArgumentList , TypeArgument
eat(TokenType.OPEN_ANGLE);
scanner.incTypeParameterLevel();
ImmutableList.Builder<ParseTree> typeArguments = ImmutableList.builder();
ParseTree type = parseType();
typeArguments.add(type);
while (peek(TokenType.COMMA)) {
eat(TokenType.COMMA);
type = parseType();
if (type != null) {
typeArguments.add(type);
}
}
eat(TokenType.CLOSE_ANGLE);
scanner.decTypeParameterLevel();
return new ParameterizedTypeTree(getTreeLocation(start), typeName, typeArguments.build());
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseArguments.
private ArgumentListTree parseArguments() {
// ArgumentList :
// AssignmentOrSpreadExpression
// ArgumentList , AssignmentOrSpreadExpression
//
// AssignmentOrSpreadExpression :
// ... AssignmentExpression
// AssignmentExpression
SourcePosition start = getTreeStartLocation();
ImmutableList.Builder<ParseTree> arguments = ImmutableList.builder();
boolean trailingComma = false;
ImmutableList.Builder<SourcePosition> commaPositions = ImmutableList.builder();
eat(TokenType.OPEN_PAREN);
while (peekAssignmentOrSpread()) {
arguments.add(parseAssignmentOrSpread());
if (!peek(TokenType.CLOSE_PAREN)) {
Token comma = eat(TokenType.COMMA);
if (comma != null) {
commaPositions.add(comma.getStart());
}
if (peek(TokenType.CLOSE_PAREN)) {
recordFeatureUsed(Feature.TRAILING_COMMA_IN_PARAM_LIST);
if (!config.atLeast8) {
reportError(comma, "Invalid trailing comma in arguments list");
}
trailingComma = true;
}
}
}
eat(TokenType.CLOSE_PAREN);
return new ArgumentListTree(getTreeLocation(start), arguments.build(), trailingComma, commaPositions.build());
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseAwaitExpression.
private ParseTree parseAwaitExpression() {
SourcePosition start = getTreeStartLocation();
if (functionContextStack.isEmpty() || !functionContextStack.peekLast().isAsynchronous) {
reportError("'await' used in a non-async function context");
}
eatPredefinedString(AWAIT);
ParseTree expression = parseUnaryExpression();
return new AwaitExpressionTree(getTreeLocation(start), expression);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseLogicalAND.
// 11.11 Logical AND
private ParseTree parseLogicalAND(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseBitwiseOR(expressionIn);
while (peek(TokenType.AND)) {
Token operator = eat(TokenType.AND);
ParseTree right = parseBitwiseOR(expressionIn);
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
}
Aggregations