Skip to content

Commit

Permalink
Fix parsing of trailing whitespace after comments
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Oct 23, 2023
1 parent 7d4d532 commit b8a1206
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ private J.MethodInvocation visitCallExpression(TSCNode node) {
List<JRightPadded<Expression>> elements = jContainer.getPadding().getElements().stream()
.map(it -> {
Expression exp = (!(it.getElement() instanceof Expression) && it.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) it.getElement()) : (Expression) it.getElement();
new JS.StatementExpression(randomId(), (Statement) it.getElement()) : (Expression) it.getElement();
return padRight(exp, it.getAfter(), it.getMarkers());
})
.collect(toList());
Expand Down Expand Up @@ -3403,8 +3403,8 @@ private List<J.Annotation> mapKeywordToAnnotation(Space prefix, TSCNode node, @N
@Nullable
private J.TypeParameters mapTypeParameters(@Nullable List<TSCNode> typeParameters) {
return typeParameters == null ? null : new J.TypeParameters(randomId(), sourceBefore(TSCSyntaxKind.LessThanToken), Markers.EMPTY,
emptyList(),
convertAll(typeParameters, commaDelim, t -> sourceBefore(TSCSyntaxKind.GreaterThanToken)));
emptyList(),
convertAll(typeParameters, commaDelim, t -> sourceBefore(TSCSyntaxKind.GreaterThanToken)));
}

private J mapVariableStatement(TSCNode node) {
Expand Down Expand Up @@ -3449,7 +3449,7 @@ private Space whitespace() {
if (comments.isEmpty()) {
initialSpace += lastToken();
} else {
comments = ListUtils.map(
comments = ListUtils.mapLast(
comments,
comment -> comment.withSuffix(comment.getSuffix() + lastToken())
);
Expand All @@ -3467,9 +3467,10 @@ private Space whitespace() {
Markers.EMPTY
);
if (comments.isEmpty()) {
comments = Collections.singletonList(comment);
comments = new ArrayList<>(1);
comments.add(comment);
} else {
comments = ListUtils.concat(comments, comment);
comments.add(comment);
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class Test {
);
}

@ExpectedToFail
@Test
void preserveWhitespaceBetweenComments() {
rewriteRun(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package org.openrewrite.javascript.tree;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ExpectedToFail;

@SuppressWarnings({"JSUnusedLocalSymbols", "LoopStatementThatDoesntLoopJS", "TypeScriptCheckImport"})
class ObjectLiteralTest extends ParserTest {

@ExpectedToFail
@Disabled // times out
@Test
void empty() {
rewriteRun(
Expand Down

0 comments on commit b8a1206

Please sign in to comment.