diff --git a/src/printer.js b/src/printer.js index 2a9bc17b3..e2a7e3343 100644 --- a/src/printer.js +++ b/src/printer.js @@ -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")) ]) ) ]) diff --git a/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap index 73b3b59d4..e43d78705 100644 --- a/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap @@ -192,37 +192,37 @@ const renderTernary = props => ( > {props.showTheThing ? - Hello world - + url=\"/auth/google\" + method=\"GET\" + colour=\"blue\" + size=\"large\" + submitLabel=\"Sign in with Google\" + > + Hello world + : \"hello \" + \"howdy! \"} {props.showTheThing ? - Hello world - + url=\"/auth/google\" + method=\"GET\" + colour=\"blue\" + size=\"large\" + submitLabel=\"Sign in with Google\" + > + Hello world + : null} {props.showTheThing ? null : - Hello world - } + url=\"/auth/google\" + method=\"GET\" + colour=\"blue\" + size=\"large\" + submitLabel=\"Sign in with Google\" + > + Hello world + } {props.showTheOtherThing ?
I am here
:
} {props.showTheOtherThing ?
I am here!!
: null} diff --git a/tests/jsx/__snapshots__/jsfmt.spec.js.snap b/tests/jsx/__snapshots__/jsfmt.spec.js.snap index 0e16d3f46..c3a386b49 100644 --- a/tests/jsx/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx/__snapshots__/jsfmt.spec.js.snap @@ -156,15 +156,15 @@ exports[`test hug.js 1`] = ` {__DEV__ ? this.renderDevApp() :
- {routes.map(route => ( - - ))} -
} + {routes.map(route => ( + + ))} +
} ;
diff --git a/tests/ternaries/__snapshots__/jsfmt.spec.js.snap b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..84f0402ff --- /dev/null +++ b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap @@ -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 + }; +" +`; diff --git a/tests/ternaries/jsfmt.spec.js b/tests/ternaries/jsfmt.spec.js new file mode 100644 index 000000000..989047bcc --- /dev/null +++ b/tests/ternaries/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname); diff --git a/tests/ternaries/test.js b/tests/ternaries/test.js new file mode 100644 index 000000000..dc275317b --- /dev/null +++ b/tests/ternaries/test.js @@ -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 }