aboutsummaryrefslogtreecommitdiff
path: root/lib/scope.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-02-02 15:07:31 +0000
committerGitHub <noreply@github.com>2021-02-02 23:07:31 +0800
commit3c556b8689346f8256781455c0e1b2f00975570f (patch)
tree0083da4d3d5e4d574313764e17032940d91eef10 /lib/scope.js
parent7110c6923b8ef82f295f5d9ff9d42d2f88432810 (diff)
downloadtracifyjs-3c556b8689346f8256781455c0e1b2f00975570f.tar.gz
tracifyjs-3c556b8689346f8256781455c0e1b2f00975570f.zip
fix corner case in `arguments` (#4609)
fixes #4608
Diffstat (limited to 'lib/scope.js')
-rw-r--r--lib/scope.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/scope.js b/lib/scope.js
index a241cc59..5f10e33d 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -101,6 +101,14 @@ SymbolDef.prototype = {
var unary_side_effects = makePredicate("delete ++ --");
+function is_lhs(node, parent) {
+ if (parent instanceof AST_Assign) return parent.left === node && node;
+ if (parent instanceof AST_DefaultValue) return parent.name === node && node;
+ if (parent instanceof AST_Destructured) return node;
+ if (parent instanceof AST_DestructuredKeyVal) return node;
+ if (parent instanceof AST_Unary) return unary_side_effects[parent.operator] && parent.expression;
+}
+
AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
options = defaults(options, {
cache: null,
@@ -269,8 +277,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
sym = self.def_global(node);
} else if (name == "arguments" && is_arguments(sym)) {
var parent = tw.parent();
- if (parent instanceof AST_Assign && parent.left === node
- || parent instanceof AST_Unary && unary_side_effects[parent.operator]) {
+ if (is_lhs(node, parent)) {
sym.scope.uses_arguments = 3;
} else if (sym.scope.uses_arguments < 2
&& !(parent instanceof AST_PropAccess && parent.expression === node)) {