@@ -1564,6 +1564,146 @@ 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" , ( ) => {
1569
+ const currentDirectory = "/user/username/projects/myproject" ;
1570
+ const field = "fullscreen" ;
1571
+ const fieldWithoutReadonly = `interface Document {
1572
+ ${ field } : boolean;
1573
+ }` ;
1574
+
1575
+ const libFileWithDocument : File = {
1576
+ path : libFile . path ,
1577
+ content : `${ libFile . content }
1578
+ interface Document {
1579
+ readonly ${ field } : boolean;
1580
+ }`
1581
+ } ;
1582
+
1583
+ function getDiagnostic ( program : Program , file : File ) {
1584
+ return getDiagnosticOfFileFromProgram ( program , file . path , file . content . indexOf ( field ) , field . length , Diagnostics . All_declarations_of_0_must_have_identical_modifiers , field ) ;
1585
+ }
1586
+
1587
+ function verifyLibFileErrorsWith ( aFile : File ) {
1588
+ const files = [ aFile , libFileWithDocument ] ;
1589
+
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 ( ) ) ;
1595
+
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 ) ;
1600
+
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
+ }
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
+ } ) ;
1623
+ }
1624
+
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 ) ;
1632
+ } ) ;
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 ) ;
1644
+ } ) ;
1645
+ } ) ;
1646
+
1647
+ it ( "when skipLibCheck and skipDefaultLibCheck changes" , ( ) => {
1648
+ const currentDirectory = "/user/username/projects/myproject" ;
1649
+ const field = "fullscreen" ;
1650
+ const aFile : File = {
1651
+ path : `${ currentDirectory } /a.ts` ,
1652
+ content : `interface Document {
1653
+ ${ field } : boolean;
1654
+ }`
1655
+ } ;
1656
+ const bFile : File = {
1657
+ path : `${ currentDirectory } /b.d.ts` ,
1658
+ content : `interface Document {
1659
+ ${ field } : boolean;
1660
+ }`
1661
+ } ;
1662
+ const libFileWithDocument : File = {
1663
+ path : libFile . path ,
1664
+ content : `${ libFile . content }
1665
+ interface Document {
1666
+ readonly ${ field } : boolean;
1667
+ }`
1668
+ } ;
1669
+ const configFile : File = {
1670
+ path : `${ currentDirectory } /tsconfig.json` ,
1671
+ content : "{}"
1672
+ } ;
1673
+
1674
+ const files = [ aFile , bFile , configFile , libFileWithDocument ] ;
1675
+
1676
+ const host = createWatchedSystem ( files , { currentDirectory } ) ;
1677
+ const watch = createWatchOfConfigFile ( "tsconfig.json" , host ) ;
1678
+ verifyProgramFiles ( ) ;
1679
+ checkOutputErrorsInitial ( host , [
1680
+ getDiagnostic ( libFileWithDocument ) ,
1681
+ getDiagnostic ( aFile ) ,
1682
+ getDiagnostic ( bFile )
1683
+ ] ) ;
1684
+
1685
+ verifyConfigChange ( { skipLibCheck : true } , [ aFile ] ) ;
1686
+ verifyConfigChange ( { skipDefaultLibCheck : true } , [ aFile , bFile ] ) ;
1687
+ verifyConfigChange ( { } , [ libFileWithDocument , aFile , bFile ] ) ;
1688
+ verifyConfigChange ( { skipDefaultLibCheck : true } , [ aFile , bFile ] ) ;
1689
+ verifyConfigChange ( { skipLibCheck : true } , [ aFile ] ) ;
1690
+ verifyConfigChange ( { } , [ libFileWithDocument , aFile , bFile ] ) ;
1691
+
1692
+ function verifyConfigChange ( compilerOptions : CompilerOptions , errorInFiles : ReadonlyArray < File > ) {
1693
+ host . writeFile ( configFile . path , JSON . stringify ( { compilerOptions } ) ) ;
1694
+ host . runQueuedTimeoutCallbacks ( ) ;
1695
+ verifyProgramFiles ( ) ;
1696
+ checkOutputErrorsIncremental ( host , errorInFiles . map ( getDiagnostic ) ) ;
1697
+ }
1698
+
1699
+ function getDiagnostic ( file : File ) {
1700
+ return getDiagnosticOfFileFromProgram ( watch ( ) , file . path , file . content . indexOf ( field ) , field . length , Diagnostics . All_declarations_of_0_must_have_identical_modifiers , field ) ;
1701
+ }
1702
+
1703
+ function verifyProgramFiles ( ) {
1704
+ checkProgramActualFiles ( watch ( ) , [ aFile . path , bFile . path , libFile . path ] ) ;
1705
+ }
1706
+ } ) ;
1567
1707
} ) ;
1568
1708
1569
1709
describe ( "tsc-watch emit with outFile or out setting" , ( ) => {
0 commit comments