From 1234ceb1d627f9fb535481b3a169cab46f45732e Mon Sep 17 00:00:00 2001 From: Aquib Master Date: Fri, 26 Oct 2018 03:49:53 +1300 Subject: [PATCH] Fix flow extends not breaking out into new lines (#5244) --- src/language-js/printer-estree.js | 6 +- .../__snapshots__/jsfmt.spec.js.snap | 127 ++++++++++++++++++ tests/interface/break.js | 46 +++++++ 3 files changed, 178 insertions(+), 1 deletion(-) diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 2bdd7f9d..2de50a9a 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -2651,7 +2651,11 @@ function printPathNoParens(path, options, print, args) { parts.push( group( indent( - concat([line, "extends ", join(", ", path.map(print, "extends"))]) + concat([ + line, + "extends ", + indent(join(concat([",", line]), path.map(print, "extends"))) + ]) ) ) ); diff --git a/tests/interface/__snapshots__/jsfmt.spec.js.snap b/tests/interface/__snapshots__/jsfmt.spec.js.snap index 2dcc03ce..810080a4 100644 --- a/tests/interface/__snapshots__/jsfmt.spec.js.snap +++ b/tests/interface/__snapshots__/jsfmt.spec.js.snap @@ -19,6 +19,52 @@ export class Environment2 extends GenericEnvironment< > { m() {}; }; + +// Declare Interface Break +declare interface ExtendsOne extends ASingleInterface { + x: string; +} + +declare interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +declare interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 { + x: string; +} + +// Interface declaration break +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 { + s: string; +} + +// Generic Types +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany + extends ASingleGenericInterface { + x: string; +} + +interface ExtendsManyWithGenerics + extends InterfaceOne, InterfaceTwo, ASingleGenericInterface, InterfaceThree { + + x: string; + } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ export interface Environment1 extends GenericEnvironment { @@ -36,6 +82,87 @@ export class Environment2 extends GenericEnvironment< m() {} } +// Declare Interface Break +declare interface ExtendsOne extends ASingleInterface { + x: string; +} + +declare interface ExtendsLarge + extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +declare interface ExtendsMany + extends Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 { + x: string; +} + +// Interface declaration break +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge + extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany + extends Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 { + s: string; +} + +// Generic Types +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge + extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany + extends ASingleGenericInterface< + Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 + > { + x: string; +} + +interface ExtendsManyWithGenerics + extends InterfaceOne, + InterfaceTwo, + ASingleGenericInterface< + Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 + >, + InterfaceThree { + x: string; +} + `; exports[`module.js - flow-verify 1`] = ` diff --git a/tests/interface/break.js b/tests/interface/break.js index 02e9e1e1..a7edf3d4 100644 --- a/tests/interface/break.js +++ b/tests/interface/break.js @@ -16,3 +16,49 @@ export class Environment2 extends GenericEnvironment< > { m() {}; }; + +// Declare Interface Break +declare interface ExtendsOne extends ASingleInterface { + x: string; +} + +declare interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +declare interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 { + x: string; +} + +// Interface declaration break +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 { + s: string; +} + +// Generic Types +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany + extends ASingleGenericInterface { + x: string; +} + +interface ExtendsManyWithGenerics + extends InterfaceOne, InterfaceTwo, ASingleGenericInterface, InterfaceThree { + + x: string; + }