use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseAmbientFunctionDeclaration.
private ParseTree parseAmbientFunctionDeclaration() {
SourcePosition start = getTreeStartLocation();
eat(Keywords.FUNCTION.type);
boolean isGenerator = eatOpt(TokenType.STAR) != null;
IdentifierToken name = eatId();
return parseAmbientFunctionDeclaration(start, name, isGenerator);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseCallSignature.
private CallSignatureTree parseCallSignature(boolean isNew) {
SourcePosition start = getTreeStartLocation();
if (isNew) {
eat(TokenType.NEW);
}
GenericTypeListTree generics = maybeParseGenericTypes();
FormalParameterListTree params = parseFormalParameterList(ParamContext.SIGNATURE);
ParseTree returnType = maybeParseColonType();
return new CallSignatureTree(getTreeLocation(start), isNew, generics, params, returnType);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseFormalParameterList.
private FormalParameterListTree parseFormalParameterList(ParamContext context) {
SourcePosition listStart = getTreeStartLocation();
eat(TokenType.OPEN_PAREN);
ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
while (peekParameter(context)) {
result.add(parseParameter(context));
if (!peek(TokenType.CLOSE_PAREN)) {
Token comma = eat(TokenType.COMMA);
if (peek(TokenType.CLOSE_PAREN)) {
features = features.with(Feature.TRAILING_COMMA_IN_PARAM_LIST);
if (!config.atLeast8) {
reportError(comma, "Invalid trailing comma in formal parameter list");
}
}
}
}
eat(TokenType.CLOSE_PAREN);
return new FormalParameterListTree(getTreeLocation(listStart), result.build());
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition 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.util.SourcePosition in project closure-compiler by google.
the class Parser method parseRestParameter.
private ParseTree parseRestParameter() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.SPREAD);
return new RestParameterTree(getTreeLocation(start), parseRestAssignmentTarget(PatternKind.INITIALIZER));
}
Aggregations