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

Remove unnecessary returns in asyncToGenerator helper #5548

Merged
merged 2 commits into from
Apr 6, 2017
Merged

Remove unnecessary returns in asyncToGenerator helper #5548

merged 2 commits into from
Apr 6, 2017

Conversation

zertosh
Copy link
Member

@zertosh zertosh commented Mar 26, 2017

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

These returns aren't necessary, so remove them and save a few bytes.

You can also reuse the callbacks passed to then - but I don't know if it's worth it:

diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js
index d7e1c0a..f081957 100644
--- a/packages/babel-helpers/src/helpers.js
+++ b/packages/babel-helpers/src/helpers.js
@@ -230,13 +230,11 @@ helpers.asyncToGenerator = template(`
           if (info.done) {
             resolve(value);
           } else {
-            Promise.resolve(value).then(function (value) {
-              step("next", value);
-            }, function (err) {
-              step("throw", err);
-            });
+            Promise.resolve(value).then(_next, _throw);
           }
         }
+        function _next(value) { step("next", value); }
+        function _throw(err) { step("throw", err); }

         step("next");
       });

@mention-bot
Copy link

@zertosh, thanks for your PR! By analyzing the history of the files in this pull request, we identified @loganfsmyth, @spicyj and @hzoo to be potential reviewers.

@codecov
Copy link

codecov bot commented Mar 26, 2017

Codecov Report

Merging #5548 into 7.0 will increase coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##              7.0   #5548      +/-   ##
=========================================
+ Coverage   85.45%   85.5%   +0.05%     
=========================================
  Files         200     200              
  Lines        9506    9506              
  Branches     2701    2701              
=========================================
+ Hits         8123    8128       +5     
+ Misses        887     882       -5     
  Partials      496     496
Impacted Files Coverage Δ
packages/babel-helpers/src/helpers.js 100% <ø> (ø) ⬆️
...bel-plugin-transform-es2015-classes/src/vanilla.js 90.59% <0%> (+0.85%) ⬆️
packages/babel-traverse/src/path/context.js 85.34% <0%> (+0.86%) ⬆️
packages/babel-traverse/src/path/modification.js 74.75% <0%> (+0.97%) ⬆️
packages/babel-helper-call-delegate/src/index.js 68% <0%> (+4%) ⬆️

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 7a1ccf0...56c116e. Read the comment docs.

Copy link
Contributor

@sophiebits sophiebits left a comment

Choose a reason for hiding this comment

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

lgtm

@hzoo what do I do now; can I just hit the merge button?

Copy link
Member

@xtuc xtuc left a comment

Choose a reason for hiding this comment

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

LGTM 👍

I like the functions, what about this:

diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js
index d7e1c0a..f081957 100644
--- a/packages/babel-helpers/src/helpers.js
+++ b/packages/babel-helpers/src/helpers.js
@@ -230,13 +230,11 @@ helpers.asyncToGenerator = template(`
           if (info.done) {
             resolve(value);
           } else {
-            Promise.resolve(value).then(function (value) {
-              step("next", value);
-            }, function (err) {
-              step("throw", err);
-            });
+            Promise.resolve(value).then(_next, _throw);
           }
         }
+        function _next(value) { step("next", value); }
+        function _throw(err) { step("throw", err); }

-        step("next");
+        _next();
       });

With mangling it could save even more bytes.

@hzoo
Copy link
Member

hzoo commented Mar 27, 2017

@spicyj I would wait for 2 thumbs for prs unless it's trivial - or if it's docs you can usually just merge yourself.

This in particular I thought we either did this on purpose for some reason or maybe I asked about it earlier as well lol

@hzoo
Copy link
Member

hzoo commented Mar 27, 2017

@hzoo hzoo added the PR: Polish 💅 A type of pull request used for our changelog categories label Mar 27, 2017
@hzoo hzoo merged commit f0dc710 into babel:7.0 Apr 6, 2017
@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: Polish 💅 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants