@@ -19,22 +19,24 @@ var tss;
19
19
/**
20
20
* @param {ts.CompilerOptions= } options TypeScript compile options (some options are ignored)
21
21
*/
22
- function TypeScriptSimple ( options ) {
22
+ function TypeScriptSimple ( options , doSemanticChecks ) {
23
23
if ( options === void 0 ) { options = { } ; }
24
+ if ( doSemanticChecks === void 0 ) { doSemanticChecks = true ; }
25
+ this . doSemanticChecks = doSemanticChecks ;
24
26
this . service = null ;
25
27
this . outputs = { } ;
26
28
this . files = { } ;
27
29
if ( options . target == null ) {
28
- options . target = 1 /* ES5 */ ;
30
+ options . target = ts . ScriptTarget . ES5 ;
29
31
}
30
32
if ( options . module == null ) {
31
- options . module = 0 /* None */ ;
33
+ options . module = ts . ModuleKind . None ;
32
34
}
33
35
this . options = options ;
34
36
}
35
37
/**
36
38
* @param {string } code TypeScript source code to compile
37
- * @return {string }
39
+ * @return {string } The JavaScript with inline sourceMaps if sourceMaps were enabled
38
40
*/
39
41
TypeScriptSimple . prototype . compile = function ( code ) {
40
42
if ( ! this . service ) {
@@ -77,7 +79,7 @@ var tss;
77
79
return path . dirname ( require . resolve ( 'typescript' ) ) ;
78
80
} ;
79
81
TypeScriptSimple . prototype . getDefaultLibFilename = function ( options ) {
80
- if ( options . target === 2 /* ES6 */ ) {
82
+ if ( options . target === ts . ScriptTarget . ES6 ) {
81
83
return 'lib.es6.d.ts' ;
82
84
}
83
85
else {
@@ -86,13 +88,22 @@ var tss;
86
88
} ;
87
89
TypeScriptSimple . prototype . toJavaScript = function ( service ) {
88
90
var output = service . getEmitOutput ( FILENAME_TS ) ;
89
- if ( output . emitOutputStatus === 0 /* Succeeded */ ) {
91
+ // Meaning of succeeded is driven by whether we need to check for semantic errors or not
92
+ var succeeded = output . emitOutputStatus === ts . EmitReturnStatus . Succeeded ;
93
+ if ( ! this . doSemanticChecks ) {
94
+ // We have an output. It implies syntactic success
95
+ if ( ! succeeded )
96
+ succeeded = ! ! output . outputFiles . length ;
97
+ }
98
+ if ( succeeded ) {
90
99
var filename = FILENAME_TS . replace ( / t s $ / , 'js' ) ;
91
100
var file = output . outputFiles . filter ( function ( file ) { return file . name === filename ; } ) [ 0 ] ;
92
101
// Fixed in v1.5 https://github.com/Microsoft/TypeScript/issues/1653
93
102
return file . text . replace ( / \r \n / g, os . EOL ) ;
94
103
}
95
- var allDiagnostics = service . getCompilerOptionsDiagnostics ( ) . concat ( service . getSyntacticDiagnostics ( FILENAME_TS ) ) . concat ( service . getSemanticDiagnostics ( FILENAME_TS ) ) ;
104
+ var allDiagnostics = service . getCompilerOptionsDiagnostics ( ) . concat ( service . getSyntacticDiagnostics ( FILENAME_TS ) ) ;
105
+ if ( this . doSemanticChecks )
106
+ allDiagnostics = allDiagnostics . concat ( service . getSemanticDiagnostics ( FILENAME_TS ) ) ;
96
107
throw new Error ( this . formatDiagnostics ( allDiagnostics ) ) ;
97
108
} ;
98
109
TypeScriptSimple . prototype . formatDiagnostics = function ( diagnostics ) {
0 commit comments