fix block-scoped function for ES6

fixes #1903
This commit is contained in:
alexlamsl
2017-05-27 19:13:09 +08:00
parent aa835eb0f6
commit 94d2aeee89
4 changed files with 23 additions and 17 deletions

View File

@@ -1249,7 +1249,14 @@ merge(Compressor.prototype, {
return true;
}
if (node instanceof AST_Defun && (node === stat || !compressor.has_directive("use strict"))) {
target.push(node);
target.push(node === stat ? node : make_node(AST_Var, node, {
definitions: [
make_node(AST_VarDef, node, {
name: make_node(AST_SymbolVar, node.name, node.name),
value: null
})
]
}));
return true;
}
if (node instanceof AST_Scope) {
@@ -2388,7 +2395,7 @@ merge(Compressor.prototype, {
}
if (hoist_funs && node instanceof AST_Defun
&& !(tt.parent() instanceof AST_Export)
&& (tt.parent() === self || !compressor.has_directive("use strict"))) {
&& tt.parent() === self) {
hoisted.push(node);
return make_node(AST_EmptyStatement, node);
}