@@ -249,6 +249,7 @@ namespace FourSlash {
249
249
if ( compilationOptions . typeRoots ) {
250
250
compilationOptions . typeRoots = compilationOptions . typeRoots . map ( p => ts . getNormalizedAbsolutePath ( p , this . basePath ) ) ;
251
251
}
252
+ compilationOptions . skipDefaultLibCheck = true ;
252
253
253
254
const languageServiceAdapter = this . getLanguageServiceAdapter ( testType , this . cancellationToken , compilationOptions ) ;
254
255
this . languageServiceAdapterHost = languageServiceAdapter . getHost ( ) ;
@@ -376,7 +377,7 @@ namespace FourSlash {
376
377
public verifyErrorExistsBetweenMarkers ( startMarkerName : string , endMarkerName : string , negative : boolean ) {
377
378
const startMarker = this . getMarkerByName ( startMarkerName ) ;
378
379
const endMarker = this . getMarkerByName ( endMarkerName ) ;
379
- const predicate = function ( errorMinChar : number , errorLimChar : number , startPos : number , endPos : number ) {
380
+ const predicate = function ( errorMinChar : number , errorLimChar : number , startPos : number , endPos : number ) {
380
381
return ( ( errorMinChar === startPos ) && ( errorLimChar === endPos ) ) ? true : false ;
381
382
} ;
382
383
@@ -428,12 +429,12 @@ namespace FourSlash {
428
429
let predicate : ( errorMinChar : number , errorLimChar : number , startPos : number , endPos : number ) => boolean ;
429
430
430
431
if ( after ) {
431
- predicate = function ( errorMinChar : number , errorLimChar : number , startPos : number , endPos : number ) {
432
+ predicate = function ( errorMinChar : number , errorLimChar : number , startPos : number , endPos : number ) {
432
433
return ( ( errorMinChar >= startPos ) && ( errorLimChar >= startPos ) ) ? true : false ;
433
434
} ;
434
435
}
435
436
else {
436
- predicate = function ( errorMinChar : number , errorLimChar : number , startPos : number , endPos : number ) {
437
+ predicate = function ( errorMinChar : number , errorLimChar : number , startPos : number , endPos : number ) {
437
438
return ( ( errorMinChar <= startPos ) && ( errorLimChar <= startPos ) ) ? true : false ;
438
439
} ;
439
440
}
@@ -458,7 +459,7 @@ namespace FourSlash {
458
459
endPos = endMarker . position ;
459
460
}
460
461
461
- errors . forEach ( function ( error : ts . Diagnostic ) {
462
+ errors . forEach ( function ( error : ts . Diagnostic ) {
462
463
if ( predicate ( error . start , error . start + error . length , startPos , endPos ) ) {
463
464
exists = true ;
464
465
}
@@ -475,7 +476,7 @@ namespace FourSlash {
475
476
Harness . IO . log ( "Unexpected error(s) found. Error list is:" ) ;
476
477
}
477
478
478
- errors . forEach ( function ( error : ts . Diagnostic ) {
479
+ errors . forEach ( function ( error : ts . Diagnostic ) {
479
480
Harness . IO . log ( " minChar: " + error . start +
480
481
", limChar: " + ( error . start + error . length ) +
481
482
", message: " + ts . flattenDiagnosticMessageText ( error . messageText , Harness . IO . newLine ( ) ) + "\n" ) ;
@@ -1348,14 +1349,7 @@ namespace FourSlash {
1348
1349
}
1349
1350
1350
1351
// Enters lines of text at the current caret position
1351
- public type ( text : string ) {
1352
- return this . typeHighFidelity ( text ) ;
1353
- }
1354
-
1355
- // Enters lines of text at the current caret position, invoking
1356
- // language service APIs to mimic Visual Studio's behavior
1357
- // as much as possible
1358
- private typeHighFidelity ( text : string ) {
1352
+ public type ( text : string , highFidelity = false ) {
1359
1353
let offset = this . currentCaretPosition ;
1360
1354
const prevChar = " " ;
1361
1355
const checkCadence = ( text . length >> 2 ) + 1 ;
@@ -1364,39 +1358,39 @@ namespace FourSlash {
1364
1358
// Make the edit
1365
1359
const ch = text . charAt ( i ) ;
1366
1360
this . languageServiceAdapterHost . editScript ( this . activeFile . fileName , offset , offset , ch ) ;
1367
- this . languageService . getBraceMatchingAtPosition ( this . activeFile . fileName , offset ) ;
1361
+ if ( highFidelity ) {
1362
+ this . languageService . getBraceMatchingAtPosition ( this . activeFile . fileName , offset ) ;
1363
+ }
1368
1364
1369
1365
this . updateMarkersForEdit ( this . activeFile . fileName , offset , offset , ch ) ;
1370
1366
offset ++ ;
1371
1367
1372
- if ( ch === "(" || ch === "," ) {
1373
- /* Signature help*/
1374
- this . languageService . getSignatureHelpItems ( this . activeFile . fileName , offset ) ;
1375
- }
1376
- else if ( prevChar === " " && / A - Z a - z _ / . test ( ch ) ) {
1377
- /* Completions */
1378
- this . languageService . getCompletionsAtPosition ( this . activeFile . fileName , offset ) ;
1379
- }
1368
+ if ( highFidelity ) {
1369
+ if ( ch === "(" || ch === "," ) {
1370
+ /* Signature help*/
1371
+ this . languageService . getSignatureHelpItems ( this . activeFile . fileName , offset ) ;
1372
+ }
1373
+ else if ( prevChar === " " && / A - Z a - z _ / . test ( ch ) ) {
1374
+ /* Completions */
1375
+ this . languageService . getCompletionsAtPosition ( this . activeFile . fileName , offset ) ;
1376
+ }
1380
1377
1381
- if ( i % checkCadence === 0 ) {
1382
- this . checkPostEditInvariants ( ) ;
1383
- // this.languageService.getSyntacticDiagnostics(this.activeFile.fileName);
1384
- // this.languageService.getSemanticDiagnostics(this.activeFile.fileName);
1378
+ if ( i % checkCadence === 0 ) {
1379
+ this . checkPostEditInvariants ( ) ;
1380
+ }
1385
1381
}
1386
1382
1387
1383
// Handle post-keystroke formatting
1388
1384
if ( this . enableFormatting ) {
1389
1385
const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , offset , ch , this . formatCodeOptions ) ;
1390
1386
if ( edits . length ) {
1391
1387
offset += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
1392
- // this.checkPostEditInvariants();
1393
1388
}
1394
1389
}
1395
1390
}
1396
1391
1397
1392
// Move the caret to wherever we ended up
1398
1393
this . currentCaretPosition = offset ;
1399
-
1400
1394
this . fixCaretPosition ( ) ;
1401
1395
this . checkPostEditInvariants ( ) ;
1402
1396
}
@@ -1415,7 +1409,6 @@ namespace FourSlash {
1415
1409
const edits = this . languageService . getFormattingEditsForRange ( this . activeFile . fileName , start , offset , this . formatCodeOptions ) ;
1416
1410
if ( edits . length ) {
1417
1411
offset += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
1418
- this . checkPostEditInvariants ( ) ;
1419
1412
}
1420
1413
}
1421
1414
@@ -2269,40 +2262,12 @@ namespace FourSlash {
2269
2262
export function runFourSlashTestContent ( basePath : string , testType : FourSlashTestType , content : string , fileName : string ) : void {
2270
2263
// Parse out the files and their metadata
2271
2264
const testData = parseTestData ( basePath , content , fileName ) ;
2272
-
2273
2265
const state = new TestState ( basePath , testType , testData ) ;
2274
-
2275
- let result = "" ;
2276
- const fourslashFile : Harness . Compiler . TestFile = {
2277
- unitName : Harness . Compiler . fourslashFileName ,
2278
- content : undefined ,
2279
- } ;
2280
- const testFile : Harness . Compiler . TestFile = {
2281
- unitName : fileName ,
2282
- content : content
2283
- } ;
2284
-
2285
- const host = Harness . Compiler . createCompilerHost (
2286
- [ fourslashFile , testFile ] ,
2287
- ( fn , contents ) => result = contents ,
2288
- ts . ScriptTarget . Latest ,
2289
- Harness . IO . useCaseSensitiveFileNames ( ) ,
2290
- Harness . IO . getCurrentDirectory ( ) ) ;
2291
-
2292
- const program = ts . createProgram ( [ Harness . Compiler . fourslashFileName , fileName ] , { outFile : "fourslashTestOutput.js" , noResolve : true , target : ts . ScriptTarget . ES3 } , host ) ;
2293
-
2294
- const sourceFile = host . getSourceFile ( fileName , ts . ScriptTarget . ES3 ) ;
2295
-
2296
- const diagnostics = ts . getPreEmitDiagnostics ( program , sourceFile ) ;
2297
- if ( diagnostics . length > 0 ) {
2298
- throw new Error ( `Error compiling ${ fileName } : ` +
2299
- diagnostics . map ( e => ts . flattenDiagnosticMessageText ( e . messageText , Harness . IO . newLine ( ) ) ) . join ( "\r\n" ) ) ;
2266
+ const output = ts . transpileModule ( content , { reportDiagnostics : true } ) ;
2267
+ if ( output . diagnostics . length > 0 ) {
2268
+ throw new Error ( `Syntax error in ${ basePath } : ${ output . diagnostics [ 0 ] . messageText } ` ) ;
2300
2269
}
2301
-
2302
- program . emit ( sourceFile ) ;
2303
-
2304
- ts . Debug . assert ( ! ! result ) ;
2305
- runCode ( result , state ) ;
2270
+ runCode ( output . outputText , state ) ;
2306
2271
}
2307
2272
2308
2273
function runCode ( code : string , state : TestState ) : void {
0 commit comments