Do not put parenthesis around not named default export (#819)

We need to add parenthesis around function expressions if they are named otherwise the name leak, but if the function is not named then it's just superfluous.

The conditional change is due to a bad use of switch case where it would fall through the next one. We don't want parenthesis there.
master
Christopher Chedeau 2017-02-27 13:46:17 -08:00 committed by James Long
parent 443a5d6d66
commit 08b8a5f2e7
3 changed files with 18 additions and 11 deletions

View File

@ -451,9 +451,16 @@ FPp.needsParens = function(assumeExpressionContext) {
if (parent.test === node) {
return true;
}
return false;
case "ExportDefaultDeclaration":
return node.type !== "ArrowFunctionExpression";
if (node.type === "ArrowFunctionExpression") {
return false;
}
if (node.type === "FunctionExpression" && !node.id) {
return false;
}
return true;
case "ExpressionStatement":
case "MemberExpression":

View File

@ -41,23 +41,23 @@ const { configureStore } = process.env.NODE_ENV === \\"production\\"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var inspect = 4 === util.inspect.length
? // node <= 0.8.x
(function(v, colors) {
function(v, colors) {
return util.inspect(v, void 0, void 0, colors);
})
}
: // node > 0.8.x
(function(v, colors) {
function(v, colors) {
return util.inspect(v, { colors: colors });
});
};
var inspect = 4 === util.inspect.length
? // node <= 0.8.x
(function(v, colors) {
function(v, colors) {
return util.inspect(v, void 0, void 0, colors);
})
}
: // node > 0.8.x
(function(v, colors) {
function(v, colors) {
return util.inspect(v, { colors: colors });
});
};
const extractTextPluginOptions = shouldUseRelativeAssetPaths
? // Making sure that the publicPath goes back to to build folder.

View File

@ -101,14 +101,14 @@ export default function f() {}
exports[`export_default_function_expression.js 1`] = `
"export default (function() {});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export default (function() {});
export default function() {};
"
`;
exports[`export_default_function_expression.js 2`] = `
"export default (function() {});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export default (function() {});
export default function() {};
"
`;