fix corner cases with export (#4699)

fixes #4698
fixes #4700
fixes #4701
fixes #4702
This commit is contained in:
Alex Lam S.L
2021-02-27 02:15:14 +00:00
committed by GitHub
parent 0a42457df6
commit e6ebf827ce
4 changed files with 32 additions and 8 deletions

View File

@@ -662,12 +662,15 @@ function OutputStream(options) {
// a function expression needs parens around it when it's provably
// the first token to appear in a statement.
function needs_parens_function(output) {
if (!output.has_parens() && first_in_statement(output)) return true;
var p = output.parent();
// export default (function foo() {});
if (this.name && p instanceof AST_ExportDefault) return true;
// export default (function() {})(foo);
if (p && p.TYPE == "Call" && output.parent(1) instanceof AST_ExportDefault) return true;
if (!output.has_parens() && first_in_statement(output, false, true)) {
// export default function() {}
// export default (function foo() {});
// export default (function() {})(foo);
// export default (function() {})`foo`;
// export default (function() {}) ? foo : bar;
return this.name || !(p instanceof AST_ExportDefault);
}
if (output.option("webkit") && p instanceof AST_PropAccess && p.expression === this) return true;
if (output.option("wrap_iife") && p instanceof AST_Call && p.expression === this) return true;
}