/** * Return a new {@link FunctionDeclarationTree}. * * <p> The location is provided at this point because it cannot be correctly calculated * until the whole function has been parsed. */ public FunctionDeclarationTree build(SourceRange location) { this.location = location; return new FunctionDeclarationTree(this); } }
public static UpdateExpressionTree postfix( SourceRange location, Token operator, ParseTree operand) { return new UpdateExpressionTree(location, operator, OperatorPosition.POSTFIX, operand); } }
public boolean isPattern() { ParseTree parseTree = this; while (parseTree.type == ParseTreeType.PAREN_EXPRESSION) { parseTree = parseTree.asParenExpression().expression; } switch (parseTree.type) { case ARRAY_PATTERN: case OBJECT_PATTERN: return true; default: return false; } }
private FunctionDeclarationTree parseAmbientFunctionDeclaration( SourcePosition start, IdentifierToken name, boolean isGenerator) { FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.DECLARATION) .setName(name) .setGenerator(isGenerator) .setGenerics(maybeParseGenericTypes()) .setFormalParameterList(parseFormalParameterList(ParamContext.SIGNATURE)) .setReturnType(maybeParseColonType()) .setFunctionBody(new EmptyStatementTree(getTreeLocation(start))); return builder.build(getTreeLocation(start)); }
private FunctionDeclarationTree parseAmbientFunctionDeclaration(SourcePosition start, IdentifierToken name, boolean isGenerator) { GenericTypeListTree generics = maybeParseGenericTypes(); FormalParameterListTree formalParameterList = parseFormalParameterList(ParamContext.SIGNATURE); ParseTree returnType = maybeParseColonType(); ParseTree functionBody = new EmptyStatementTree(getTreeLocation(start)); FunctionDeclarationTree declaration = new FunctionDeclarationTree( getTreeLocation(start), name, generics, false, isGenerator, false, null, FunctionDeclarationTree.Kind.DECLARATION, formalParameterList, returnType, functionBody); return declaration; }
private IndexSignatureTree parseIndexSignature() { SourcePosition start = getTreeStartLocation(); eat(TokenType.OPEN_SQUARE); IdentifierToken name = eatIdOrKeywordAsId(); eat(TokenType.COLON); ParseTree indexType = parseTypeName(); // must be 'string' or 'number' eat(TokenType.CLOSE_SQUARE); eat(TokenType.COLON); ParseTree declaredType = parseType(); ParseTree nameTree = new MemberVariableTree(getTreeLocation(start), name, false, false, null, indexType); return new IndexSignatureTree(getTreeLocation(start), nameTree, declaredType); }
private ParseTree parseAsyncFunctionDeclaration() { SourcePosition start = getTreeStartLocation(); eatAsyncFunctionStart(); boolean generator = peek(TokenType.STAR); if (generator) { eat(TokenType.STAR); } FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.DECLARATION) .setName(eatId()) .setAsync(true); parseFunctionTail( builder, generator ? FunctionFlavor.ASYNCHRONOUS_GENERATOR : FunctionFlavor.ASYNCHRONOUS); return builder.build(getTreeLocation(start)); }
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)); }
private ParseTree parseFunctionDeclaration() { SourcePosition start = getTreeStartLocation(); eat(Keywords.FUNCTION.type); boolean isGenerator = eatOpt(TokenType.STAR) != null; FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.DECLARATION).setName(eatId()); parseFunctionTail(builder, isGenerator ? FunctionFlavor.GENERATOR : FunctionFlavor.NORMAL); return builder.build(getTreeLocation(start)); }
private LiteralExpressionTree parseLiteralExpression() { SourcePosition start = getTreeStartLocation(); Token literal = nextLiteralToken(); return new LiteralExpressionTree(getTreeLocation(start), literal); }
private VariableStatementTree parseVariableStatement() { SourcePosition start = getTreeStartLocation(); VariableDeclarationListTree declarations = parseVariableDeclarationList(); eatPossibleImplicitSemiColon(); return new VariableStatementTree(getTreeLocation(start), declarations); }
private ParseTree parseBreakStatement() { SourcePosition start = getTreeStartLocation(); eat(TokenType.BREAK); IdentifierToken name = null; if (!peekImplicitSemiColon()) { name = eatIdOpt(); } eatPossibleImplicitSemiColon(); return new BreakStatementTree(getTreeLocation(start), name); }
public static Builder builder(Kind kind) { return new Builder(kind); }
private FunctionDeclarationTree parseMethodSignature(SourcePosition start, IdentifierToken name, boolean isStatic, boolean isGenerator, boolean isOptional, TokenType access) { GenericTypeListTree generics = maybeParseGenericTypes(); FormalParameterListTree formalParameterList = parseFormalParameterList(ParamContext.SIGNATURE); ParseTree returnType = maybeParseColonType(); ParseTree functionBody = new EmptyStatementTree(getTreeLocation(start)); FunctionDeclarationTree declaration = new FunctionDeclarationTree( getTreeLocation(start), name, generics, isStatic, isGenerator, isOptional, access, FunctionDeclarationTree.Kind.MEMBER, formalParameterList, returnType, functionBody); return declaration; }
private IndexSignatureTree parseIndexSignature() { SourcePosition start = getTreeStartLocation(); eat(TokenType.OPEN_SQUARE); IdentifierToken name = eatIdOrKeywordAsId(); eat(TokenType.COLON); ParseTree indexType = parseTypeName(); // must be 'string' or 'number' eat(TokenType.CLOSE_SQUARE); eat(TokenType.COLON); ParseTree declaredType = parseType(); ParseTree nameTree = new MemberVariableTree(getTreeLocation(start), name, false, false, null, indexType); return new IndexSignatureTree(getTreeLocation(start), nameTree, declaredType); }
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)); }
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)); }
public boolean isPattern() { ParseTree parseTree = this; while (parseTree.type == ParseTreeType.PAREN_EXPRESSION) { parseTree = parseTree.asParenExpression().expression; } switch (parseTree.type) { case ARRAY_PATTERN: case OBJECT_PATTERN: return true; default: return false; } }
public static UpdateExpressionTree prefix( SourceRange location, Token operator, ParseTree operand) { return new UpdateExpressionTree(location, operator, OperatorPosition.PREFIX, operand); }
public boolean isValidAssignmentTarget() { ParseTree parseTree = this; while (parseTree.type == ParseTreeType.PAREN_EXPRESSION) { parseTree = parseTree.asParenExpression().expression; } switch(parseTree.type) { case IDENTIFIER_EXPRESSION: case MEMBER_EXPRESSION: case MEMBER_LOOKUP_EXPRESSION: case ARRAY_PATTERN: case OBJECT_PATTERN: case DEFAULT_PARAMETER: return true; default: return false; } }