The file parameter TS passes to compilerHost.getSourceFile will
sometimes be the same path string that we passed to createProgram.
In particular, it seems to work that way for the very first file in
the list.
But then if that file imports from other files, the TS compiler will
go find those files and pass them to getSourceFile using absolute
paths, even if the same file appears in our list under a relative
path.
As a result, when comparing the filename passed to getSourceFile
against our list of files we mean to operate on, we'll miss that it's
there and fail to realize we should apply our transformers.
Fix the issue by making those comparisons entirely in terms of
absolute paths. Also, while we're here, use a Set instead of
searching through an Array, so that the lookups take O(1) time.
The
file
parameter TS passes tocompilerHost.getSourceFile
will sometimes be the same path string that we passed tocreateProgram
. In particular, it seems to work that way for the very first file in the list.But then if that file imports from other files, the TS compiler will go find those files and pass them to
getSourceFile
using absolute paths, even if the same file appears in our list under a relative path.As a result, when comparing the filename passed to
getSourceFile
against our list of files we mean to operate on, we'll miss that it's there and fail to realize we should apply our transformers.Fix the issue by making those comparisons entirely in terms of absolute paths. Also, while we're here, use a Set instead of searching through an Array, so that the lookups take O(1) time.
And add a test that reproduces the issue.