-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More Flow linting for unnecessary optional chaining
Summary: The previous diff naively checks if `null` or `undefined` can appear on the LHS to judge if an optional chain is useful. However, consider the following: ``` type Foo = {bar: Bar}; type Bar = {baz: number}; declare var foo: ?Foo; foo?.bar?.baz; ``` Our previous analysis judges the second `?.` to be useful, but writing `foo?.bar.baz` would be equivalent. Although `foo?.bar` can be `undefined`, it can only be undefined due to the semantics of `?.`, not due to `foo.bar` being `undefined`. Therefore, the second `?.` does not guard against anything beyond what short-circuiting would already catch. To implement this, we add another flavor of `VoidT` which is produced solely by optional chains. We can thus detect whether a potential `undefined` is a legitimate one we should catch with `?.` or merely one produced by an earlier optional chain which we can handle with short-circuiting. Reviewed By: avikchaudhuri Differential Revision: D8122045 fbshipit-source-id: 20cd76f218f8467a16c8d930f68426ef6c581270
- Loading branch information
1 parent
3bfe2d4
commit ed80625
Showing
10 changed files
with
110 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.