support early returns and typeof checks for feature detection #596
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.
Hey Amila, thanks for building this plugin!
Sorry for the large PR, I'm hoping this will spark some discussion mainly, the code here is still WIP. But I wanted to get it in front of you before I get too far along.
As a lot of the issues point out,
if
statements prevent this plugin from detecting browser compat issues, and I wanted to take a shot at fixing it. But I wound up taking a few steps more and fixed a few other things.Fundamentally this sort of changes how this plugin is implemented. But I think it makes sense as far as what this plugin is meant to catch. When I think about these apis, I don't really care whether they're function calls,
new
statements, or member expressions. The error is simply that the object/method doesn't exist in certain browsers, and that's what we want to catch.With that in mind, this PR changes the approach to only lint on
Identifier
nodes. And it focuses on what types of operations would cause runtime errors. So any code that is testing if a feature exists is now okay:But if you do something that would result in a
ReferenceError
, we'll report it:I did a bit of other cleanup too, if that's desirable:
I'm happy to make whatever changes you'd like! I very much want to use this plugin, and these issues were the main blockers for me. I also plan on adding linting for unsupported regex features, and probably going through the list of other issues as well.
fixes:
typeof
in feature detection #520