diff --git a/src/parser.ts b/src/parser.ts index a805fa28..d1a4cc1c 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -100,14 +100,14 @@ function processTree( Object.keys(multiFields).forEach(name => (javaNode[`${name}Nodes`] = [])); } - node.children - .flatMap(child => + node.children.forEach((child, index) => { + const fieldName = node.fieldNameForChild(index); + const children = child.type === SyntaxType.ParenthesizedExpression && !isParenthesizedParent(javaNode) ? child.namedChildren - : [child] - ) - .forEach((child, index) => { + : [child]; + children.forEach(child => { const { type, text: value, startPosition, endPosition } = child; if (type === SyntaxType.BlockComment || type === SyntaxType.LineComment) { comments.push({ @@ -128,7 +128,6 @@ function processTree( printed: false }); } else { - const fieldName = node.fieldNameForChild(index); const javaChild = processTree(child, fieldName, comments); javaNode.children.push(javaChild); @@ -145,6 +144,7 @@ function processTree( } } }); + }); return javaNode; } diff --git a/test/unit-test/comments/expression/_input.java b/test/unit-test/comments/expression/_input.java index e69b535d..097f798f 100644 --- a/test/unit-test/comments/expression/_input.java +++ b/test/unit-test/comments/expression/_input.java @@ -7,5 +7,9 @@ void example() { a + // comment (b); + + a = (// + b + ); } } diff --git a/test/unit-test/comments/expression/_output.java b/test/unit-test/comments/expression/_output.java index a6141d8b..823c2c63 100644 --- a/test/unit-test/comments/expression/_output.java +++ b/test/unit-test/comments/expression/_output.java @@ -7,5 +7,8 @@ void example() { a + // comment b; + + a = // + b; } }