From 86d1264097e7905fb3eee0540e9075f94514fea4 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 2 Feb 2017 10:37:59 -0800 Subject: [PATCH] Fix ternary indent bug (#577) * Add test.js files back to source control * Fix ternary indent bug (#564) --- .gitignore | 1 - src/printer.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 52 +++++++++++++++++++ tests/ternaries/jsfmt.spec.js | 1 + 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2c48b4041..93f136199 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ node_modules npm-debug.log -test.js diff --git a/src/printer.js b/src/printer.js index 23daf3e4d..229e5bfa0 100644 --- a/src/printer.js +++ b/src/printer.js @@ -774,10 +774,10 @@ function genericPrintNoParens(path, options, print) { concat([ line, "? ", - indent(options.tabWidth, path.call(print, "consequent")), + indent(2, path.call(print, "consequent")), line, ": ", - indent(options.tabWidth, path.call(print, "alternate")) + indent(2, path.call(print, "alternate")) ]) ) ]) diff --git a/tests/ternaries/__snapshots__/jsfmt.spec.js.snap b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap index 84f0402ff..b78a8903c 100644 --- a/tests/ternaries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap @@ -49,3 +49,55 @@ const obj5 = conditionIsTruthy }; " `; + +exports[`test test.js 2`] = ` +"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 index 989047bcc..1ec983a6b 100644 --- a/tests/ternaries/jsfmt.spec.js +++ b/tests/ternaries/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, { tabWidth: 4 });