From b8a1206ec058dc5b537e2e441943b929753a786e Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Mon, 23 Oct 2023 08:14:03 +0200 Subject: [PATCH] Fix parsing of trailing whitespace after comments --- .../internal/TypeScriptParserVisitor.java | 13 +++++++------ .../openrewrite/javascript/tree/CommentTest.java | 1 - .../javascript/tree/ObjectLiteralTest.java | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java index e930caf2..b01d21d4 100644 --- a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java +++ b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java @@ -572,7 +572,7 @@ private J.MethodInvocation visitCallExpression(TSCNode node) { List> 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()); @@ -3403,8 +3403,8 @@ private List mapKeywordToAnnotation(Space prefix, TSCNode node, @N @Nullable private J.TypeParameters mapTypeParameters(@Nullable List 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) { @@ -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()) ); @@ -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; } diff --git a/src/test/java/org/openrewrite/javascript/tree/CommentTest.java b/src/test/java/org/openrewrite/javascript/tree/CommentTest.java index d95c744d..f2283970 100644 --- a/src/test/java/org/openrewrite/javascript/tree/CommentTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/CommentTest.java @@ -61,7 +61,6 @@ class Test { ); } - @ExpectedToFail @Test void preserveWhitespaceBetweenComments() { rewriteRun( diff --git a/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java b/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java index ad0540b1..96914b82 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java @@ -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(