diff --git a/boa_engine/src/bytecompiler/mod.rs b/boa_engine/src/bytecompiler/mod.rs index 5399f80cfcf..56e05adb23a 100644 --- a/boa_engine/src/bytecompiler/mod.rs +++ b/boa_engine/src/bytecompiler/mod.rs @@ -1259,7 +1259,7 @@ impl<'b> ByteCompiler<'b> { Expression::This => { self.access_get(Access::This, use_expr)?; } - Expression::Spread(spread) => self.compile_expr(spread.val(), true)?, + Expression::Spread(spread) => self.compile_expr(spread.target(), true)?, Expression::Function(function) => { self.function(function.into(), NodeKind::Expression, use_expr)?; } @@ -1299,7 +1299,7 @@ impl<'b> ByteCompiler<'b> { } } Expression::Await(expr) => { - self.compile_expr(expr.expr(), true)?; + self.compile_expr(expr.target(), true)?; self.emit_opcode(Opcode::Await); self.emit_opcode(Opcode::GeneratorNext); if !use_expr { @@ -1307,7 +1307,7 @@ impl<'b> ByteCompiler<'b> { } } Expression::Yield(r#yield) => { - if let Some(expr) = r#yield.expr() { + if let Some(expr) = r#yield.target() { self.compile_expr(expr, true)?; } else { self.emit_opcode(Opcode::PushUndefined); @@ -1616,9 +1616,9 @@ impl<'b> ByteCompiler<'b> { for_in_loop: &ForInLoop, label: Option, ) -> JsResult<()> { - let init_bound_names = for_in_loop.init().bound_names(); + let init_bound_names = for_in_loop.initializer().bound_names(); if init_bound_names.is_empty() { - self.compile_expr(for_in_loop.expr(), true)?; + self.compile_expr(for_in_loop.target(), true)?; } else { self.context.push_compile_time_environment(false); let push_env = self.emit_opcode_with_two_operands(Opcode::PushDeclarativeEnvironment); @@ -1626,7 +1626,7 @@ impl<'b> ByteCompiler<'b> { for name in init_bound_names { self.context.create_mutable_binding(name, false); } - self.compile_expr(for_in_loop.expr(), true)?; + self.compile_expr(for_in_loop.target(), true)?; let (num_bindings, compile_environment) = self.context.pop_compile_time_environment(); let index_compile_environment = self.push_compile_environment(compile_environment); @@ -1646,7 +1646,7 @@ impl<'b> ByteCompiler<'b> { let push_env = self.emit_opcode_with_two_operands(Opcode::PushDeclarativeEnvironment); let exit = self.emit_opcode_with_operand(Opcode::ForInLoopNext); - match for_in_loop.init() { + match for_in_loop.initializer() { IterableLoopInitializer::Identifier(ident) => { self.context.create_mutable_binding(*ident, true); let binding = self.context.set_mutable_binding(*ident); @@ -2106,7 +2106,7 @@ impl<'b> ByteCompiler<'b> { } } Statement::Throw(throw) => { - self.compile_expr(throw.expr(), true)?; + self.compile_expr(throw.target(), true)?; self.emit(Opcode::Throw, &[]); } Statement::Switch(switch) => { @@ -2153,7 +2153,7 @@ impl<'b> ByteCompiler<'b> { self.emit_opcode(Opcode::PopEnvironment); } Statement::Return(ret) => { - if let Some(expr) = ret.expr() { + if let Some(expr) = ret.target() { self.compile_expr(expr, true)?; } else { self.emit(Opcode::PushUndefined, &[]); @@ -2336,14 +2336,14 @@ impl<'b> ByteCompiler<'b> { } let (call, kind) = match callable { - Callable::Call(call) => match call.expr() { + Callable::Call(call) => match call.function() { Expression::Identifier(ident) if *ident == Sym::EVAL => (call, CallKind::CallEval), _ => (call, CallKind::Call), }, Callable::New(new) => (new.call(), CallKind::New), }; - match call.expr() { + match call.function() { Expression::PropertyAccess(access) => { self.compile_expr(access.target(), true)?; if kind == CallKind::Call { diff --git a/boa_engine/src/syntax/ast/expression/await.rs b/boa_engine/src/syntax/ast/expression/await.rs index 0aae6a926ed..035b84533fe 100644 --- a/boa_engine/src/syntax/ast/expression/await.rs +++ b/boa_engine/src/syntax/ast/expression/await.rs @@ -17,24 +17,24 @@ use boa_interner::{Interner, ToIndentedString, ToInternedString}; #[cfg_attr(feature = "deser", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq)] pub struct Await { - expr: Box, + target: Box, } impl Await { - /// Return the expression that should be awaited. + /// Return the target expression that should be awaited. #[inline] - pub(crate) fn expr(&self) -> &Expression { - &self.expr + pub(crate) fn target(&self) -> &Expression { + &self.target } #[inline] pub(crate) fn contains_arguments(&self) -> bool { - self.expr.contains_arguments() + self.target.contains_arguments() } #[inline] pub(crate) fn contains(&self, symbol: ContainsSymbol) -> bool { - self.expr.contains(symbol) + self.target.contains(symbol) } } @@ -44,14 +44,14 @@ where { #[inline] fn from(e: T) -> Self { - Self { expr: e.into() } + Self { target: e.into() } } } impl ToInternedString for Await { #[inline] fn to_interned_string(&self, interner: &Interner) -> String { - format!("await {}", self.expr.to_indented_string(interner, 0)) + format!("await {}", self.target.to_indented_string(interner, 0)) } } diff --git a/boa_engine/src/syntax/ast/expression/call.rs b/boa_engine/src/syntax/ast/expression/call.rs index 51d3ecf0b9c..e003c475416 100644 --- a/boa_engine/src/syntax/ast/expression/call.rs +++ b/boa_engine/src/syntax/ast/expression/call.rs @@ -20,24 +20,24 @@ use super::Expression; #[cfg_attr(feature = "deser", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq)] pub struct Call { - target: Box, + function: Box, args: Box<[Expression]>, } impl Call { /// Creates a new `Call` AST Expression. #[inline] - pub fn new(target: Expression, args: Box<[Expression]>) -> Self { + pub fn new(function: Expression, args: Box<[Expression]>) -> Self { Self { - target: target.into(), + function: function.into(), args, } } - /// Gets the name of the function call. + /// Gets the target function of this call expression. #[inline] - pub fn expr(&self) -> &Expression { - &self.target + pub fn function(&self) -> &Expression { + &self.function } /// Retrieves the arguments passed to the function. @@ -48,12 +48,12 @@ impl Call { #[inline] pub(crate) fn contains_arguments(&self) -> bool { - self.target.contains_arguments() || self.args.iter().any(Expression::contains_arguments) + self.function.contains_arguments() || self.args.iter().any(Expression::contains_arguments) } #[inline] pub(crate) fn contains(&self, symbol: ContainsSymbol) -> bool { - self.target.contains(symbol) || self.args.iter().any(|expr| expr.contains(symbol)) + self.function.contains(symbol) || self.args.iter().any(|expr| expr.contains(symbol)) } } @@ -62,7 +62,7 @@ impl ToInternedString for Call { fn to_interned_string(&self, interner: &Interner) -> String { format!( "{}({})", - self.target.to_interned_string(interner), + self.function.to_interned_string(interner), join_nodes(interner, &self.args) ) } diff --git a/boa_engine/src/syntax/ast/expression/new.rs b/boa_engine/src/syntax/ast/expression/new.rs index 7f7a88c6a0b..5dc2731c2ea 100644 --- a/boa_engine/src/syntax/ast/expression/new.rs +++ b/boa_engine/src/syntax/ast/expression/new.rs @@ -25,19 +25,19 @@ pub struct New { } impl New { - /// Gets the name of the function call. + /// Gets the constructor of the new expression. #[inline] - pub fn expr(&self) -> &Expression { - self.call.expr() + pub fn constructor(&self) -> &Expression { + self.call.function() } - /// Retrieves the arguments passed to the function. + /// Retrieves the arguments passed to the constructor. #[inline] pub fn args(&self) -> &[Expression] { self.call.args() } - /// Returns the inner call + /// Returns the inner call expression. pub(crate) fn call(&self) -> &Call { &self.call } diff --git a/boa_engine/src/syntax/ast/expression/operator/assign/mod.rs b/boa_engine/src/syntax/ast/expression/operator/assign/mod.rs index e2d4776dc84..3474908ae83 100644 --- a/boa_engine/src/syntax/ast/expression/operator/assign/mod.rs +++ b/boa_engine/src/syntax/ast/expression/operator/assign/mod.rs @@ -372,7 +372,7 @@ pub(crate) fn array_decl_to_declaration_pattern( }); } Expression::Spread(spread) => { - match spread.val() { + match spread.target() { Expression::Identifier(ident) => { bindings.push(ArrayPatternElement::SingleNameRest { ident: *ident }); } diff --git a/boa_engine/src/syntax/ast/expression/spread.rs b/boa_engine/src/syntax/ast/expression/spread.rs index b8c41c3de40..cf6ece318cd 100644 --- a/boa_engine/src/syntax/ast/expression/spread.rs +++ b/boa_engine/src/syntax/ast/expression/spread.rs @@ -24,39 +24,39 @@ use super::Expression; #[cfg_attr(feature = "deser", serde(transparent))] #[derive(Clone, Debug, PartialEq)] pub struct Spread { - expression: Box, + target: Box, } impl Spread { - /// Gets the expression to be expanded by the spread operator. + /// Gets the target expression to be expanded by the spread operator. #[inline] - pub fn val(&self) -> &Expression { - &self.expression + pub fn target(&self) -> &Expression { + &self.target } /// Creates a `Spread` AST Expression. #[inline] - pub fn new(val: Expression) -> Self { + pub fn new(target: Expression) -> Self { Self { - expression: Box::new(val), + target: Box::new(target), } } #[inline] pub(crate) fn contains_arguments(&self) -> bool { - self.expression.contains_arguments() + self.target.contains_arguments() } #[inline] pub(crate) fn contains(&self, symbol: ContainsSymbol) -> bool { - self.expression.contains(symbol) + self.target.contains(symbol) } } impl ToInternedString for Spread { #[inline] fn to_interned_string(&self, interner: &Interner) -> String { - format!("...{}", self.val().to_interned_string(interner)) + format!("...{}", self.target().to_interned_string(interner)) } } diff --git a/boa_engine/src/syntax/ast/expression/yield.rs b/boa_engine/src/syntax/ast/expression/yield.rs index 73b2e4bb7c6..213ab133d12 100644 --- a/boa_engine/src/syntax/ast/expression/yield.rs +++ b/boa_engine/src/syntax/ast/expression/yield.rs @@ -15,15 +15,15 @@ use super::Expression; #[cfg_attr(feature = "deser", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq)] pub struct Yield { - expr: Option>, + target: Option>, delegate: bool, } impl Yield { - /// Gets the expression of this `Yield` statement. + /// Gets the target expression of this `Yield` statement. #[inline] - pub fn expr(&self) -> Option<&Expression> { - self.expr.as_ref().map(Box::as_ref) + pub fn target(&self) -> Option<&Expression> { + self.target.as_ref().map(Box::as_ref) } /// Returns `true` if this `Yield` statement delegates to another generator or iterable object. @@ -36,19 +36,19 @@ impl Yield { #[inline] pub fn new(expr: Option, delegate: bool) -> Self { Self { - expr: expr.map(Box::new), + target: expr.map(Box::new), delegate, } } #[inline] pub(crate) fn contains_arguments(&self) -> bool { - matches!(self.expr, Some(ref expr) if expr.contains_arguments()) + matches!(self.target, Some(ref expr) if expr.contains_arguments()) } #[inline] pub(crate) fn contains(&self, symbol: ContainsSymbol) -> bool { - matches!(self.expr, Some(ref expr) if expr.contains(symbol)) + matches!(self.target, Some(ref expr) if expr.contains(symbol)) } } @@ -63,7 +63,7 @@ impl ToInternedString for Yield { #[inline] fn to_interned_string(&self, interner: &Interner) -> String { let y = if self.delegate { "yield*" } else { "yield" }; - if let Some(ex) = self.expr() { + if let Some(ex) = self.target() { format!("{y} {}", ex.to_interned_string(interner)) } else { y.to_owned() diff --git a/boa_engine/src/syntax/ast/statement/iteration/for_in_loop.rs b/boa_engine/src/syntax/ast/statement/iteration/for_in_loop.rs index 1a1bf84a5cf..f19fd95e956 100644 --- a/boa_engine/src/syntax/ast/statement/iteration/for_in_loop.rs +++ b/boa_engine/src/syntax/ast/statement/iteration/for_in_loop.rs @@ -15,32 +15,32 @@ use boa_interner::{Interner, ToIndentedString, ToInternedString}; #[cfg_attr(feature = "deser", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq)] pub struct ForInLoop { - init: IterableLoopInitializer, - expr: Expression, + initializer: IterableLoopInitializer, + target: Expression, body: Box, } impl ForInLoop { /// Creates a new `ForInLoop`. #[inline] - pub fn new(init: IterableLoopInitializer, expr: Expression, body: Statement) -> Self { + pub fn new(initializer: IterableLoopInitializer, target: Expression, body: Statement) -> Self { Self { - init, - expr, + initializer, + target, body: body.into(), } } /// Gets the initializer of the for...in loop. #[inline] - pub fn init(&self) -> &IterableLoopInitializer { - &self.init + pub fn initializer(&self) -> &IterableLoopInitializer { + &self.initializer } - /// Gets the for...in loop expression. + /// Gets the target object of the for...in loop. #[inline] - pub fn expr(&self) -> &Expression { - &self.expr + pub fn target(&self) -> &Expression { + &self.target } /// Gets the body of the for...in loop. @@ -51,14 +51,16 @@ impl ForInLoop { #[inline] pub(crate) fn contains_arguments(&self) -> bool { - self.init.contains_arguments() - || self.expr.contains_arguments() + self.initializer.contains_arguments() + || self.target.contains_arguments() || self.body.contains_arguments() } #[inline] pub(crate) fn contains(&self, symbol: ContainsSymbol) -> bool { - self.init.contains(symbol) || self.expr.contains(symbol) || self.body.contains(symbol) + self.initializer.contains(symbol) + || self.target.contains(symbol) + || self.body.contains(symbol) } } @@ -66,8 +68,8 @@ impl ToIndentedString for ForInLoop { fn to_indented_string(&self, interner: &Interner, indentation: usize) -> String { let mut buf = format!( "for ({} in {}) ", - self.init.to_interned_string(interner), - self.expr.to_interned_string(interner) + self.initializer.to_interned_string(interner), + self.target.to_interned_string(interner) ); buf.push_str(&self.body().to_indented_string(interner, indentation)); diff --git a/boa_engine/src/syntax/ast/statement/mod.rs b/boa_engine/src/syntax/ast/statement/mod.rs index 3c44c35adc0..c097e04627b 100644 --- a/boa_engine/src/syntax/ast/statement/mod.rs +++ b/boa_engine/src/syntax/ast/statement/mod.rs @@ -179,7 +179,7 @@ impl Statement { for_loop.body().var_declared_names(vars); } Self::ForInLoop(for_in_loop) => { - if let IterableLoopInitializer::Var(bind) = for_in_loop.init() { + if let IterableLoopInitializer::Var(bind) = for_in_loop.initializer() { vars.extend(bind.idents()); } for_in_loop.body().var_declared_names(vars); diff --git a/boa_engine/src/syntax/ast/statement/return.rs b/boa_engine/src/syntax/ast/statement/return.rs index 8a99661a272..a8fbd04578f 100644 --- a/boa_engine/src/syntax/ast/statement/return.rs +++ b/boa_engine/src/syntax/ast/statement/return.rs @@ -21,27 +21,27 @@ use boa_interner::{Interner, ToInternedString}; #[cfg_attr(feature = "deser", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq)] pub struct Return { - expr: Option, + target: Option, } impl Return { - /// Gets the expression value of this `Return` statement. - pub fn expr(&self) -> Option<&Expression> { - self.expr.as_ref() + /// Gets the target expression value of this `Return` statement. + pub fn target(&self) -> Option<&Expression> { + self.target.as_ref() } /// Creates a `Return` AST node. - pub fn new(expr: Option) -> Self { - Self { expr } + pub fn new(expression: Option) -> Self { + Self { target: expression } } pub(crate) fn contains_arguments(&self) -> bool { - matches!(self.expr, Some(ref expr) if expr.contains_arguments()) + matches!(self.target, Some(ref expr) if expr.contains_arguments()) } #[inline] pub(crate) fn contains(&self, symbol: ContainsSymbol) -> bool { - matches!(self.expr, Some(ref expr) if expr.contains(symbol)) + matches!(self.target, Some(ref expr) if expr.contains(symbol)) } } @@ -53,7 +53,7 @@ impl From for Statement { impl ToInternedString for Return { fn to_interned_string(&self, interner: &Interner) -> String { - match self.expr() { + match self.target() { Some(ex) => format!("return {}", ex.to_interned_string(interner)), None => "return".to_owned(), } diff --git a/boa_engine/src/syntax/ast/statement/throw.rs b/boa_engine/src/syntax/ast/statement/throw.rs index 42e826baf8b..552b0b4bd8e 100644 --- a/boa_engine/src/syntax/ast/statement/throw.rs +++ b/boa_engine/src/syntax/ast/statement/throw.rs @@ -18,34 +18,34 @@ use boa_interner::{Interner, ToInternedString}; #[cfg_attr(feature = "deser", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq)] pub struct Throw { - expression: Expression, + target: Expression, } impl Throw { - /// Gets the expression value of this `Throw` statement. - pub fn expr(&self) -> &Expression { - &self.expression + /// Gets the target expression of this `Throw` statement. + pub fn target(&self) -> &Expression { + &self.target } /// Creates a `Throw` AST node. - pub fn new(expression: Expression) -> Self { - Self { expression } + pub fn new(target: Expression) -> Self { + Self { target } } #[inline] pub(crate) fn contains_arguments(&self) -> bool { - self.expression.contains_arguments() + self.target.contains_arguments() } #[inline] pub(crate) fn contains(&self, symbol: ContainsSymbol) -> bool { - self.expression.contains(symbol) + self.target.contains(symbol) } } impl ToInternedString for Throw { fn to_interned_string(&self, interner: &Interner) -> String { - format!("throw {}", self.expression.to_interned_string(interner)) + format!("throw {}", self.target.to_interned_string(interner)) } }