Skip to content
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

Prevent multiple return statements in a loop when replacing expressions #5030

Merged
merged 1 commit into from Feb 9, 2017

Conversation

existentialism
Copy link
Member

@existentialism existentialism commented Dec 21, 2016

Q A
Patch: Bug Fix? Y
Major: Breaking Change? N
Minor: New Feature? N
Deprecations? N
Spec Compliancy? N
Tests Added/Pass? Y/Y
Fixed Tickets Fixes #5022
License MIT
Doc PR
Dependency Changes

Could definitely use some guidance on this, as I'm still digging through a lot of this :P

@existentialism existentialism added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Dec 21, 2016
@codecov-io
Copy link

codecov-io commented Dec 21, 2016

Codecov Report

Merging #5030 into master will increase coverage by 0.02%.

@@            Coverage Diff             @@
##           master    #5030      +/-   ##
==========================================
+ Coverage   89.15%   89.17%   +0.02%     
==========================================
  Files         203      203              
  Lines        9823     9824       +1     
  Branches     2616     2615       -1     
==========================================
+ Hits         8758     8761       +3     
+ Misses       1065     1063       -2
Impacted Files Coverage Δ
packages/babel-traverse/src/path/replacement.js 80.18% <100%> (+0.55%)
...abel-generator/src/generators/template-literals.js 100% <ø> (ø)
packages/babel-traverse/src/path/family.js 86.45% <ø> (+2.08%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c3392f...9c46fd6. Read the comment docs.

@xtuc
Copy link
Member

xtuc commented Dec 21, 2016

Nice job! 👍

let uid = loop.getData("expressionReplacementReturnUid");

if (!uid) {
let callee = this.get("callee");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

@@ -0,0 +1,9 @@
let a = do {
while (p = p.parentPath) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd feel better if there was a let p before the let a 😃

uid = callee.scope.generateDeclaredUidIdentifier("ret");
callee.get("body").pushContainer("body", t.returnStatement(uid));
loop.setData("expressionReplacementReturnUid", uid);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably do

} else {
  uid = t.identifier(uid.name);
}

or else we'll be inserting the same identifier node in multiple places in the AST.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@loganfsmyth
Copy link
Member

One small comment, and this has a conflict, but otherwise looks good.

@loganfsmyth loganfsmyth merged commit 6da9bb8 into babel:master Feb 9, 2017
@existentialism existentialism deleted the issue5022 branch February 9, 2017 21:07
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do expressions transform incorrectly for if inside while statements
5 participants