diff --git a/src/fast-path.js b/src/fast-path.js index fd41810da..c734de4d1 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -385,7 +385,8 @@ FastPath.prototype.needsParens = function(options) { if ( parent.type === "UnaryExpression" || parent.type === "AwaitExpression" || - parent.type === "TSAsExpression" + parent.type === "TSAsExpression" || + parent.type === "TSNonNullExpression" ) { return true; } @@ -398,6 +399,7 @@ FastPath.prototype.needsParens = function(options) { case "SpreadElement": case "SpreadProperty": case "TSAsExpression": + case "TSNonNullExpression": return true; case "MemberExpression": diff --git a/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap index b59005148..6a27e7ebe 100644 --- a/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap @@ -3,8 +3,24 @@ exports[`parens.ts 1`] = ` (a ? b : c) ![tokenKey]; (a || b) ![tokenKey]; + +async function f() { + return (await foo())!; +} + +function* g() { + return (yield * foo())!; +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (a ? b : c)![tokenKey]; (a || b)![tokenKey]; +async function f() { + return (await foo())!; +} + +function* g() { + return (yield* foo())!; +} + `; diff --git a/tests/typescript_non_null/parens.ts b/tests/typescript_non_null/parens.ts index 2f72c1104..24d3d1087 100644 --- a/tests/typescript_non_null/parens.ts +++ b/tests/typescript_non_null/parens.ts @@ -1,2 +1,10 @@ (a ? b : c) ![tokenKey]; (a || b) ![tokenKey]; + +async function f() { + return (await foo())!; +} + +function* g() { + return (yield * foo())!; +}