|
|
@ -16,8 +16,9 @@ use crate::{ |
|
|
|
FunctionExpression, GeneratorDeclaration, GeneratorExpression, |
|
|
|
FunctionExpression, GeneratorDeclaration, GeneratorExpression, |
|
|
|
}, |
|
|
|
}, |
|
|
|
operations::{ |
|
|
|
operations::{ |
|
|
|
bound_names, lexically_declared_names, lexically_scoped_declarations, var_declared_names, |
|
|
|
bound_names, contains, lexically_declared_names, lexically_scoped_declarations, |
|
|
|
var_scoped_declarations, LexicallyScopedDeclaration, VarScopedDeclaration, |
|
|
|
var_declared_names, var_scoped_declarations, ContainsSymbol, LexicallyScopedDeclaration, |
|
|
|
|
|
|
|
VarScopedDeclaration, |
|
|
|
}, |
|
|
|
}, |
|
|
|
property::PropertyName, |
|
|
|
property::PropertyName, |
|
|
|
scope::{FunctionScopes, IdentifierReference, Scope}, |
|
|
|
scope::{FunctionScopes, IdentifierReference, Scope}, |
|
|
@ -1171,11 +1172,14 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
node: &'ast mut FunctionDeclaration, |
|
|
|
node: &'ast mut FunctionDeclaration, |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
self.visit_function_like( |
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut None, |
|
|
|
&mut None, |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1183,11 +1187,14 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
node: &'ast mut GeneratorDeclaration, |
|
|
|
node: &'ast mut GeneratorDeclaration, |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
self.visit_function_like( |
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut None, |
|
|
|
&mut None, |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1195,11 +1202,14 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
node: &'ast mut AsyncFunctionDeclaration, |
|
|
|
node: &'ast mut AsyncFunctionDeclaration, |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
self.visit_function_like( |
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut None, |
|
|
|
&mut None, |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1207,11 +1217,14 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
node: &'ast mut AsyncGeneratorDeclaration, |
|
|
|
node: &'ast mut AsyncGeneratorDeclaration, |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
self.visit_function_like( |
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut None, |
|
|
|
&mut None, |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1219,11 +1232,14 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
node: &'ast mut FunctionExpression, |
|
|
|
node: &'ast mut FunctionExpression, |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
self.visit_function_like( |
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.name_scope, |
|
|
|
&mut node.name_scope, |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1231,11 +1247,14 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
node: &'ast mut GeneratorExpression, |
|
|
|
node: &'ast mut GeneratorExpression, |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
self.visit_function_like( |
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.name_scope, |
|
|
|
&mut node.name_scope, |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1243,11 +1262,14 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
node: &'ast mut AsyncFunctionExpression, |
|
|
|
node: &'ast mut AsyncFunctionExpression, |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
self.visit_function_like( |
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.name_scope, |
|
|
|
&mut node.name_scope, |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1255,11 +1277,14 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
node: &'ast mut AsyncGeneratorExpression, |
|
|
|
node: &'ast mut AsyncGeneratorExpression, |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
self.visit_function_like( |
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.name_scope, |
|
|
|
&mut node.name_scope, |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1267,11 +1292,14 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
node: &'ast mut ArrowFunction, |
|
|
|
node: &'ast mut ArrowFunction, |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
self.visit_function_like( |
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut None, |
|
|
|
&mut None, |
|
|
|
|
|
|
|
true, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1279,11 +1307,14 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
node: &'ast mut AsyncArrowFunction, |
|
|
|
node: &'ast mut AsyncArrowFunction, |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
self.visit_function_like( |
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut None, |
|
|
|
&mut None, |
|
|
|
|
|
|
|
true, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1338,12 +1369,17 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
node: &'ast mut ClassElement, |
|
|
|
node: &'ast mut ClassElement, |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
) -> ControlFlow<Self::BreakTy> { |
|
|
|
match node { |
|
|
|
match node { |
|
|
|
ClassElement::MethodDefinition(node) => self.visit_function_like( |
|
|
|
ClassElement::MethodDefinition(node) => { |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
|
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut None, |
|
|
|
&mut None, |
|
|
|
), |
|
|
|
false, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
ClassElement::FieldDefinition(field) | ClassElement::StaticFieldDefinition(field) => { |
|
|
|
ClassElement::FieldDefinition(field) | ClassElement::StaticFieldDefinition(field) => { |
|
|
|
try_break!(self.visit_property_name_mut(&mut field.name)); |
|
|
|
try_break!(self.visit_property_name_mut(&mut field.name)); |
|
|
|
let index = self.index; |
|
|
|
let index = self.index; |
|
|
@ -1371,12 +1407,17 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
} |
|
|
|
} |
|
|
|
ControlFlow::Continue(()) |
|
|
|
ControlFlow::Continue(()) |
|
|
|
} |
|
|
|
} |
|
|
|
ClassElement::StaticBlock(node) => self.visit_function_like( |
|
|
|
ClassElement::StaticBlock(node) => { |
|
|
|
|
|
|
|
let contains_direct_eval = contains(node.statements(), ContainsSymbol::DirectEval); |
|
|
|
|
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut FormalParameterList::default(), |
|
|
|
&mut FormalParameterList::default(), |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut None, |
|
|
|
&mut None, |
|
|
|
), |
|
|
|
false, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1390,11 +1431,14 @@ impl<'ast> VisitorMut<'ast> for ScopeIndexVisitor { |
|
|
|
try_break!(self.visit_expression_mut(name)); |
|
|
|
try_break!(self.visit_expression_mut(name)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let contains_direct_eval = node.contains_direct_eval(); |
|
|
|
self.visit_function_like( |
|
|
|
self.visit_function_like( |
|
|
|
&mut node.body, |
|
|
|
&mut node.body, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.parameters, |
|
|
|
&mut node.scopes, |
|
|
|
&mut node.scopes, |
|
|
|
&mut None, |
|
|
|
&mut None, |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
contains_direct_eval, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1531,6 +1575,8 @@ impl ScopeIndexVisitor { |
|
|
|
parameters: &mut FormalParameterList, |
|
|
|
parameters: &mut FormalParameterList, |
|
|
|
scopes: &mut FunctionScopes, |
|
|
|
scopes: &mut FunctionScopes, |
|
|
|
name_scope: &mut Option<Scope>, |
|
|
|
name_scope: &mut Option<Scope>, |
|
|
|
|
|
|
|
arrow: bool, |
|
|
|
|
|
|
|
contains_direct_eval: bool, |
|
|
|
) -> ControlFlow<()> { |
|
|
|
) -> ControlFlow<()> { |
|
|
|
let index = self.index; |
|
|
|
let index = self.index; |
|
|
|
if let Some(scope) = name_scope { |
|
|
|
if let Some(scope) = name_scope { |
|
|
@ -1539,7 +1585,9 @@ impl ScopeIndexVisitor { |
|
|
|
} |
|
|
|
} |
|
|
|
scope.set_index(self.index); |
|
|
|
scope.set_index(self.index); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if !(arrow && scopes.function_scope.all_bindings_local() && !contains_direct_eval) { |
|
|
|
self.index += 1; |
|
|
|
self.index += 1; |
|
|
|
|
|
|
|
} |
|
|
|
scopes.function_scope.set_index(self.index); |
|
|
|
scopes.function_scope.set_index(self.index); |
|
|
|
if let Some(scope) = &scopes.parameters_eval_scope { |
|
|
|
if let Some(scope) = &scopes.parameters_eval_scope { |
|
|
|
if !scope.all_bindings_local() { |
|
|
|
if !scope.all_bindings_local() { |
|
|
|