Search in sources :

Example 6 with BlockTree

use of com.google.javascript.jscomp.parsing.parser.trees.BlockTree 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();
        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(partial.start), propertyName, partial.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(partial.start), property, partial.isStatic, partial.accessModifier, parameter, type, body);
    }
}
Also used : SetAccessorTree(com.google.javascript.jscomp.parsing.parser.trees.SetAccessorTree) BlockTree(com.google.javascript.jscomp.parsing.parser.trees.BlockTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree) ComputedPropertySetterTree(com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertySetterTree)

Aggregations

BlockTree (com.google.javascript.jscomp.parsing.parser.trees.BlockTree)6 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)5 SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)4 CatchTree (com.google.javascript.jscomp.parsing.parser.trees.CatchTree)1 ComputedPropertyGetterTree (com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyGetterTree)1 ComputedPropertySetterTree (com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertySetterTree)1 FinallyTree (com.google.javascript.jscomp.parsing.parser.trees.FinallyTree)1 GetAccessorTree (com.google.javascript.jscomp.parsing.parser.trees.GetAccessorTree)1 SetAccessorTree (com.google.javascript.jscomp.parsing.parser.trees.SetAccessorTree)1