joarwilk / flowgen

Generate flowtype definition files from TypeScript
Other
657 stars 87 forks source link

Fix issue where transformers didn't run on imported files #183

Closed gnprice closed 2 years ago

gnprice commented 2 years ago

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.

And add a test that reproduces the issue.

orta commented 2 years ago

Thanks looks good to me!