Skip to content

Commit

Permalink
Fix missing parens when function expressions is tag
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism committed Jan 23, 2017
1 parent d76092b commit 74b9375
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/babel-generator/src/node/parentheses.js
Expand Up @@ -166,20 +166,22 @@ export function UnaryLike(node: Object, parent: Object): boolean {
}

export function FunctionExpression(node: Object, parent: Object, printStack: Array<Object>): boolean {
return isFirstInStatement(printStack, { considerDefaultExports: true });
}

export function ArrowFunctionExpression(node: Object, parent: Object): boolean {
// export default (function () {});
if (t.isExportDeclaration(parent)) {
if (t.isTaggedTemplateExpression(parent)) {
return true;
}

if (t.isBinaryExpression(parent) || t.isLogicalExpression(parent)) {
return true;
}
return isFirstInStatement(printStack, { considerDefaultExports: true });
}

if (t.isUnaryExpression(parent)) {
export function ArrowFunctionExpression(node: Object, parent: Object): boolean {
if (
// export default (function () {});
t.isExportDeclaration(parent) ||
t.isBinaryExpression(parent) ||
t.isLogicalExpression(parent) ||
t.isUnaryExpression(parent) ||
t.isTaggedTemplateExpression(parent)
) {
return true;
}

Expand Down
@@ -0,0 +1,2 @@
(() => {})``;
(function() {})``;
@@ -0,0 +1,2 @@
(() => {})``;
(function () {})``;

0 comments on commit 74b9375

Please sign in to comment.