diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-29 16:22:03 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-30 00:22:03 +0800 |
commit | 1956edd503bde9db8e99d8a499d54d5a508f8bb8 (patch) | |
tree | 32b1f05ad7820a1070639ef78ae5caf4fcfd0ac9 /lib/scope.js | |
parent | 560ccc1221639dca9db354ad6830e418a9f0073d (diff) | |
download | tracifyjs-1956edd503bde9db8e99d8a499d54d5a508f8bb8.tar.gz tracifyjs-1956edd503bde9db8e99d8a499d54d5a508f8bb8.zip |
fix corner cases with `arguments` (#4481)
fixes #4480
Diffstat (limited to 'lib/scope.js')
-rw-r--r-- | lib/scope.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/scope.js b/lib/scope.js index 0c35b0dd..4660c787 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -265,10 +265,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) { } if (!sym) { sym = self.def_global(node); - } else if (name == "arguments" - && sym.orig[0] instanceof AST_SymbolFunarg - && !(sym.orig[1] instanceof AST_SymbolFunarg) - && !(sym.scope instanceof AST_Arrow)) { + } 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]) { @@ -297,6 +294,13 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) { node.reference(options); return true; } + if (node instanceof AST_VarDef) { + if (node.value && node.name.name == "arguments") { + var sym = node.name.scope.resolve().find_variable("arguments"); + if (sym && is_arguments(sym)) sym.scope.uses_arguments = 3; + } + return; + } }); self.walk(tw); @@ -322,6 +326,12 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) { } })); + function is_arguments(sym) { + return sym.orig[0] instanceof AST_SymbolFunarg + && !(sym.orig[1] instanceof AST_SymbolFunarg || sym.orig[2] instanceof AST_SymbolFunarg) + && !(sym.scope instanceof AST_Arrow); + } + function redefine(node, scope) { var name = node.name; var old_def = node.thedef; |