private ParseTree parseArrowFunctionBody(Expression expressionIn, FunctionFlavor functionFlavor) { functionContextStack.addLast(functionFlavor); ParseTree arrowFunctionBody; if (peek(TokenType.OPEN_CURLY)) { arrowFunctionBody = parseFunctionBody(); } else { arrowFunctionBody = parseAssignment(expressionIn); } functionContextStack.removeLast(); return arrowFunctionBody; }
private FunctionDeclarationTree parseFunctionTail( SourcePosition start, IdentifierToken name, boolean isStatic, boolean isGenerator, TokenType access, FunctionDeclarationTree.Kind kind) { inGeneratorContext.addLast(isGenerator); GenericTypeListTree generics = maybeParseGenericTypes(); FormalParameterListTree formalParameterList = parseFormalParameterList(ParamContext.IMPLEMENTATION); ParseTree returnType = maybeParseColonType(); BlockTree functionBody = parseFunctionBody(); FunctionDeclarationTree declaration = new FunctionDeclarationTree( getTreeLocation(start), name, generics, isStatic, isGenerator, false, access, kind, formalParameterList, returnType, functionBody); inGeneratorContext.removeLast(); return declaration; }
private void parseFunctionTail( FunctionDeclarationTree.Builder builder, FunctionFlavor functionFlavor) { functionContextStack.addLast(functionFlavor); builder .setGenerator(functionFlavor.isGenerator) .setGenerics(maybeParseGenericTypes()) .setFormalParameterList(parseFormalParameterList(ParamContext.IMPLEMENTATION)) .setReturnType(maybeParseColonType()) .setFunctionBody(parseFunctionBody()); functionContextStack.removeLast(); }
private ParseTree parseSetAccessor(PartialClassElement partial) { eatPredefinedString(PredefinedName.SET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); FormalParameterListTree parameter = parseSetterParameterList(); ParseTree returnType = maybeParseColonType(); if (returnType != null) { reportError(scanner.peekToken(), "setter should not have any returns"); } 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, partial.accessModifier, parameter, body); } }
private ParseTree parseArrowFunctionTail( SourcePosition start, GenericTypeListTree generics, FormalParameterListTree formalParameterList, Expression expressionIn) { inGeneratorContext.addLast(false); ParseTree returnType = null; if (peek(TokenType.COLON)) { returnType = parseTypeAnnotation(); } if (peekImplicitSemiColon()) { reportError("No newline allowed before '=>'"); } eat(TokenType.ARROW); ParseTree functionBody; if (peek(TokenType.OPEN_CURLY)) { functionBody = parseFunctionBody(); } else { functionBody = parseAssignment(expressionIn); } FunctionDeclarationTree declaration = new FunctionDeclarationTree( getTreeLocation(start), null, generics, false, false, false, null, FunctionDeclarationTree.Kind.ARROW, formalParameterList, returnType, functionBody); inGeneratorContext.removeLast(); return declaration; }
private ParseTree parseGetAccessor(TokenType access) { SourcePosition start = getTreeStartLocation(); boolean isStatic = eatOpt(TokenType.STATIC) != null; eatPredefinedString(PredefinedName.GET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); return new GetAccessorTree(getTreeLocation(start), propertyName, isStatic, returnType, body); } else { ParseTree property = parseComputedPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); return new ComputedPropertyGetterTree( getTreeLocation(start), property, isStatic, access, returnType, body); } }
private ParseTree parseGetAccessor(PartialClassElement partial) { eatPredefinedString(PredefinedName.GET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); recordFeatureUsed(Feature.GETTER); return new GetAccessorTree( getTreeLocation(partial.start), propertyName, partial.isStatic, returnType, body); } else { ParseTree property = parseComputedPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); recordFeatureUsed(Feature.GETTER); return new ComputedPropertyGetterTree( getTreeLocation(partial.start), property, partial.isStatic, partial.accessModifier, returnType, body); } }
private ParseTree parseSetAccessor(TokenType access) { SourcePosition start = getTreeStartLocation(); boolean isStatic = eatOpt(TokenType.STATIC) != null; eatPredefinedString(PredefinedName.SET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); eat(TokenType.OPEN_PAREN); IdentifierToken parameter = eatId(); ParseTree type = maybeParseColonType(); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); if (returnType != null) { reportError(scanner.peekToken(), "setter should not have any returns"); } BlockTree body = parseFunctionBody(); return new SetAccessorTree( getTreeLocation(start), propertyName, isStatic, parameter, type, body); } else { ParseTree property = parseComputedPropertyName(); eat(TokenType.OPEN_PAREN); IdentifierToken parameter = eatId(); ParseTree type = maybeParseColonType(); eat(TokenType.CLOSE_PAREN); BlockTree body = parseFunctionBody(); return new ComputedPropertySetterTree( getTreeLocation(start), property, isStatic, access, parameter, type, body); } }