Fix various parenthesis issues on the left side of template (#404)
parent
e45a9b0582
commit
2f220de204
|
@ -241,6 +241,7 @@ FPp.needsParens = function(assumeExpressionContext) {
|
|||
case "MemberExpression":
|
||||
return name === "object" && parent.object === node;
|
||||
|
||||
case "TaggedTemplateExpression":
|
||||
case "CallExpression":
|
||||
case "NewExpression":
|
||||
return true;
|
||||
|
@ -272,6 +273,7 @@ FPp.needsParens = function(assumeExpressionContext) {
|
|||
case "NewExpression":
|
||||
return name === "callee" && parent.callee === node;
|
||||
|
||||
case "TaggedTemplateExpression":
|
||||
case "UnaryExpression":
|
||||
case "SpreadElement":
|
||||
case "SpreadProperty":
|
||||
|
@ -324,6 +326,7 @@ FPp.needsParens = function(assumeExpressionContext) {
|
|||
case "AwaitExpression":
|
||||
case "YieldExpression":
|
||||
switch (parent.type) {
|
||||
case "TaggedTemplateExpression":
|
||||
case "BinaryExpression":
|
||||
case "LogicalExpression":
|
||||
case "UnaryExpression":
|
||||
|
@ -366,11 +369,13 @@ FPp.needsParens = function(assumeExpressionContext) {
|
|||
case "AssignmentExpression":
|
||||
case "ConditionalExpression":
|
||||
switch (parent.type) {
|
||||
case "TaggedTemplateExpression":
|
||||
case "UnaryExpression":
|
||||
case "SpreadElement":
|
||||
case "SpreadProperty":
|
||||
case "BinaryExpression":
|
||||
case "LogicalExpression":
|
||||
case "LogicalExpression":
|
||||
case "NewExpression":
|
||||
return true;
|
||||
|
||||
|
@ -415,6 +420,7 @@ FPp.needsParens = function(assumeExpressionContext) {
|
|||
|
||||
case "ClassExpression":
|
||||
switch (parent.type) {
|
||||
case "TaggedTemplateExpression":
|
||||
case "BinaryExpression":
|
||||
case "ExportDefaultDeclaration":
|
||||
case "ExpressionStatement":
|
||||
|
|
|
@ -31,6 +31,121 @@ var x = {
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`test parenthesis.js 1`] = `
|
||||
"// \"ArrowFunctionExpression\"
|
||||
(() => {})\`\`;
|
||||
|
||||
// \"AssignmentExpression\"
|
||||
(b = c)\`\`;
|
||||
|
||||
// \"AwaitExpression\"
|
||||
async function f() {
|
||||
(await b)\`\`;
|
||||
}
|
||||
|
||||
// \"BinaryExpression\"
|
||||
(b + c)\`\`;
|
||||
|
||||
// \"CallExpression\"
|
||||
b()\`\`;
|
||||
|
||||
// \"ClassExpression\"
|
||||
(class {})\`\`;
|
||||
|
||||
// \"ConditionalExpression\"
|
||||
(b ? c : d)\`\`;
|
||||
|
||||
// \"FunctionExpression\"
|
||||
(function() {})\`\`;
|
||||
|
||||
// \"LogicalExpression\"
|
||||
(b || c)\`\`;
|
||||
|
||||
// \"MemberExpression\"
|
||||
b.c\`\`;
|
||||
|
||||
// \"NewExpression\"
|
||||
(new B())\`\`;
|
||||
|
||||
// \"ObjectExpression\"
|
||||
({})\`\`;
|
||||
|
||||
// \"SequenceExpression\"
|
||||
(b, c)\`\`;
|
||||
|
||||
// \"TaggedTemplateExpression\"
|
||||
(\`\`)\`\`;
|
||||
|
||||
// \"UnaryExpression\"
|
||||
(void b)\`\`;
|
||||
|
||||
// \"UpdateExpression\"
|
||||
(++b)\`\`;
|
||||
|
||||
// \"YieldExpression\"
|
||||
function* f() {
|
||||
(yield 1)\`\`;
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// \"ArrowFunctionExpression\"
|
||||
(() => {
|
||||
})\`\`;
|
||||
|
||||
// \"AssignmentExpression\"
|
||||
(b = c)\`\`;
|
||||
|
||||
// \"AwaitExpression\"
|
||||
async function f() {
|
||||
(await b)\`\`;
|
||||
}
|
||||
|
||||
// \"BinaryExpression\"
|
||||
(b + c)\`\`;
|
||||
|
||||
// \"CallExpression\"
|
||||
b()\`\`;
|
||||
|
||||
// \"ClassExpression\"
|
||||
(class {})\`\`;
|
||||
|
||||
// \"ConditionalExpression\"
|
||||
(b ? c : d)\`\`;
|
||||
|
||||
// \"FunctionExpression\"
|
||||
(function() {
|
||||
})\`\`;
|
||||
|
||||
// \"LogicalExpression\"
|
||||
(b || c)\`\`;
|
||||
|
||||
// \"MemberExpression\"
|
||||
b.c\`\`;
|
||||
|
||||
// \"NewExpression\"
|
||||
new B()\`\`;
|
||||
|
||||
// \"ObjectExpression\"
|
||||
({})\`\`;
|
||||
|
||||
// \"SequenceExpression\"
|
||||
(b, c)\`\`;
|
||||
|
||||
// \"TaggedTemplateExpression\"
|
||||
\`\`\`\`;
|
||||
|
||||
// \"UnaryExpression\"
|
||||
(void b)\`\`;
|
||||
|
||||
// \"UpdateExpression\"
|
||||
(++b)\`\`;
|
||||
|
||||
// \"YieldExpression\"
|
||||
function* f() {
|
||||
(yield 1)\`\`;
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`test template.js 1`] = `
|
||||
"/* @flow */
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
// "ArrowFunctionExpression"
|
||||
(() => {})``;
|
||||
|
||||
// "AssignmentExpression"
|
||||
(b = c)``;
|
||||
|
||||
// "AwaitExpression"
|
||||
async function f() {
|
||||
(await b)``;
|
||||
}
|
||||
|
||||
// "BinaryExpression"
|
||||
(b + c)``;
|
||||
|
||||
// "CallExpression"
|
||||
b()``;
|
||||
|
||||
// "ClassExpression"
|
||||
(class {})``;
|
||||
|
||||
// "ConditionalExpression"
|
||||
(b ? c : d)``;
|
||||
|
||||
// "FunctionExpression"
|
||||
(function() {})``;
|
||||
|
||||
// "LogicalExpression"
|
||||
(b || c)``;
|
||||
|
||||
// "MemberExpression"
|
||||
b.c``;
|
||||
|
||||
// "NewExpression"
|
||||
(new B())``;
|
||||
|
||||
// "ObjectExpression"
|
||||
({})``;
|
||||
|
||||
// "SequenceExpression"
|
||||
(b, c)``;
|
||||
|
||||
// "TaggedTemplateExpression"
|
||||
(``)``;
|
||||
|
||||
// "UnaryExpression"
|
||||
(void b)``;
|
||||
|
||||
// "UpdateExpression"
|
||||
(++b)``;
|
||||
|
||||
// "YieldExpression"
|
||||
function* f() {
|
||||
(yield 1)``;
|
||||
}
|
Loading…
Reference in New Issue