@@ -98,4 +98,27 @@ namespace ts {
98
98
] ) ;
99
99
} ) ;
100
100
} ) ;
101
+
102
+ describe ( "Program.isSourceFileFromExternalLibrary" , ( ) => {
103
+ it ( "works on redirect files" , ( ) => {
104
+ // In this example '/node_modules/foo/index.d.ts' will redirect to '/node_modules/bar/node_modules/foo/index.d.ts'.
105
+ const a = new documents . TextDocument ( "/a.ts" , 'import * as bar from "bar"; import * as foo from "foo";' ) ;
106
+ const bar = new documents . TextDocument ( "/node_modules/bar/index.d.ts" , 'import * as foo from "foo";' ) ;
107
+ const fooPackageJsonText = '{ "name": "foo", "version": "1.2.3" }' ;
108
+ const fooIndexText = "export const x: number;" ;
109
+ const barFooPackage = new documents . TextDocument ( "/node_modules/bar/node_modules/foo/package.json" , fooPackageJsonText ) ;
110
+ const barFooIndex = new documents . TextDocument ( "/node_modules/bar/node_modules/foo/index.d.ts" , fooIndexText ) ;
111
+ const fooPackage = new documents . TextDocument ( "/node_modules/foo/package.json" , fooPackageJsonText ) ;
112
+ const fooIndex = new documents . TextDocument ( "/node_modules/foo/index.d.ts" , fooIndexText ) ;
113
+
114
+ const fs = vfs . createFromFileSystem ( Harness . IO , /*ignoreCase*/ false , { documents : [ a , bar , barFooPackage , barFooIndex , fooPackage , fooIndex ] , cwd : "/" } ) ;
115
+ const program = createProgram ( [ "/a.ts" ] , emptyOptions , new fakes . CompilerHost ( fs , { newLine : NewLineKind . LineFeed } ) ) ;
116
+
117
+ for ( const file of [ a , bar , barFooIndex , fooIndex ] ) {
118
+ const isExternalExpected = file !== a ;
119
+ const isExternalActual = program . isSourceFileFromExternalLibrary ( program . getSourceFile ( file . file ) ! ) ;
120
+ assert . equal ( isExternalActual , isExternalExpected , `Expected ${ file . file } isSourceFileFromExternalLibrary to be ${ isExternalExpected } , got ${ isExternalActual } ` ) ;
121
+ }
122
+ } ) ;
123
+ } ) ;
101
124
}
0 commit comments