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

master
Lucas Azzola 2017-06-15 09:34:12 +10:00 committed by GitHub
parent 3726067923
commit a2328edced
3 changed files with 27 additions and 1 deletions

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":

View File

@ -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())!;
}
`;

View File

@ -1,2 +1,10 @@
(a ? b : c) ![tokenKey];
(a || b) ![tokenKey];
async function f() {
return (await foo())!;
}
function* g() {
return (yield * foo())!;
}