@@ -1016,7 +1016,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
10161016 if ( diagnosticList . length ) reportTSError ( diagnosticList ) ;
10171017
10181018 if ( output . emitSkipped ) {
1019- throw new TypeError ( ` ${ relative ( cwd , fileName ) } : Emit skipped` ) ;
1019+ return [ undefined , undefined , true ] ;
10201020 }
10211021
10221022 // Throw an error when requiring `.d.ts` files.
@@ -1029,7 +1029,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
10291029 ) ;
10301030 }
10311031
1032- return [ output . outputFiles [ 1 ] . text , output . outputFiles [ 0 ] . text ] ;
1032+ return [ output . outputFiles [ 1 ] . text , output . outputFiles [ 0 ] . text , false ] ;
10331033 } ;
10341034
10351035 getTypeInfo = ( code : string , fileName : string , position : number ) => {
@@ -1159,7 +1159,8 @@ export function create(rawOptions: CreateOptions = {}): Service {
11591159 } ;
11601160
11611161 getOutput = ( code : string , fileName : string ) => {
1162- const output : [ string , string ] = [ '' , '' ] ;
1162+ let outText = '' ;
1163+ let outMap = '' ;
11631164
11641165 updateMemoryCache ( code , fileName ) ;
11651166
@@ -1179,9 +1180,9 @@ export function create(rawOptions: CreateOptions = {}): Service {
11791180 sourceFile ,
11801181 ( path , file , writeByteOrderMark ) => {
11811182 if ( path . endsWith ( '.map' ) ) {
1182- output [ 1 ] = file ;
1183+ outMap = file ;
11831184 } else {
1184- output [ 0 ] = file ;
1185+ outText = file ;
11851186 }
11861187
11871188 if ( options . emit ) sys . writeFile ( path , file , writeByteOrderMark ) ;
@@ -1192,11 +1193,11 @@ export function create(rawOptions: CreateOptions = {}): Service {
11921193 ) ;
11931194
11941195 if ( result . emitSkipped ) {
1195- throw new TypeError ( ` ${ relative ( cwd , fileName ) } : Emit skipped` ) ;
1196+ return [ undefined , undefined , true ] ;
11961197 }
11971198
11981199 // Throw an error when requiring files that cannot be compiled.
1199- if ( output [ 0 ] === '' ) {
1200+ if ( outText === '' ) {
12001201 if ( program . isSourceFileFromExternalLibrary ( sourceFile ) ) {
12011202 throw new TypeError (
12021203 `Unable to compile file from external library: ${ relative (
@@ -1214,7 +1215,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
12141215 ) ;
12151216 }
12161217
1217- return output ;
1218+ return [ outText , outMap , false ] ;
12181219 } ;
12191220
12201221 getTypeInfo = ( code : string , fileName : string , position : number ) => {
@@ -1291,7 +1292,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
12911292 ) ;
12921293 if ( diagnosticList . length ) reportTSError ( diagnosticList ) ;
12931294
1294- return [ result . outputText , result . sourceMapText as string ] ;
1295+ return [ result . outputText , result . sourceMapText as string , false ] ;
12951296 } ;
12961297 }
12971298
@@ -1308,24 +1309,27 @@ export function create(rawOptions: CreateOptions = {}): Service {
13081309 : createTranspileOnlyGetOutputFunction (
13091310 ts . ModuleKind . ES2020 || ts . ModuleKind . ES2015
13101311 ) ;
1312+ const getOutputTranspileOnly = createTranspileOnlyGetOutputFunction ( ) ;
13111313
13121314 // Create a simple TypeScript compiler proxy.
13131315 function compile ( code : string , fileName : string , lineOffset = 0 ) {
13141316 const normalizedFileName = normalizeSlashes ( fileName ) ;
13151317 const classification =
13161318 moduleTypeClassifier . classifyModule ( normalizedFileName ) ;
13171319 // Must always call normal getOutput to throw typechecking errors
1318- let [ value , sourceMap ] = getOutput ( code , normalizedFileName ) ;
1320+ let [ value , sourceMap , emitSkipped ] = getOutput ( code , normalizedFileName ) ;
13191321 // If module classification contradicts the above, call the relevant transpiler
13201322 if ( classification . moduleType === 'cjs' && getOutputForceCommonJS ) {
13211323 [ value , sourceMap ] = getOutputForceCommonJS ( code , normalizedFileName ) ;
13221324 } else if ( classification . moduleType === 'esm' && getOutputForceESM ) {
13231325 [ value , sourceMap ] = getOutputForceESM ( code , normalizedFileName ) ;
1326+ } else if ( emitSkipped ) {
1327+ [ value , sourceMap ] = getOutputTranspileOnly ( code , normalizedFileName ) ;
13241328 }
13251329 const output = updateOutput (
1326- value ,
1330+ value ! ,
13271331 normalizedFileName ,
1328- sourceMap ,
1332+ sourceMap ! ,
13291333 getExtension
13301334 ) ;
13311335 outputCache . set ( normalizedFileName , { content : output } ) ;
@@ -1456,7 +1460,7 @@ function registerExtension(
14561460/**
14571461 * Internal source output.
14581462 */
1459- type SourceOutput = [ string , string ] ;
1463+ type SourceOutput = [ string , string , false ] | [ undefined , undefined , true ] ;
14601464
14611465/**
14621466 * Update the output remapping the source map.
0 commit comments