Indent ternaries (#484)

master
Alex Rattray 2017-01-26 11:58:40 -08:00 committed by Christopher Chedeau
parent eaddd4b3e6
commit 72c9424c53
6 changed files with 98 additions and 35 deletions

View File

@ -771,10 +771,10 @@ function genericPrintNoParens(path, options, print) {
concat([
line,
"? ",
path.call(print, "consequent"),
indent(options.tabWidth, path.call(print, "consequent")),
line,
": ",
path.call(print, "alternate")
indent(options.tabWidth, path.call(print, "alternate"))
])
)
])

View File

@ -192,37 +192,37 @@ const renderTernary = props => (
>
{props.showTheThing
? <BaseForm
url=\"/auth/google\"
method=\"GET\"
colour=\"blue\"
size=\"large\"
submitLabel=\"Sign in with Google\"
>
Hello world
</BaseForm>
url=\"/auth/google\"
method=\"GET\"
colour=\"blue\"
size=\"large\"
submitLabel=\"Sign in with Google\"
>
Hello world
</BaseForm>
: \"hello \" + \"howdy! \"}
{props.showTheThing
? <BaseForm
url=\"/auth/google\"
method=\"GET\"
colour=\"blue\"
size=\"large\"
submitLabel=\"Sign in with Google\"
>
Hello world
</BaseForm>
url=\"/auth/google\"
method=\"GET\"
colour=\"blue\"
size=\"large\"
submitLabel=\"Sign in with Google\"
>
Hello world
</BaseForm>
: null}
{props.showTheThing
? null
: <BaseForm
url=\"/auth/google\"
method=\"GET\"
colour=\"blue\"
size=\"large\"
submitLabel=\"Sign in with Google\"
>
Hello world
</BaseForm>}
url=\"/auth/google\"
method=\"GET\"
colour=\"blue\"
size=\"large\"
submitLabel=\"Sign in with Google\"
>
Hello world
</BaseForm>}
{props.showTheOtherThing ? <div>I am here</div> : <div attr=\"blah\" />}
{props.showTheOtherThing ? <div>I am here!!</div> : null}
</BaseForm>

View File

@ -156,15 +156,15 @@ exports[`test hug.js 1`] = `
{__DEV__
? this.renderDevApp()
: <div>
{routes.map(route => (
<MatchAsync
key={\`\${route.to}-async\`}
pattern={route.to}
exactly={route.to === \"/\"}
getComponent={routeES6Modules[route.value]}
/>
))}
</div>}
{routes.map(route => (
<MatchAsync
key={\`\${route.to}-async\`}
pattern={route.to}
exactly={route.to === \"/\"}
getComponent={routeES6Modules[route.value]}
/>
))}
</div>}
</div>;
<div>

View File

@ -0,0 +1,51 @@
exports[`test test.js 1`] = `
"const obj0 = conditionIsTruthy ? shortThing : otherShortThing
const obj1 = conditionIsTruthy ? { some: \'long\', object: \'with\', lots: \'of\', stuff } : shortThing
const obj2 = conditionIsTruthy ? shortThing : { some: \'long\', object: \'with\', lots: \'of\', stuff }
const obj3 = conditionIsTruthy ? { some: \'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\', object: \'with\', lots: \'of\', stuff } : shortThing
const obj4 = conditionIsTruthy ? shortThing : { some: \'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\', object: \'with\', lots: \'of\', stuff }
const obj5 = conditionIsTruthy ? { some: \'long\', object: \'with\', lots: \'of\', stuff } : { some: \'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\', object: \'with\', lots: \'of\', stuff }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const obj0 = conditionIsTruthy ? shortThing : otherShortThing;
const obj1 = conditionIsTruthy
? { some: \"long\", object: \"with\", lots: \"of\", stuff }
: shortThing;
const obj2 = conditionIsTruthy
? shortThing
: { some: \"long\", object: \"with\", lots: \"of\", stuff };
const obj3 = conditionIsTruthy
? {
some: \"eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\",
object: \"with\",
lots: \"of\",
stuff
}
: shortThing;
const obj4 = conditionIsTruthy
? shortThing
: {
some: \"eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\",
object: \"with\",
lots: \"of\",
stuff
};
const obj5 = conditionIsTruthy
? { some: \"long\", object: \"with\", lots: \"of\", stuff }
: {
some: \"eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger\",
object: \"with\",
lots: \"of\",
stuff
};
"
`;

View File

@ -0,0 +1 @@
run_spec(__dirname);

11
tests/ternaries/test.js Normal file
View File

@ -0,0 +1,11 @@
const obj0 = conditionIsTruthy ? shortThing : otherShortThing
const obj1 = conditionIsTruthy ? { some: 'long', object: 'with', lots: 'of', stuff } : shortThing
const obj2 = conditionIsTruthy ? shortThing : { some: 'long', object: 'with', lots: 'of', stuff }
const obj3 = conditionIsTruthy ? { some: 'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger', object: 'with', lots: 'of', stuff } : shortThing
const obj4 = conditionIsTruthy ? shortThing : { some: 'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger', object: 'with', lots: 'of', stuff }
const obj5 = conditionIsTruthy ? { some: 'long', object: 'with', lots: 'of', stuff } : { some: 'eeeeeeeeeeeeven looooooooooooooooooooooooooooooonger', object: 'with', lots: 'of', stuff }