@@ -1564,6 +1564,125 @@ export class Data2 {
1564
1564
verifyTransitiveExports ( [ libFile , app , lib2Public , lib2Data , lib2Data2 , lib1Public , lib1ToolsPublic , lib1ToolsInterface ] ) ;
1565
1565
} ) ;
1566
1566
} ) ;
1567
+
1568
+ describe ( "updates errors in lib file when non module file changes" , ( ) => {
1569
+ const currentDirectory = "/user/username/projects/myproject" ;
1570
+ const field = "fullscreen" ;
1571
+ const aFile : File = {
1572
+ path : `${ currentDirectory } /a.ts` ,
1573
+ content : `interface Document {
1574
+ ${ field } : boolean;
1575
+ }`
1576
+ } ;
1577
+ const libFileWithDocument : File = {
1578
+ path : libFile . path ,
1579
+ content : `${ libFile . content }
1580
+ interface Document {
1581
+ readonly ${ field } : boolean;
1582
+ }`
1583
+ } ;
1584
+
1585
+ function getDiagnostic ( program : Program , file : File ) {
1586
+ return getDiagnosticOfFileFromProgram ( program , file . path , file . content . indexOf ( field ) , field . length , Diagnostics . All_declarations_of_0_must_have_identical_modifiers , field ) ;
1587
+ }
1588
+
1589
+ const files = [ aFile , libFileWithDocument ] ;
1590
+
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 ( ) ) ;
1596
+
1597
+ host . writeFile ( aFile . path , "var x = 10;" ) ;
1598
+ host . runQueuedTimeoutCallbacks ( ) ;
1599
+ checkProgramActualFiles ( watch ( ) , [ aFile . path , libFile . path ] ) ;
1600
+ checkOutputErrorsIncremental ( host , emptyArray ) ;
1601
+
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
+ ] ;
1612
+ }
1613
+ }
1614
+
1615
+ it ( "with default options" , ( ) => {
1616
+ verifyLibErrors ( { } ) ;
1617
+ } ) ;
1618
+ it ( "with skipLibCheck" , ( ) => {
1619
+ verifyLibErrors ( { skipLibCheck : true } ) ;
1620
+ } ) ;
1621
+ it ( "with skipDefaultLibCheck" , ( ) => {
1622
+ verifyLibErrors ( { skipDefaultLibCheck : true } ) ;
1623
+ } ) ;
1624
+ } ) ;
1625
+
1626
+ it ( "when skipLibCheck and skipDefaultLibCheck changes" , ( ) => {
1627
+ const currentDirectory = "/user/username/projects/myproject" ;
1628
+ const field = "fullscreen" ;
1629
+ const aFile : File = {
1630
+ path : `${ currentDirectory } /a.ts` ,
1631
+ content : `interface Document {
1632
+ ${ field } : boolean;
1633
+ }`
1634
+ } ;
1635
+ const bFile : File = {
1636
+ path : `${ currentDirectory } /b.d.ts` ,
1637
+ content : `interface Document {
1638
+ ${ field } : boolean;
1639
+ }`
1640
+ } ;
1641
+ const libFileWithDocument : File = {
1642
+ path : libFile . path ,
1643
+ content : `${ libFile . content }
1644
+ interface Document {
1645
+ readonly ${ field } : boolean;
1646
+ }`
1647
+ } ;
1648
+ const configFile : File = {
1649
+ path : `${ currentDirectory } /tsconfig.json` ,
1650
+ content : "{}"
1651
+ } ;
1652
+
1653
+ const files = [ aFile , bFile , configFile , libFileWithDocument ] ;
1654
+
1655
+ const host = createWatchedSystem ( files , { currentDirectory } ) ;
1656
+ const watch = createWatchOfConfigFile ( "tsconfig.json" , host ) ;
1657
+ verifyProgramFiles ( ) ;
1658
+ checkOutputErrorsInitial ( host , [
1659
+ getDiagnostic ( libFileWithDocument ) ,
1660
+ getDiagnostic ( aFile ) ,
1661
+ getDiagnostic ( bFile )
1662
+ ] ) ;
1663
+
1664
+ verifyConfigChange ( { skipLibCheck : true } , [ aFile ] ) ;
1665
+ verifyConfigChange ( { skipDefaultLibCheck : true } , [ aFile , bFile ] ) ;
1666
+ verifyConfigChange ( { } , [ libFileWithDocument , aFile , bFile ] ) ;
1667
+ verifyConfigChange ( { skipDefaultLibCheck : true } , [ aFile , bFile ] ) ;
1668
+ verifyConfigChange ( { skipLibCheck : true } , [ aFile ] ) ;
1669
+ verifyConfigChange ( { } , [ libFileWithDocument , aFile , bFile ] ) ;
1670
+
1671
+ function verifyConfigChange ( compilerOptions : CompilerOptions , errorInFiles : ReadonlyArray < File > ) {
1672
+ host . writeFile ( configFile . path , JSON . stringify ( { compilerOptions } ) ) ;
1673
+ host . runQueuedTimeoutCallbacks ( ) ;
1674
+ verifyProgramFiles ( ) ;
1675
+ checkOutputErrorsIncremental ( host , errorInFiles . map ( getDiagnostic ) ) ;
1676
+ }
1677
+
1678
+ function getDiagnostic ( file : File ) {
1679
+ return getDiagnosticOfFileFromProgram ( watch ( ) , file . path , file . content . indexOf ( field ) , field . length , Diagnostics . All_declarations_of_0_must_have_identical_modifiers , field ) ;
1680
+ }
1681
+
1682
+ function verifyProgramFiles ( ) {
1683
+ checkProgramActualFiles ( watch ( ) , [ aFile . path , bFile . path , libFile . path ] ) ;
1684
+ }
1685
+ } ) ;
1567
1686
} ) ;
1568
1687
1569
1688
describe ( "tsc-watch emit with outFile or out setting" , ( ) => {
0 commit comments