From b730f4eccf07aea752550ba5b94572971daef9d5 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Wed, 7 Jun 2017 14:20:55 -0700 Subject: [PATCH] Add group around TSMethodSignature (#2037) This ensures that the comment size is not taken into account during measurement Fixes #1976 --- src/printer.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 13 +++++++++++++ tests/typescript_interface/comments.js | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/typescript_interface/comments.js diff --git a/src/printer.js b/src/printer.js index 21f9ec220..13757260d 100644 --- a/src/printer.js +++ b/src/printer.js @@ -2453,7 +2453,7 @@ function genericPrintNoParens(path, options, print, args) { if (n.typeAnnotation) { parts.push(": ", path.call(print, "typeAnnotation")); } - return concat(parts); + return group(concat(parts)); case "TSNamespaceExportDeclaration": if (n.declaration) { // Temporary fix until https://github.com/eslint/typescript-eslint-parser/issues/263 diff --git a/tests/typescript_interface/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_interface/__snapshots__/jsfmt.spec.js.snap index e6c2d8ae8..b20f63d18 100644 --- a/tests/typescript_interface/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_interface/__snapshots__/jsfmt.spec.js.snap @@ -9,6 +9,19 @@ abstract interface I {} `; +exports[`comments.js 1`] = ` +interface ScreenObject { + // I make things weird. + at(point: Point): Screen | undefined; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +interface ScreenObject { + // I make things weird. + at(point: Point): Screen | undefined; +} + +`; + exports[`separator.ts 1`] = ` declare module 'selenium-webdriver' { export const until: { diff --git a/tests/typescript_interface/comments.js b/tests/typescript_interface/comments.js new file mode 100644 index 000000000..513e607bd --- /dev/null +++ b/tests/typescript_interface/comments.js @@ -0,0 +1,4 @@ +interface ScreenObject { + // I make things weird. + at(point: Point): Screen | undefined; +}