Locate imports at their first use site #16
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was motivated by #12 but ultimately unrelated to that.
This PR updates the generated imports to actually have a location. Previously imports would have no location. This is generally fine, but it meant that if you tried to import a module that didn't exist, you'd get an error at the top of the file like this:
That's not wrong since the import doesn't actually exist in the source file, but it's not very helpful either. After the changes in this PR, the imports are "located" at the same place as their first use site. That means that if you try to import a module that doesn't exist, you'll get an error at that use site:
This is much nicer and should make it easier to debug when things go wrong. Note that this also applies to modules that are hidden:
Unfortunately I couldn't think of a way to (easily) test this since the locations aren't included in the output.