aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-10-03 11:27:17 +0100
committerGitHub <noreply@github.com>2020-10-03 18:27:17 +0800
commit142bd1bd1a77c0893e7b88268ef1a4d4f1be13d0 (patch)
tree0597b1cbf48a89b518033903cae3e87e7edbb491 /lib/compress.js
parent8cb509d50e8bbc4c79d9bd0274a625f5ec37fe42 (diff)
downloadtracifyjs-142bd1bd1a77c0893e7b88268ef1a4d4f1be13d0.tar.gz
tracifyjs-142bd1bd1a77c0893e7b88268ef1a4d4f1be13d0.zip
workaround quirks on latter specs (#4172)
closes #4171
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 513528e7..a7e5eaca 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4851,8 +4851,8 @@ merge(Compressor.prototype, {
&& (old_def.name == def.name.name || all(old_def.references, function(ref) {
return ref.scope.find_variable(def.name) === def.name.definition();
})))
- && can_rename(def.value, def.name.name)
- && (!compressor.has_directive("use strict") || parent instanceof AST_Scope)) {
+ && can_declare_defun()
+ && can_rename(def.value, def.name.name)) {
AST_Node.warn("Declaring {name} as function [{file}:{line},{col}]", template(def.name));
var defun = make_node(AST_Defun, def, def.value);
defun.name = make_node(AST_SymbolDefun, def.name, def.name);
@@ -4908,6 +4908,13 @@ merge(Compressor.prototype, {
var def = fn.variables.get(name);
return !def || fn.name && def === fn.name.definition();
}
+
+ function can_declare_defun() {
+ if (compressor.has_directive("use strict")) return parent instanceof AST_Scope;
+ return parent instanceof AST_Block
+ || parent instanceof AST_For && parent.init === node
+ || parent instanceof AST_If;
+ }
});
switch (head.length) {
case 0: