Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Convert simple arrow function body to expression #616

Merged
merged 2 commits into from
Jul 8, 2017

Conversation

ashsearle
Copy link
Contributor

Eliminate unnecessary return keyword by converting arrow function block statements to expressions where possible.

Example:

const foo = () => {
  return (1, 2);
};
const bar = () => {
  return [];
};

// becomes
const foo = () => (1, 2);
const bar = () => [];

@boopathi boopathi added the Tag: New Feature Pull Request adding a new feature label Jul 7, 2017
@@ -780,6 +780,17 @@ module.exports = ({ types: t }) => {
exit(path) {
const { node, parent } = path;

if (
t.isArrowFunctionExpression(parent) &&
node.body &&
Copy link
Member

@boopathi boopathi Jul 7, 2017

Choose a reason for hiding this comment

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

We are in a BlockStatement - is this check ever falsey ? A BlockStatement's body is always an array.

@boopathi boopathi self-assigned this Jul 7, 2017
@boopathi boopathi merged commit 5e1870b into babel:master Jul 8, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Tag: New Feature Pull Request adding a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants