diff --git a/src/printer.js b/src/printer.js index fe7b38c0b6f0..9addf5adc636 100644 --- a/src/printer.js +++ b/src/printer.js @@ -403,7 +403,8 @@ function genericPrintNoParens(path, options, print, args) { i++; } while ( firstNonMemberParent && - firstNonMemberParent.type === "MemberExpression" + (firstNonMemberParent.type === "MemberExpression" || + firstNonMemberParent.type === "TSNonNullExpression") ); const shouldInline = diff --git a/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap index 6a27e7ebe26c..530b94771074 100644 --- a/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,22 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`member-chain.js 1`] = ` +const { somePropThatHasAReallyLongName, anotherPropThatHasALongName } = this.props.imReallySureAboutThis!; + +const { somePropThatHasAReallyLongName, anotherPropThatHasALongName } = this.props.imReallySureAboutThis!.anotherObject; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const { + somePropThatHasAReallyLongName, + anotherPropThatHasALongName +} = this.props.imReallySureAboutThis!; + +const { + somePropThatHasAReallyLongName, + anotherPropThatHasALongName +} = this.props.imReallySureAboutThis!.anotherObject; + +`; + exports[`parens.ts 1`] = ` (a ? b : c) ![tokenKey]; (a || b) ![tokenKey]; diff --git a/tests/typescript_non_null/member-chain.js b/tests/typescript_non_null/member-chain.js new file mode 100644 index 000000000000..8d8e5a14c292 --- /dev/null +++ b/tests/typescript_non_null/member-chain.js @@ -0,0 +1,3 @@ +const { somePropThatHasAReallyLongName, anotherPropThatHasALongName } = this.props.imReallySureAboutThis!; + +const { somePropThatHasAReallyLongName, anotherPropThatHasALongName } = this.props.imReallySureAboutThis!.anotherObject;