Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing parens when function expressions is tag #5193

Merged
merged 2 commits into from Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 12 additions & 10 deletions packages/babel-generator/src/node/parentheses.js
Expand Up @@ -170,16 +170,14 @@ export function FunctionExpression(node: Object, parent: Object, printStack: Arr
}

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

if (t.isBinaryExpression(parent) || t.isLogicalExpression(parent)) {
return true;
}

if (t.isUnaryExpression(parent)) {
if (
// export default (function () {});
t.isExportDeclaration(parent) ||
t.isBinaryExpression(parent) ||
t.isLogicalExpression(parent) ||
t.isUnaryExpression(parent) ||
t.isTaggedTemplateExpression(parent)
) {
return true;
}

Expand Down Expand Up @@ -225,6 +223,10 @@ function isFirstInStatement(printStack: Array<Object>, {
return true;
}

if (t.isTaggedTemplateExpression(parent)) {
return true;
}

if (considerDefaultExports && t.isExportDefaultDeclaration(parent, { declaration: node })) {
return true;
}
Expand Down
@@ -0,0 +1,2 @@
(() => {})``;
(function(){}``);
@@ -0,0 +1,2 @@
(() => {})``;
(function () {})``;