use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseAsyncFunctionExpression.
private ParseTree parseAsyncFunctionExpression() {
SourcePosition start = getTreeStartLocation();
eatAsyncFunctionStart();
boolean generator = peek(TokenType.STAR);
if (generator) {
eat(TokenType.STAR);
}
FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.EXPRESSION).setName(eatIdOpt()).setAsync(true);
parseFunctionTail(builder, generator ? FunctionFlavor.ASYNCHRONOUS_GENERATOR : FunctionFlavor.ASYNCHRONOUS);
return builder.build(getTreeLocation(start));
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseIterSpread.
private IterSpreadTree parseIterSpread() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.ELLIPSIS);
ParseTree operand = parseAssignmentExpression();
return new IterSpreadTree(getTreeLocation(start), operand);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseFunctionBody.
private BlockTree parseFunctionBody() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.OPEN_CURLY);
ImmutableList<ParseTree> result = parseSourceElementList();
eat(TokenType.CLOSE_CURLY);
return new BlockTree(getTreeLocation(start), result);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseBlock.
// 12.1 Block
private BlockTree parseBlock() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.OPEN_CURLY);
// Spec says Statement list. However functions are also embedded in the wild.
ImmutableList<ParseTree> result = parseSourceElementList();
eat(TokenType.CLOSE_CURLY);
return new BlockTree(getTreeLocation(start), result);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseArrayLiteral.
// 11.1.4 Array Literal Expression
private ParseTree parseArrayLiteral() {
// ArrayLiteral :
// [ Elisionopt ]
// [ ElementList ]
// [ ElementList , Elisionopt ]
//
// ElementList :
// Elisionopt AssignmentOrSpreadExpression
// ElementList , Elisionopt AssignmentOrSpreadExpression
//
// Elision :
// ,
// Elision ,
SourcePosition start = getTreeStartLocation();
ImmutableList.Builder<ParseTree> elements = ImmutableList.builder();
eat(TokenType.OPEN_SQUARE);
Token trailingCommaToken = null;
while (peek(TokenType.COMMA) || peek(TokenType.ELLIPSIS) || peekAssignmentExpression()) {
trailingCommaToken = null;
if (peek(TokenType.COMMA)) {
SourcePosition commaStart = getTreeStartLocation();
trailingCommaToken = eat(TokenType.COMMA);
// Consider the empty element to start & end immediately before the comma token.
elements.add(new NullTree(new SourceRange(commaStart, commaStart)));
} else {
if (peek(TokenType.ELLIPSIS)) {
recordFeatureUsed(Feature.SPREAD_EXPRESSIONS);
elements.add(parseIterSpread());
} else {
elements.add(parseAssignmentExpression());
}
if (!peek(TokenType.CLOSE_SQUARE)) {
trailingCommaToken = eat(TokenType.COMMA);
}
}
}
eat(TokenType.CLOSE_SQUARE);
maybeReportTrailingComma(trailingCommaToken);
return new ArrayLiteralExpressionTree(getTreeLocation(start), elements.build(), trailingCommaToken != null);
}
Aggregations