TypeScript: keep parens around with yield/await non-null assertion, fixes #2137 (#2149)

This commit is contained in:
Lucas Azzola authored and GitHub committed 2017-06-15 09:34:12 +10:00
1 parent 3726067923
commit a2328edced
3 files changed
+27 -1

No files matched your search

+3 -1
View File
@@ -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":
@@ -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())!;
}
`;
+8
View File
@@ -1,2 +1,10 @@
(a ? b : c) ![tokenKey];
(a || b) ![tokenKey];
async function f() {
return (await foo())!;
}
function* g() {
return (yield * foo())!;
}