use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseWithStatement.
// 12.10 The with Statement
private ParseTree parseWithStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.WITH);
eat(TokenType.OPEN_PAREN);
ParseTree expression = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new WithStatementTree(getTreeLocation(start), expression, body);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseBitwiseOR.
// 11.10 Bitwise OR
private ParseTree parseBitwiseOR(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseBitwiseXOR(expressionIn);
while (peek(TokenType.BAR)) {
Token operator = eat(TokenType.BAR);
ParseTree right = parseBitwiseXOR(expressionIn);
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseFunctionExpression.
private ParseTree parseFunctionExpression() {
SourcePosition start = getTreeStartLocation();
eat(Keywords.FUNCTION.type);
boolean isGenerator = eatOpt(TokenType.STAR) != null;
FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.EXPRESSION).setName(eatIdOpt());
parseFunctionTail(builder, isGenerator ? FunctionFlavor.GENERATOR : FunctionFlavor.NORMAL);
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 transformToArrowFormalParameters.
private FormalParameterListTree transformToArrowFormalParameters(ParseTree leftOfArrow) {
FormalParameterListTree arrowParameterList;
switch(leftOfArrow.type) {
case FORMAL_PARAMETER_LIST:
arrowParameterList = leftOfArrow.asFormalParameterList();
break;
case IDENTIFIER_EXPRESSION:
// e.g. x => x + 1
arrowParameterList = new FormalParameterListTree(leftOfArrow.location, ImmutableList.<ParseTree>of(leftOfArrow), /* hasTrailingComma= */
false, ImmutableList.<SourcePosition>of());
break;
case ARGUMENT_LIST:
case PAREN_EXPRESSION:
// e.g. (x) => x + 1
resetScanner(leftOfArrow);
// If we fail to parse as an ArrowFunction parameter list then
// parseFormalParameterList will take care of reporting errors.
arrowParameterList = parseFormalParameterList();
break;
default:
reportError(leftOfArrow, "invalid arrow function parameters");
arrowParameterList = newEmptyFormalParameterList(leftOfArrow.location);
}
return arrowParameterList;
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method maybeParseOptionalExpression.
/**
* Tries to parse the expression as an optional expression.
*
* <p>`operand?.identifier` or `operand?.[expression]` or `operand?.(arg1, arg2)`
*
* <p>returns parse tree after trying to parse it as an optional expression
*/
private ParseTree maybeParseOptionalExpression(ParseTree operand) {
// The optional chain's source info should cover the lhs operand also
SourcePosition start = operand.location.start;
while (peek(TokenType.QUESTION_DOT)) {
eat(TokenType.QUESTION_DOT);
switch(peekType()) {
case OPEN_PAREN:
ArgumentListTree arguments = parseArguments();
operand = new OptChainCallExpressionTree(getTreeLocation(start), operand, arguments, /* isStartOfOptionalChain = */
true, arguments.hasTrailingComma);
break;
case OPEN_SQUARE:
eat(TokenType.OPEN_SQUARE);
ParseTree member = parseExpression();
eat(TokenType.CLOSE_SQUARE);
operand = new OptionalMemberLookupExpressionTree(getTreeLocation(start), operand, member, /* isStartOfOptionalChain = */
true);
break;
case NO_SUBSTITUTION_TEMPLATE:
case TEMPLATE_HEAD:
reportError("template literal cannot be used within optional chaining");
break;
default:
if (peekIdOrKeyword()) {
IdentifierToken id = eatIdOrKeywordAsId();
operand = new OptionalMemberExpressionTree(getTreeLocation(start), operand, id, /* isStartOfOptionalChain = */
true);
} else {
reportError("syntax error: %s not allowed in optional chain", peekType());
}
}
operand = parseRemainingOptionalChainSegment(operand);
}
return operand;
}
Aggregations