Move to file: fix detection of references to globals that shouldn't be moved #60450
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.
Fixes #59799
Fixes #60408
Closes #60173
Closes #60410
isGlobalType
was a red herring; it was implemented incorrectly but it never mattered if something was a global type. What we actually care about is whether the thing we’re moving was merging with declarations in other files. If we check that after ruling out that it was in an import, then it must be a global, and if the thing has a global definition in another file, we can’t start exporting it without breaking that merge:Why don’t we want to export
interface String
when we move the prototype method definition here?String.prototype...
refers to a value whileinterface String
refers to a type—this feels important, but they’re actually two different meanings of the same symbol!String
is a global type—if we had instead writteninterface Foo {}
and moved the codetype Bar = Foo
, it would be true thatFoo
is a global type, but we make an assumption that most people want modules most of the time, and it’s probably a coincidence that they hadn’t made this file a module yet. In this case, we would actually start exportinginterface Foo {}
, converting it from a global type to an exported type. (Also, the same argument can be made for values, so being a type has nothing to do with it.)String
from a global to an export by making modifications in this file alone—there are other definitions ofString
in other files, which increases our confidence that it’s actually intended to be a global.