From c94dbe010da5750ba80a15c752cff62589323779 Mon Sep 17 00:00:00 2001 From: Andrii Rodionov Date: Tue, 14 Jan 2025 17:31:07 +0100 Subject: [PATCH] Implemented visitExternalModuleReference (#195) Co-authored-by: Andrii Rodionov --- openrewrite/src/javascript/parser.ts | 15 ++++++++++++++- openrewrite/test/javascript/parser/import.test.ts | 9 +++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/openrewrite/src/javascript/parser.ts b/openrewrite/src/javascript/parser.ts index 6ff03be..22b9d97 100644 --- a/openrewrite/src/javascript/parser.ts +++ b/openrewrite/src/javascript/parser.ts @@ -3393,7 +3393,20 @@ export class JavaScriptParserVisitor { } visitExternalModuleReference(node: ts.ExternalModuleReference) { - return this.visitUnknown(node); + return new J.MethodInvocation( + randomId(), + this.prefix(node), + Markers.EMPTY, + null, + null, + this.mapIdentifier(node, "require"), + new J.JContainer( + this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)!), + [this.rightPadded(this.visit(node.expression), this.suffix(node.expression))], + Markers.EMPTY + ), + this.mapMethodType(node) + ) } visitJsxElement(node: ts.JsxElement) { diff --git a/openrewrite/test/javascript/parser/import.test.ts b/openrewrite/test/javascript/parser/import.test.ts index d40d10b..f7ea1bc 100644 --- a/openrewrite/test/javascript/parser/import.test.ts +++ b/openrewrite/test/javascript/parser/import.test.ts @@ -115,4 +115,13 @@ describe('import mapping', () => { `) ); }); + + test('external module import', () => { + rewriteRun( + //language=typescript + typeScript(` + import mongodb = /*a*/require/*b*/(/*c*/'mongodb'/*d*/)/*e*/; + `) + ); + }); });