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

Object attribute assigned fat arrow function with implicit return of a ternary causes next line to indent #854

Closed
underscorebrody opened this issue Jan 26, 2016 · 9 comments
Milestone

Comments

@underscorebrody
Copy link

For example:

Original:

test(() => {
    var a = {}

    a.what = () => true ? 1 : 2

    a.thing = () => {
        // some code
    }
})

Becomes this:

test(() => {
    var a = {}

    a.what = () => true ? 1 : 2

        a.thing = () => {
        // some code
    }
})

Notes:

  • This can be worked around by putting the ternary in parentheses
  • It does not occur if the fat arrow function is being assigned to a the value of a var, only if it's assigned to the attribute of an object
  • Only occurs inside a function being passed as an argument to another function
  • Only occurs if there is a line between the function with the ternary and the next function
@underscorebrody underscorebrody changed the title Assigned fat arrow function with implicit return of results of a ternary causes next line to indent Object attribute assigned fat arrow function with implicit return of a ternary causes next line to indent Jan 26, 2016
@bitwiseman
Copy link
Member

Again, are you sure? I don't see this when I run with the new setting against that input. 😄

@bitwiseman
Copy link
Member

In just a minute, I'll have the new code up on the website and you should be able to double check issues you find.

@underscorebrody
Copy link
Author

This one i'm pretty sure about! I saw this issue but not the other one i mentioned once i had re-installed against the most recent hash. I will re-test once the code is live though to verify.

@underscorebrody
Copy link
Author

Okay I've done some additonal testing, it seems this only occurs if the code is inside a function being passed as an argument to another function, i've updated the description with additional notes and specifications for reproduction. I was able to reproduce it in a blank file with the above code in it.

@bitwiseman
Copy link
Member

Excellent! Thanks!

@bitwiseman bitwiseman added this to the v1.6.0 milestone Jan 26, 2016
@bitwiseman
Copy link
Member

So, both of these work, but the one you provided breaks. Should be easy enough to track down. Thanks again.

test(() => {
    var a = {}

    a.what = () => true ? 1 : 2;

    a.thing = () => {
        // some code
    }
})

test(() => {
    var a = {}

    a.what = () => true ? 1 : 2
    a.thing = () => {
        a()
    }
})

@underscorebrody
Copy link
Author

Interesting, this one also works FYI:

test(() => {
    var a = {}

    a.what = () => (true ? 1 : 2)

    a.thing = () => {
        // some code
    }
})

@bitwiseman
Copy link
Member

Yeah, that makes sense. The => has an implied expression after it. The () makes the expression explicit. The ; case is the same way, it make the end-of-statement explicit. The beautifier has a hard time with implicit cases - it often doesn't have enough information to figure out what is going on.

@underscorebrody
Copy link
Author

Thanks, @bitwiseman !!

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