@@ -1565,15 +1565,13 @@ export class Data2 {
1565
1565
} ) ;
1566
1566
} ) ;
1567
1567
1568
- describe ( "updates errors in lib file when non module file changes " , ( ) => {
1568
+ describe ( "updates errors in lib file" , ( ) => {
1569
1569
const currentDirectory = "/user/username/projects/myproject" ;
1570
1570
const field = "fullscreen" ;
1571
- const aFile : File = {
1572
- path : `${ currentDirectory } /a.ts` ,
1573
- content : `interface Document {
1571
+ const fieldWithoutReadonly = `interface Document {
1574
1572
${ field } : boolean;
1575
- }`
1576
- } ;
1573
+ }` ;
1574
+
1577
1575
const libFileWithDocument : File = {
1578
1576
path : libFile . path ,
1579
1577
content : `${ libFile . content }
@@ -1586,40 +1584,63 @@ interface Document {
1586
1584
return getDiagnosticOfFileFromProgram ( program , file . path , file . content . indexOf ( field ) , field . length , Diagnostics . All_declarations_of_0_must_have_identical_modifiers , field ) ;
1587
1585
}
1588
1586
1589
- const files = [ aFile , libFileWithDocument ] ;
1587
+ function verifyLibFileErrorsWith ( aFile : File ) {
1588
+ const files = [ aFile , libFileWithDocument ] ;
1590
1589
1591
- function verifyLibErrors ( options : CompilerOptions ) {
1592
- const host = createWatchedSystem ( files , { currentDirectory } ) ;
1593
- const watch = createWatchOfFilesAndCompilerOptions ( [ aFile . path ] , host , options ) ;
1594
- checkProgramActualFiles ( watch ( ) , [ aFile . path , libFile . path ] ) ;
1595
- checkOutputErrorsInitial ( host , getErrors ( ) ) ;
1590
+ function verifyLibErrors ( options : CompilerOptions ) {
1591
+ const host = createWatchedSystem ( files , { currentDirectory } ) ;
1592
+ const watch = createWatchOfFilesAndCompilerOptions ( [ aFile . path ] , host , options ) ;
1593
+ checkProgramActualFiles ( watch ( ) , [ aFile . path , libFile . path ] ) ;
1594
+ checkOutputErrorsInitial ( host , getErrors ( ) ) ;
1596
1595
1597
- host . writeFile ( aFile . path , "var x = 10;" ) ;
1598
- host . runQueuedTimeoutCallbacks ( ) ;
1599
- checkProgramActualFiles ( watch ( ) , [ aFile . path , libFile . path ] ) ;
1600
- checkOutputErrorsIncremental ( host , emptyArray ) ;
1596
+ host . writeFile ( aFile . path , aFile . content . replace ( fieldWithoutReadonly , "var x: string;" ) ) ;
1597
+ host . runQueuedTimeoutCallbacks ( ) ;
1598
+ checkProgramActualFiles ( watch ( ) , [ aFile . path , libFile . path ] ) ;
1599
+ checkOutputErrorsIncremental ( host , emptyArray ) ;
1601
1600
1602
- host . writeFile ( aFile . path , aFile . content ) ;
1603
- host . runQueuedTimeoutCallbacks ( ) ;
1604
- checkProgramActualFiles ( watch ( ) , [ aFile . path , libFile . path ] ) ;
1605
- checkOutputErrorsIncremental ( host , getErrors ( ) ) ;
1606
-
1607
- function getErrors ( ) {
1608
- return [
1609
- ...( options . skipLibCheck || options . skipDefaultLibCheck ? [ ] : [ getDiagnostic ( watch ( ) , libFileWithDocument ) ] ) ,
1610
- getDiagnostic ( watch ( ) , aFile )
1611
- ] ;
1601
+ host . writeFile ( aFile . path , aFile . content ) ;
1602
+ host . runQueuedTimeoutCallbacks ( ) ;
1603
+ checkProgramActualFiles ( watch ( ) , [ aFile . path , libFile . path ] ) ;
1604
+ checkOutputErrorsIncremental ( host , getErrors ( ) ) ;
1605
+
1606
+ function getErrors ( ) {
1607
+ return [
1608
+ ...( options . skipLibCheck || options . skipDefaultLibCheck ? [ ] : [ getDiagnostic ( watch ( ) , libFileWithDocument ) ] ) ,
1609
+ getDiagnostic ( watch ( ) , aFile )
1610
+ ] ;
1611
+ }
1612
1612
}
1613
+
1614
+ it ( "with default options" , ( ) => {
1615
+ verifyLibErrors ( { } ) ;
1616
+ } ) ;
1617
+ it ( "with skipLibCheck" , ( ) => {
1618
+ verifyLibErrors ( { skipLibCheck : true } ) ;
1619
+ } ) ;
1620
+ it ( "with skipDefaultLibCheck" , ( ) => {
1621
+ verifyLibErrors ( { skipDefaultLibCheck : true } ) ;
1622
+ } ) ;
1613
1623
}
1614
1624
1615
- it ( "with default options" , ( ) => {
1616
- verifyLibErrors ( { } ) ;
1617
- } ) ;
1618
- it ( "with skipLibCheck" , ( ) => {
1619
- verifyLibErrors ( { skipLibCheck : true } ) ;
1625
+ describe ( "when non module file changes" , ( ) => {
1626
+ const aFile : File = {
1627
+ path : `${ currentDirectory } /a.ts` ,
1628
+ content : `${ fieldWithoutReadonly }
1629
+ var y: number;`
1630
+ } ;
1631
+ verifyLibFileErrorsWith ( aFile ) ;
1620
1632
} ) ;
1621
- it ( "with skipDefaultLibCheck" , ( ) => {
1622
- verifyLibErrors ( { skipDefaultLibCheck : true } ) ;
1633
+
1634
+ describe ( "when module file with global definitions changes" , ( ) => {
1635
+ const aFile : File = {
1636
+ path : `${ currentDirectory } /a.ts` ,
1637
+ content : `export {}
1638
+ declare global {
1639
+ ${ fieldWithoutReadonly }
1640
+ var y: number;
1641
+ }`
1642
+ } ;
1643
+ verifyLibFileErrorsWith ( aFile ) ;
1623
1644
} ) ;
1624
1645
} ) ;
1625
1646
0 commit comments