aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 3f9678a7..22f4736a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6562,10 +6562,25 @@ merge(Compressor.prototype, {
if (def.orig.length > 1) return null;
if (def.assignments > 0) return false;
if (def.name == name) return def;
- if (name == "await" && is_async(fn)) return false;
- if (name == "yield" && is_generator(fn)) return false;
+ var forbidden;
+ switch (name) {
+ case "await":
+ forbidden = is_async;
+ break;
+ case "yield":
+ forbidden = is_generator;
+ break;
+ }
return all(def.references, function(ref) {
- return ref.scope.find_variable(name) === sym;
+ var scope = ref.scope;
+ if (scope.find_variable(name) !== sym) return false;
+ if (forbidden) {
+ scope = scope.resolve();
+ do {
+ if (forbidden(scope)) return false;
+ } while ((scope = scope.parent_scope.resolve()) && scope !== fn);
+ }
+ return true;
}) && def;
}