parenthesise exported iifes correctly

This commit is contained in:
Fábio Santos 2018-03-07 20:50:01 +00:00
parent 569757d14d
commit 402bbda1d1
3 changed files with 22 additions and 1 deletions

View File

@ -1106,6 +1106,20 @@ function OutputStream(options) {
self._do_print(output);
});
DEFPRINT(AST_Function, function(self, output) {
var parent = output.parent();
var grandparent = output.parent(1);
var is_exported_iife = parent instanceof AST_Call && parent.expression == self &&
grandparent instanceof AST_Export && grandparent.is_default;
if (is_exported_iife) {
output.with_parens(function() {
self._do_print(output);
});
} else {
self._do_print(output);
}
});
DEFPRINT(AST_PrefixedTemplateString, function(self, output) {
self.prefix.print(output);
self.template_string.print(output);

View File

@ -410,7 +410,7 @@ export_default_anonymous_function_not_call: {
export default function(){}(foo);
}
// FIXME: should be `export default function(){};foo;`
expect_exact: "export default function(){}(foo);"
expect_exact: "export default(function(){})(foo);"
}
export_default_anonymous_generator_not_call: {

View File

@ -0,0 +1,7 @@
issue_2977: {
input: {
export default (function () {})();
}
expect_exact: "export default(function(){})();"
}