-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test for for-of optimization on arrays and add it for array type anno… #4747
Conversation
a8d8b9a
to
dced37b
Compare
Codecov Report
@@ Coverage Diff @@
## 7.0 #4747 +/- ##
==========================================
+ Coverage 85.21% 85.33% +0.11%
==========================================
Files 284 284
Lines 9958 9984 +26
Branches 2780 2788 +8
==========================================
+ Hits 8486 8520 +34
+ Misses 971 965 -6
+ Partials 501 499 -2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
This assumes that people have the correct type annotation. But what if they do what we do? Like having typeannotations but not verifying them, because then even if the type annotation is Array it could be an object. |
Hm good point - would we be ok with that assumption? @jridgewell thoughts? |
Linking @Kovensky's suggestion too http://astexplorer.net/#/dh8bycNK1A/2 |
I think the biggest improvement here is when we can prove it's an array, so @Kovensky's would work just fine for me. |
We could remove the type annotation check I guess and it would just check for binding/array.from |
How about with |
@danez I think if you are going to opt-in to types, it's on you to make sure you run flow/ts. So it's a good assumption to make |
via @ljharb: |
@@ -0,0 +1,4 @@ | |||
for (const y of (b: Array<any>)) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't add the type check yet but we can
I think we can land this as is since I didn't add the type part so it's safe |
const binding = path.scope.getBinding(right.node.name); | ||
return optimize(path, binding.path.get("init")); | ||
} else if (right.isCallExpression() && ( | ||
isArrayFrom(right.get("callee").node) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather see this in
babel/packages/babel-traverse/src/path/inference/inferers.js
Lines 148 to 150 in 622672d
export function CallExpression() { | |
return resolveCall(this.get("callee")); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to let you finish this up if you want to refactor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this, I'll add this to #5835, and you'll promise to review it. 😉
was going to do this earlier but I closed the pr