Search in sources :

Example 1 with BlockTree

use of com.google.javascript.jscomp.parsing.parser.trees.BlockTree in project closure-compiler by google.

the class Parser method parseGetAccessor.

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();
        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();
        return new ComputedPropertyGetterTree(getTreeLocation(partial.start), property, partial.isStatic, partial.accessModifier, returnType, body);
    }
}
Also used : GetAccessorTree(com.google.javascript.jscomp.parsing.parser.trees.GetAccessorTree) ComputedPropertyGetterTree(com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyGetterTree) BlockTree(com.google.javascript.jscomp.parsing.parser.trees.BlockTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 2 with BlockTree

use of com.google.javascript.jscomp.parsing.parser.trees.BlockTree in project closure-compiler by google.

the class Parser method parseCatch.

private CatchTree parseCatch() {
    SourcePosition start = getTreeStartLocation();
    CatchTree catchBlock;
    eat(TokenType.CATCH);
    eat(TokenType.OPEN_PAREN);
    ParseTree exception;
    if (peekPatternStart()) {
        exception = parsePattern(PatternKind.INITIALIZER);
    } else {
        exception = parseIdentifierExpression();
    }
    eat(TokenType.CLOSE_PAREN);
    BlockTree catchBody = parseBlock();
    catchBlock = new CatchTree(getTreeLocation(start), exception, catchBody);
    return catchBlock;
}
Also used : CatchTree(com.google.javascript.jscomp.parsing.parser.trees.CatchTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) BlockTree(com.google.javascript.jscomp.parsing.parser.trees.BlockTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 3 with BlockTree

use of com.google.javascript.jscomp.parsing.parser.trees.BlockTree 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);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) BlockTree(com.google.javascript.jscomp.parsing.parser.trees.BlockTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 4 with BlockTree

use of com.google.javascript.jscomp.parsing.parser.trees.BlockTree in project closure-compiler by google.

the class Parser method parseFinallyBlock.

private FinallyTree parseFinallyBlock() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.FINALLY);
    BlockTree finallyBlock = parseBlock();
    return new FinallyTree(getTreeLocation(start), finallyBlock);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) BlockTree(com.google.javascript.jscomp.parsing.parser.trees.BlockTree) FinallyTree(com.google.javascript.jscomp.parsing.parser.trees.FinallyTree)

Example 5 with BlockTree

use of com.google.javascript.jscomp.parsing.parser.trees.BlockTree 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);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) BlockTree(com.google.javascript.jscomp.parsing.parser.trees.BlockTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

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