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

Implicit Return Function on New Line not Preserved #806

Closed
timothyeburke opened this issue Nov 17, 2015 · 5 comments
Closed

Implicit Return Function on New Line not Preserved #806

timothyeburke opened this issue Nov 17, 2015 · 5 comments
Milestone

Comments

@timothyeburke
Copy link
Contributor

Original Code:

angular.module('bugcheck.filters').filter('zeroToDash',
    () => (i) => i === 0 ? '-' : i
)

I have "preserve_newlines": true, in my config file, but I get this output:

angular.module('bugcheck.filters').filter('zeroToDash', () => (i) => i === 0 ? '-' : i)

Is there a different config flag I should be using to preserve the line break there?

@bitwiseman bitwiseman added this to the v1.6.0 milestone Nov 18, 2015
@bitwiseman
Copy link
Member

// remains unchanged
angular.module('bugcheck.filters').filter('zeroToDash',
    a
)

// has same problem as reported above
angular.module('bugcheck.filters').filter('zeroToDash',
    (a)
)

I'm going to say this is a bug, but the fix may be tricky. I'll see what i can do in the next milestone.

What is the syntax your using at () => (i) =>? Can you point me to docs on it? We must have some support for it or you'd get worse behavior, but it isn't ringing any bells.

@timothyeburke
Copy link
Contributor Author

@bitwiseman https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

It's an es6 arrow function using implicit return that's returning an es6 arrow function using implicit return.

Using babel, it would look like this in es5:

angular.module('bugcheck.filters').filter('zeroToDash', function () {
    return function (i) {
        return i === 0 ? '-' : i;
    };
});

@bitwiseman
Copy link
Member

Okay, the issue is that we don't preserve new lines after comma and before (. Easy to do, but the tricky part will be not breaking other scenarios. But I'll definitely look at it.

@timothyeburke
Copy link
Contributor Author

I threw this together - it works in my scenario and doesn't break the other tests.
#808

@bitwiseman
Copy link
Member

Well, that's pretty cool. Thanks!

bitwiseman added a commit that referenced this issue Nov 18, 2015
Resolve #806: Preserve newline on arrow functions.
olsonpm pushed a commit to olsonpm/js-beautify that referenced this issue Dec 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants