@@ -87,29 +87,34 @@ function compileFileFromMemory(
87
87
let map ;
88
88
89
89
const realHost = ts . createCompilerHost ( compilerOptions , true ) ;
90
- const dummyFilePath = filename ;
90
+ const dummyFileName = ts . sys . resolvePath ( filename ) ;
91
+
92
+ const isDummyFile = ( fileName : string ) => ts . sys . resolvePath ( fileName ) === dummyFileName
91
93
92
94
const host : ts . CompilerHost = {
93
- fileExists : filePath =>
94
- filePath === dummyFilePath || realHost . fileExists ( filePath ) ,
95
- getCanonicalFileName : fileName => realHost . getCanonicalFileName ( fileName ) ,
95
+ fileExists : fileName =>
96
+ isDummyFile ( fileName ) || realHost . fileExists ( fileName ) ,
97
+ getCanonicalFileName : fileName => isDummyFile ( fileName )
98
+ ? ts . sys . useCaseSensitiveFileNames
99
+ ? fileName
100
+ : fileName . toLowerCase ( )
101
+ : realHost . getCanonicalFileName ( fileName ) ,
96
102
getSourceFile : (
97
103
fileName ,
98
104
languageVersion ,
99
105
onError ,
100
106
shouldCreateNewSourceFile ,
101
107
) =>
102
- fileName === dummyFilePath
103
- ? ts . createSourceFile ( dummyFilePath , code , languageVersion )
108
+ isDummyFile ( fileName )
109
+ ? ts . createSourceFile ( dummyFileName , code , languageVersion )
104
110
: realHost . getSourceFile (
105
- fileName ,
106
- languageVersion ,
107
- onError ,
108
- shouldCreateNewSourceFile ,
109
- ) ,
110
- readFile : filePath =>
111
- // istanbul ignore next
112
- filePath === dummyFilePath ? content : realHost . readFile ( filePath ) ,
111
+ fileName ,
112
+ languageVersion ,
113
+ onError ,
114
+ shouldCreateNewSourceFile ,
115
+ ) ,
116
+ readFile : fileName =>
117
+ isDummyFile ( fileName ) ? content : realHost . readFile ( fileName ) ,
113
118
writeFile : ( fileName , data ) => {
114
119
if ( fileName . endsWith ( '.map' ) ) {
115
120
map = data ;
@@ -130,7 +135,7 @@ function compileFileFromMemory(
130
135
) ,
131
136
} ;
132
137
133
- const program = ts . createProgram ( [ dummyFilePath ] , compilerOptions , host ) ;
138
+ const program = ts . createProgram ( [ dummyFileName ] , compilerOptions , host ) ;
134
139
const emitResult = program . emit ( undefined , undefined , undefined , undefined , {
135
140
before : [ importTransformer ] ,
136
141
} ) ;
0 commit comments