Skip to content

Commit

Permalink
More multi-variable support
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Oct 4, 2024
1 parent ee68354 commit 2c40069
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 2 additions & 3 deletions openrewrite/src/javascript/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,10 +1255,9 @@ export class JavaScriptParserVisitor {
);
}

visitVariableStatement(node: ts.VariableStatement): J.VariableDeclarations | J.Unknown {
visitVariableStatement(node: ts.VariableStatement) {
if (node.declarationList.declarations.length > 1) {
// we can't map this to a `J.VariableDeclarations` because the variables can all declare their own type
return this.visitUnknown(node);
return this.visitVariableDeclarationList(node.declarationList);
}
return new J.VariableDeclarations(
randomId(),
Expand Down
13 changes: 12 additions & 1 deletion openrewrite/test/javascript/parser/variableDeclarations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('variable declaration mapping', () => {
})
);
});

test('const2', () => {
rewriteRun(
typeScript(
Expand All @@ -48,4 +47,16 @@ describe('variable declaration mapping', () => {
})
);
});
test('multi', () => {
rewriteRun(
//language=typescript
typeScript('let a=2, b=2 ')
);
});
test('multi typed', () => {
rewriteRun(
//language=typescript
typeScript('let a: number =2, b: string = "2" ')
);
});
});

0 comments on commit 2c40069

Please sign in to comment.