Skip to content
This repository was archived by the owner on Oct 1, 2019. It is now read-only.

Fix elif with multiple body #7

Merged
merged 3 commits into from
Jan 13, 2018
Merged

Conversation

vjeux
Copy link
Contributor

@vjeux vjeux commented Dec 25, 2017

Fixes #4

@vjeux vjeux requested a review from patrick91 December 25, 2017 19:54
if condition:
pass
assert somethinganother_statement()

Copy link
Member

Choose a reason for hiding this comment

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

Is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh wow no. I made it not crash, I didn't realize it was completely broken... Oops!

@patrick91
Copy link
Member

@vjeux I've added a working version of the if printing, it is bit ugly, there's some code duplication as well, but we can fix that. Can you see if you like the approach? :)

@vjeux
Copy link
Contributor Author

vjeux commented Jan 13, 2018

Your code looks good :)

Code duplication is fine. I would say it’s even better than trying to come with some convoluted abstraction.

The problem here is that the ast itself is fucked up, not that the printer code is bad or more complicated than it ought to be

@patrick91 patrick91 merged commit 22f4b3f into prettier:master Jan 13, 2018
@patrick91
Copy link
Member

Thanks @vjeux I've cleaned it up a bit and merged :)

@vjeux
Copy link
Contributor Author

vjeux commented Jan 13, 2018

@patrick91: btw, treat this as your project, feel free to commit as often as you want :)

const n = path.getValue();

if (n.orelse && n.orelse.length > 0) {
if (n.orelse[0].ast_type === "If") {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should check that the length is exactly 1. Otherwise you transform

if foo:
    foo()
else:
    if bar:
        bar()
    if baz:
        baz()

into

if foo:
  foo()
elif bar:
  bar()
elif baz:
  baz()

And other weird things whenever an if shows up under an else for any reason.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch! I've submitted an initial PR to fix this: #20

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants