From 867b8299652464a4301e12bd71b96065e7306c13 Mon Sep 17 00:00:00 2001 From: Dan Harper Date: Tue, 10 Jan 2017 18:42:03 +0000 Subject: [PATCH] Print Flow types with no name (fixes #38) --- src/printer.js | 4 ++-- tests/prettier/__snapshots__/jsfmt.spec.js.snap | 9 +++++++++ tests/prettier/jsfmt.spec.js | 1 + tests/prettier/optional-type-name.js | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tests/prettier/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/prettier/jsfmt.spec.js create mode 100644 tests/prettier/optional-type-name.js diff --git a/src/printer.js b/src/printer.js index 6e71a04e..c4092565 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1329,7 +1329,7 @@ function genericPrintNoParens(path, options, print) { return concat([ path.call(print, "name"), n.optional ? "?" : "", - ": ", + n.name ? ": " : "", path.call(print, "typeAnnotation") ]); case "GenericTypeAnnotation": @@ -1399,7 +1399,7 @@ function genericPrintNoParens(path, options, print) { variance, "[", path.call(print, "id"), - ": ", + n.id ? ": " : "", path.call(print, "key"), "]: ", path.call(print, "value") diff --git a/tests/prettier/__snapshots__/jsfmt.spec.js.snap b/tests/prettier/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..a1221a5a --- /dev/null +++ b/tests/prettier/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,9 @@ +exports[`test optional-type-name.js 1`] = ` +"type Foo = (any) => string + +type Bar = { [string]: number } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +type Foo = (any) => string; + +type Bar = { [string]: number };" +`; diff --git a/tests/prettier/jsfmt.spec.js b/tests/prettier/jsfmt.spec.js new file mode 100644 index 00000000..989047bc --- /dev/null +++ b/tests/prettier/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname); diff --git a/tests/prettier/optional-type-name.js b/tests/prettier/optional-type-name.js new file mode 100644 index 00000000..fb40895a --- /dev/null +++ b/tests/prettier/optional-type-name.js @@ -0,0 +1,3 @@ +type Foo = (any) => string + +type Bar = { [string]: number }