@@ -50,6 +50,26 @@ const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
50
50
) {
51
51
return undefined ;
52
52
}
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
+ }
53
73
if ( ts . isImportDeclaration ( node ) ) {
54
74
return unpathImportDeclaration ( node ) ;
55
75
}
@@ -60,6 +80,18 @@ const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
60
80
return ts . visitEachChild ( node , visit , context ) ;
61
81
}
62
82
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
+ }
63
95
function unpathImportDeclaration (
64
96
node : ts . ImportDeclaration
65
97
) : ts . VisitResult < ts . Statement > {
0 commit comments