Skip to content

Commit

Permalink
Implemented visitExternalModuleReference (#195)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrii Rodionov <[email protected]>
  • Loading branch information
arodionov and Andrii Rodionov authored Jan 14, 2025
1 parent 9bceecd commit c94dbe0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 14 additions & 1 deletion openrewrite/src/javascript/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions openrewrite/test/javascript/parser/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,13 @@ describe('import mapping', () => {
`)
);
});

test('external module import', () => {
rewriteRun(
//language=typescript
typeScript(`
import mongodb = /*a*/require/*b*/(/*c*/'mongodb'/*d*/)/*e*/;
`)
);
});
});

0 comments on commit c94dbe0

Please sign in to comment.