@@ -11,24 +11,24 @@ import compareVersions from 'compare-versions';
11
11
12
12
import { endsWith } from './string' ;
13
13
import fixExportClass from './fixExportClass' ;
14
-
14
+ /*
15
15
interface Options {
16
16
tsconfig?: boolean;
17
17
include?: string | string[];
18
18
exclude?: string | string[];
19
19
typescript?: typeof ts;
20
20
module?: string;
21
21
}
22
-
22
+ */
23
23
const resolveHost = {
24
- directoryExists ( dirPath : string ) : boolean {
24
+ directoryExists ( dirPath ) {
25
25
try {
26
26
return statSync ( dirPath ) . isDirectory ( ) ;
27
27
} catch ( err ) {
28
28
return false ;
29
29
}
30
30
} ,
31
- fileExists ( filePath : string ) : boolean {
31
+ fileExists ( filePath ) {
32
32
try {
33
33
return statSync ( filePath ) . isFile ( ) ;
34
34
} catch ( err ) {
@@ -37,12 +37,12 @@ const resolveHost = {
37
37
}
38
38
} ;
39
39
40
- function goodErrors ( diagnostic : ts . Diagnostic ) : boolean {
40
+ function goodErrors ( diagnostic ) {
41
41
// All errors except `Cannot compile modules into 'es6' when targeting 'ES5' or lower.`
42
42
return diagnostic . code !== 1204 ;
43
43
}
44
44
45
- function getDefaultOptions ( ) : any {
45
+ function getDefaultOptions ( ) {
46
46
return {
47
47
noEmitHelpers : true ,
48
48
module : 'es2015' ,
@@ -53,7 +53,7 @@ function getDefaultOptions(): any {
53
53
// Gratefully lifted from 'look-up', due to problems using it directly:
54
54
// https://github.com/jonschlinkert/look-up/blob/master/index.js
55
55
// MIT Licenced
56
- function findFile ( cwd : string , filename : string ) : string {
56
+ function findFile ( cwd , filename ) {
57
57
let fp = cwd ? ( cwd + '/' + filename ) : filename ;
58
58
59
59
if ( existsSync ( fp ) ) {
@@ -74,7 +74,7 @@ function findFile( cwd: string, filename: string ): string {
74
74
return null ;
75
75
}
76
76
77
- function compilerOptionsFromTsConfig ( typescript : typeof ts ) : ts . CompilerOptions {
77
+ function compilerOptionsFromTsConfig ( typescript ) {
78
78
const cwd = process . cwd ( ) ;
79
79
80
80
const tsconfig = typescript . readConfigFile ( findFile ( cwd , 'tsconfig.json' ) , path => readFileSync ( path , 'utf8' ) ) ;
@@ -84,7 +84,7 @@ function compilerOptionsFromTsConfig( typescript: typeof ts ): ts.CompilerOption
84
84
return tsconfig . config . compilerOptions ;
85
85
}
86
86
87
- function adjustCompilerOptions ( typescript : typeof ts , options : any ) {
87
+ function adjustCompilerOptions ( typescript , options ) {
88
88
// Set `sourceMap` to `inlineSourceMap` if it's a boolean
89
89
// under the assumption that both are never specified simultaneously.
90
90
if ( typeof options . inlineSourceMap === 'boolean' ) {
@@ -104,7 +104,7 @@ function adjustCompilerOptions( typescript: typeof ts, options: any ) {
104
104
}
105
105
}
106
106
107
- export default function typescript ( options : Options ) {
107
+ export default function typescript ( options ) {
108
108
options = assign ( { } , options || { } ) ;
109
109
110
110
const filter = createFilter (
@@ -115,7 +115,7 @@ export default function typescript ( options: Options ) {
115
115
delete options . exclude ;
116
116
117
117
// Allow users to override the TypeScript version used for transpilation.
118
- const typescript : typeof ts = options . typescript || ts ;
118
+ const typescript = options . typescript || ts ;
119
119
120
120
delete options . typescript ;
121
121
@@ -149,19 +149,21 @@ export default function typescript ( options: Options ) {
149
149
const compilerOptions = parsed . options ;
150
150
151
151
return {
152
- resolveId ( importee : string , importer : string ) : string {
152
+ resolveId ( importee , importer ) {
153
153
// Handle the special `typescript-helpers` import itself.
154
154
if ( importee === 'typescript-helpers' ) {
155
155
return path . resolve ( __dirname , '../src/typescript-helpers.js' ) ;
156
156
}
157
157
158
158
if ( ! importer ) return null ;
159
159
160
- var result : ts . ResolvedModuleWithFailedLookupLocations ;
160
+ var result ;
161
+
162
+ importer = importer . split ( '\\' ) . join ( '/' ) ;
161
163
162
164
if ( compareVersions ( typescript . version , '1.8.0' ) < 0 ) {
163
165
// Suppress TypeScript warnings for function call.
164
- result = ( typescript as any ) . nodeModuleNameResolver ( importee , importer , resolveHost ) ;
166
+ result = typescript . nodeModuleNameResolver ( importee , importer , resolveHost ) ;
165
167
} else {
166
168
result = typescript . nodeModuleNameResolver ( importee , importer , compilerOptions , resolveHost ) ;
167
169
}
@@ -177,7 +179,7 @@ export default function typescript ( options: Options ) {
177
179
return null ;
178
180
} ,
179
181
180
- transform ( code : string , id : string ) : { code : string , map : any } {
182
+ transform ( code , id ) {
181
183
if ( ! filter ( id ) ) return null ;
182
184
183
185
const transformed = typescript . transpileModule ( fixExportClass ( code , id ) , {
@@ -208,7 +210,7 @@ export default function typescript ( options: Options ) {
208
210
} ) ;
209
211
210
212
if ( fatalError ) {
211
- throw new Error ( `There were TypeScript errors transpiling " ${ id } " ` ) ;
213
+ throw new Error ( `There were TypeScript errors transpiling` ) ;
212
214
}
213
215
214
216
return {
@@ -217,7 +219,7 @@ export default function typescript ( options: Options ) {
217
219
`\nimport { __assign, __awaiter, __extends, __decorate, __metadata, __param } from 'typescript-helpers';` ,
218
220
219
221
// Rollup expects `map` to be an object so we must parse the string
220
- map : JSON . parse ( transformed . sourceMapText as string )
222
+ map : JSON . parse ( transformed . sourceMapText )
221
223
} ;
222
224
}
223
225
} ;
0 commit comments