use of com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree in project closure-compiler by google.
the class Parser method parseFormalParameterList.
private FormalParameterListTree parseFormalParameterList() {
SourcePosition listStart = getTreeStartLocation();
eat(TokenType.OPEN_PAREN);
ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
boolean trailingComma = false;
ImmutableList.Builder<SourcePosition> commaPositions = ImmutableList.builder();
while (peekParameter()) {
result.add(parseParameter());
if (!peek(TokenType.CLOSE_PAREN)) {
Token comma = eat(TokenType.COMMA);
if (comma != null) {
commaPositions.add(comma.getStart());
} else {
// semi-arbitrary comma position in case the code is syntactially invalid & missing one
commaPositions.add(getTreeEndLocation());
}
if (peek(TokenType.CLOSE_PAREN)) {
recordFeatureUsed(Feature.TRAILING_COMMA_IN_PARAM_LIST);
if (!config.atLeast8) {
reportError(comma, "Invalid trailing comma in formal parameter list");
}
trailingComma = true;
}
}
}
eat(TokenType.CLOSE_PAREN);
return new FormalParameterListTree(getTreeLocation(listStart), result.build(), trailingComma, commaPositions.build());
}
use of com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree 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.FormalParameterListTree 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));
}
use of com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree 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));
}
Aggregations