@@ -1016,7 +1016,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
1016
1016
if ( diagnosticList . length ) reportTSError ( diagnosticList ) ;
1017
1017
1018
1018
if ( output . emitSkipped ) {
1019
- throw new TypeError ( ` ${ relative ( cwd , fileName ) } : Emit skipped` ) ;
1019
+ return [ undefined , undefined , true ] ;
1020
1020
}
1021
1021
1022
1022
// Throw an error when requiring `.d.ts` files.
@@ -1029,7 +1029,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
1029
1029
) ;
1030
1030
}
1031
1031
1032
- return [ output . outputFiles [ 1 ] . text , output . outputFiles [ 0 ] . text ] ;
1032
+ return [ output . outputFiles [ 1 ] . text , output . outputFiles [ 0 ] . text , false ] ;
1033
1033
} ;
1034
1034
1035
1035
getTypeInfo = ( code : string , fileName : string , position : number ) => {
@@ -1159,7 +1159,8 @@ export function create(rawOptions: CreateOptions = {}): Service {
1159
1159
} ;
1160
1160
1161
1161
getOutput = ( code : string , fileName : string ) => {
1162
- const output : [ string , string ] = [ '' , '' ] ;
1162
+ let outText = '' ;
1163
+ let outMap = '' ;
1163
1164
1164
1165
updateMemoryCache ( code , fileName ) ;
1165
1166
@@ -1179,9 +1180,9 @@ export function create(rawOptions: CreateOptions = {}): Service {
1179
1180
sourceFile ,
1180
1181
( path , file , writeByteOrderMark ) => {
1181
1182
if ( path . endsWith ( '.map' ) ) {
1182
- output [ 1 ] = file ;
1183
+ outMap = file ;
1183
1184
} else {
1184
- output [ 0 ] = file ;
1185
+ outText = file ;
1185
1186
}
1186
1187
1187
1188
if ( options . emit ) sys . writeFile ( path , file , writeByteOrderMark ) ;
@@ -1192,11 +1193,11 @@ export function create(rawOptions: CreateOptions = {}): Service {
1192
1193
) ;
1193
1194
1194
1195
if ( result . emitSkipped ) {
1195
- throw new TypeError ( ` ${ relative ( cwd , fileName ) } : Emit skipped` ) ;
1196
+ return [ undefined , undefined , true ] ;
1196
1197
}
1197
1198
1198
1199
// Throw an error when requiring files that cannot be compiled.
1199
- if ( output [ 0 ] === '' ) {
1200
+ if ( outText === '' ) {
1200
1201
if ( program . isSourceFileFromExternalLibrary ( sourceFile ) ) {
1201
1202
throw new TypeError (
1202
1203
`Unable to compile file from external library: ${ relative (
@@ -1214,7 +1215,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
1214
1215
) ;
1215
1216
}
1216
1217
1217
- return output ;
1218
+ return [ outText , outMap , false ] ;
1218
1219
} ;
1219
1220
1220
1221
getTypeInfo = ( code : string , fileName : string , position : number ) => {
@@ -1291,7 +1292,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
1291
1292
) ;
1292
1293
if ( diagnosticList . length ) reportTSError ( diagnosticList ) ;
1293
1294
1294
- return [ result . outputText , result . sourceMapText as string ] ;
1295
+ return [ result . outputText , result . sourceMapText as string , false ] ;
1295
1296
} ;
1296
1297
}
1297
1298
@@ -1308,24 +1309,27 @@ export function create(rawOptions: CreateOptions = {}): Service {
1308
1309
: createTranspileOnlyGetOutputFunction (
1309
1310
ts . ModuleKind . ES2020 || ts . ModuleKind . ES2015
1310
1311
) ;
1312
+ const getOutputTranspileOnly = createTranspileOnlyGetOutputFunction ( ) ;
1311
1313
1312
1314
// Create a simple TypeScript compiler proxy.
1313
1315
function compile ( code : string , fileName : string , lineOffset = 0 ) {
1314
1316
const normalizedFileName = normalizeSlashes ( fileName ) ;
1315
1317
const classification =
1316
1318
moduleTypeClassifier . classifyModule ( normalizedFileName ) ;
1317
1319
// Must always call normal getOutput to throw typechecking errors
1318
- let [ value , sourceMap ] = getOutput ( code , normalizedFileName ) ;
1320
+ let [ value , sourceMap , emitSkipped ] = getOutput ( code , normalizedFileName ) ;
1319
1321
// If module classification contradicts the above, call the relevant transpiler
1320
1322
if ( classification . moduleType === 'cjs' && getOutputForceCommonJS ) {
1321
1323
[ value , sourceMap ] = getOutputForceCommonJS ( code , normalizedFileName ) ;
1322
1324
} else if ( classification . moduleType === 'esm' && getOutputForceESM ) {
1323
1325
[ value , sourceMap ] = getOutputForceESM ( code , normalizedFileName ) ;
1326
+ } else if ( emitSkipped ) {
1327
+ [ value , sourceMap ] = getOutputTranspileOnly ( code , normalizedFileName ) ;
1324
1328
}
1325
1329
const output = updateOutput (
1326
- value ,
1330
+ value ! ,
1327
1331
normalizedFileName ,
1328
- sourceMap ,
1332
+ sourceMap ! ,
1329
1333
getExtension
1330
1334
) ;
1331
1335
outputCache . set ( normalizedFileName , { content : output } ) ;
@@ -1456,7 +1460,7 @@ function registerExtension(
1456
1460
/**
1457
1461
* Internal source output.
1458
1462
*/
1459
- type SourceOutput = [ string , string ] ;
1463
+ type SourceOutput = [ string , string , false ] | [ undefined , undefined , true ] ;
1460
1464
1461
1465
/**
1462
1466
* Update the output remapping the source map.
0 commit comments