From c58f6ae86046195e6be462e5eb202123767f3f84 Mon Sep 17 00:00:00 2001 From: traceyyoshima Date: Tue, 14 Nov 2023 18:17:51 -0700 Subject: [PATCH] Fixed cases. --- .../internal/TypeScriptParserVisitor.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java index a5369d52..38eec377 100644 --- a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java +++ b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java @@ -733,24 +733,27 @@ private J.ClassDeclaration visitClassDeclaration(TSCNode node) { private J visitCaseClause(TSCNode node) { TSCNode expression = node.getOptionalNodeProperty("expression"); List statements = node.getNodeListProperty("statements"); - List> list = new ArrayList<>(); + Space prefix = whitespace(); + JContainer expressions = JContainer.build( + expression == null ? EMPTY : sourceBefore(TSCSyntaxKind.CaseKeyword), + singletonList(JRightPadded.build((Expression) visitNode(expression))), + Markers.EMPTY + ); + List> list = new ArrayList<>(statements.size()); + Space before = sourceBefore(TSCSyntaxKind.ColonToken); for (TSCNode it : statements) { JRightPadded statementJRightPadded = maybeSemicolon((Statement) visitNode(it)); list.add(statementJRightPadded); } return new J.Case( randomId(), - whitespace(), + prefix, Markers.EMPTY, J.Case.Type.Statement, null, + expressions, JContainer.build( - expression == null ? EMPTY : sourceBefore(TSCSyntaxKind.CaseKeyword), - singletonList(JRightPadded.build((Expression) visitNode(expression))), - Markers.EMPTY - ), - JContainer.build( - sourceBefore(TSCSyntaxKind.ColonToken), + before, list, Markers.EMPTY ), @@ -859,24 +862,27 @@ private J.Annotation visitDecorator(TSCNode node) { private J visitDefaultClause(TSCNode node) { List statements = node.getNodeListProperty("statements"); - List> list = new ArrayList<>(); + Space prefix = whitespace(); + JContainer expressions = JContainer.build( + EMPTY, + singletonList(JRightPadded.build(new J.Identifier(randomId(), sourceBefore(TSCSyntaxKind.DefaultKeyword), Markers.EMPTY, emptyList(), "default", null, null))), + Markers.EMPTY + ); + Space before = sourceBefore(TSCSyntaxKind.ColonToken); + List> list = new ArrayList<>(statements.size()); for (TSCNode it : statements) { JRightPadded statementJRightPadded = maybeSemicolon((Statement) visitNode(it)); list.add(statementJRightPadded); } return new J.Case( randomId(), - whitespace(), + prefix, Markers.EMPTY, J.Case.Type.Statement, null, + expressions, JContainer.build( - EMPTY, - singletonList(JRightPadded.build(new J.Identifier(randomId(), sourceBefore(TSCSyntaxKind.DefaultKeyword), Markers.EMPTY, emptyList(), "default", null, null))), - Markers.EMPTY - ), - JContainer.build( - sourceBefore(TSCSyntaxKind.ColonToken), + before, list, Markers.EMPTY ),