use of com.google.javascript.jscomp.parsing.parser.trees.OptionalParameterTree 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;
}
Aggregations