@@ -50,6 +50,26 @@ const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
5050 ) {
5151 return undefined ;
5252 }
53+ if (
54+ ts . isCallExpression ( node ) &&
55+ ts . isIdentifier ( node . expression ) &&
56+ node . expression . text === "require" &&
57+ ts . isStringLiteral ( node . arguments [ 0 ] ) &&
58+ node . arguments . length === 1
59+ ) {
60+ const firstArg = node . arguments [ 0 ] as ts . StringLiteral ;
61+ const file = bindModuleToFile ( firstArg . text ) ;
62+ if ( ! file ) {
63+ return node ;
64+ }
65+ const fileLiteral = ts . createLiteral ( file ) ;
66+ return ts . updateCall ( node , node . expression , node . typeArguments , [
67+ fileLiteral
68+ ] ) ;
69+ }
70+ if ( ts . isExternalModuleReference ( node ) ) {
71+ return unpathImportEqualsDeclaration ( node ) ;
72+ }
5373 if ( ts . isImportDeclaration ( node ) ) {
5474 return unpathImportDeclaration ( node ) ;
5575 }
@@ -60,6 +80,18 @@ const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
6080 return ts . visitEachChild ( node , visit , context ) ;
6181 }
6282
83+ function unpathImportEqualsDeclaration ( node : ts . ExternalModuleReference ) {
84+ if ( ! ts . isStringLiteral ( node . expression ) ) {
85+ return node ;
86+ }
87+ const file = bindModuleToFile ( node . expression . text ) ;
88+ if ( ! file ) {
89+ return node ;
90+ }
91+ const fileLiteral = ts . createLiteral ( file ) ;
92+
93+ return ts . updateExternalModuleReference ( node , fileLiteral ) ;
94+ }
6395 function unpathImportDeclaration (
6496 node : ts . ImportDeclaration
6597 ) : ts . VisitResult < ts . Statement > {
0 commit comments