@Test public void multple_parameters_and_block_body() throws Exception { ArrowFunctionTree tree = parse("(p1, p2) => p;", Kind.ARROW_FUNCTION); assertThat(tree.is(Kind.ARROW_FUNCTION)).isTrue(); assertThat(tree.parameters().is(Kind.FORMAL_PARAMETER_LIST)).isTrue(); assertThat(tree.doubleArrow().text()).isEqualTo(JavaScriptPunctuator.DOUBLEARROW.getValue()); assertThat(expressionToString(tree.conciseBody())).isEqualTo("p"); }
@Override public void visitArrowFunction(ArrowFunctionTree tree) { newFunctionScope(tree); skipBlock(tree.body()); super.visitArrowFunction(tree); leaveScope(); }
@Test public void single_no_parenthesis_parameter_and_block_body() throws Exception { ArrowFunctionTree tree = parse("p => {};", Kind.ARROW_FUNCTION); assertThat(tree.is(Kind.ARROW_FUNCTION)).isTrue(); assertThat(tree.parameters() instanceof IdentifierTree).isTrue(); assertThat(((IdentifierTree) tree.parameters()).name()).isEqualTo("p"); assertThat(tree.doubleArrow().text()).isEqualTo(JavaScriptPunctuator.DOUBLEARROW.getValue()); assertThat(tree.conciseBody().is(Kind.BLOCK)).isTrue(); }
@Test public void single_no_parenthesis_parameter_and_expression_body() throws Exception { ArrowFunctionTree tree = parse("p => p;", Kind.ARROW_FUNCTION); assertThat(tree.is(Kind.ARROW_FUNCTION)).isTrue(); assertThat(tree.parameters() instanceof IdentifierTree).isTrue(); assertThat(((IdentifierTree) tree.parameters()).name()).isEqualTo("p"); assertThat(tree.doubleArrow().text()).isEqualTo("=>"); assertThat(expressionToString(tree.conciseBody())).isEqualTo("p"); }