Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove try_break macro in favour of question mark operator #4112

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions core/ast/src/declaration/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::{
AsyncFunctionDeclaration, AsyncGeneratorDeclaration, ClassDeclaration, FunctionDeclaration,
GeneratorDeclaration,
},
try_break,
visitor::{VisitWith, Visitor, VisitorMut},
Declaration, Expression,
};
Expand Down Expand Up @@ -50,7 +49,7 @@ impl VisitWith for ReExportKind {
Self::Namespaced { name: None } => ControlFlow::Continue(()),
Self::Named { names } => {
for name in &**names {
try_break!(visitor.visit_export_specifier(name));
visitor.visit_export_specifier(name)?;
}
ControlFlow::Continue(())
}
Expand All @@ -66,7 +65,7 @@ impl VisitWith for ReExportKind {
Self::Namespaced { name: None } => ControlFlow::Continue(()),
Self::Named { names } => {
for name in &mut **names {
try_break!(visitor.visit_export_specifier_mut(name));
visitor.visit_export_specifier_mut(name)?;
}
ControlFlow::Continue(())
}
Expand Down Expand Up @@ -117,12 +116,12 @@ impl VisitWith for ExportDeclaration {
{
match self {
Self::ReExport { specifier, kind } => {
try_break!(visitor.visit_module_specifier(specifier));
visitor.visit_module_specifier(specifier)?;
visitor.visit_re_export_kind(kind)
}
Self::List(list) => {
for item in &**list {
try_break!(visitor.visit_export_specifier(item));
visitor.visit_export_specifier(item)?;
}
ControlFlow::Continue(())
}
Expand All @@ -147,12 +146,12 @@ impl VisitWith for ExportDeclaration {
{
match self {
Self::ReExport { specifier, kind } => {
try_break!(visitor.visit_module_specifier_mut(specifier));
visitor.visit_module_specifier_mut(specifier)?;
visitor.visit_re_export_kind_mut(kind)
}
Self::List(list) => {
for item in &mut **list {
try_break!(visitor.visit_export_specifier_mut(item));
visitor.visit_export_specifier_mut(item)?;
}
ControlFlow::Continue(())
}
Expand Down Expand Up @@ -226,15 +225,15 @@ impl VisitWith for ExportSpecifier {
where
V: Visitor<'a>,
{
try_break!(visitor.visit_sym(&self.alias));
visitor.visit_sym(&self.alias)?;
visitor.visit_sym(&self.private_name)
}

fn visit_with_mut<'a, V>(&'a mut self, visitor: &mut V) -> ControlFlow<V::BreakTy>
where
V: VisitorMut<'a>,
{
try_break!(visitor.visit_sym_mut(&mut self.alias));
visitor.visit_sym_mut(&mut self.alias)?;
visitor.visit_sym_mut(&mut self.private_name)
}
}
Expand Down
17 changes: 8 additions & 9 deletions core/ast/src/declaration/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::ops::ControlFlow;

use crate::{
expression::Identifier,
try_break,
visitor::{VisitWith, Visitor, VisitorMut},
};
use boa_interner::Sym;
Expand Down Expand Up @@ -49,7 +48,7 @@ impl VisitWith for ImportKind {
Self::Namespaced { binding } => visitor.visit_identifier(binding),
Self::Named { names } => {
for name in &**names {
try_break!(visitor.visit_import_specifier(name));
visitor.visit_import_specifier(name)?;
}
ControlFlow::Continue(())
}
Expand All @@ -65,7 +64,7 @@ impl VisitWith for ImportKind {
Self::Namespaced { binding } => visitor.visit_identifier_mut(binding),
Self::Named { names } => {
for name in &mut **names {
try_break!(visitor.visit_import_specifier_mut(name));
visitor.visit_import_specifier_mut(name)?;
}
ControlFlow::Continue(())
}
Expand Down Expand Up @@ -134,9 +133,9 @@ impl VisitWith for ImportDeclaration {
V: Visitor<'a>,
{
if let Some(default) = &self.default {
try_break!(visitor.visit_identifier(default));
visitor.visit_identifier(default)?;
}
try_break!(visitor.visit_import_kind(&self.kind));
visitor.visit_import_kind(&self.kind)?;
visitor.visit_module_specifier(&self.specifier)
}

Expand All @@ -145,9 +144,9 @@ impl VisitWith for ImportDeclaration {
V: VisitorMut<'a>,
{
if let Some(default) = &mut self.default {
try_break!(visitor.visit_identifier_mut(default));
visitor.visit_identifier_mut(default)?;
}
try_break!(visitor.visit_import_kind_mut(&mut self.kind));
visitor.visit_import_kind_mut(&mut self.kind)?;
visitor.visit_module_specifier_mut(&mut self.specifier)
}
}
Expand Down Expand Up @@ -197,15 +196,15 @@ impl VisitWith for ImportSpecifier {
where
V: Visitor<'a>,
{
try_break!(visitor.visit_identifier(&self.binding));
visitor.visit_identifier(&self.binding)?;
visitor.visit_sym(&self.export_name)
}

fn visit_with_mut<'a, V>(&'a mut self, visitor: &mut V) -> ControlFlow<V::BreakTy>
where
V: VisitorMut<'a>,
{
try_break!(visitor.visit_identifier_mut(&mut self.binding));
visitor.visit_identifier_mut(&mut self.binding)?;
visitor.visit_sym_mut(&mut self.export_name)
}
}
Expand Down
13 changes: 6 additions & 7 deletions core/ast/src/declaration/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
expression::{Expression, Identifier},
join_nodes,
pattern::Pattern,
try_break,
visitor::{VisitWith, Visitor, VisitorMut},
Statement,
};
Expand Down Expand Up @@ -197,7 +196,7 @@ impl VisitWith for VariableList {
V: Visitor<'a>,
{
for variable in &*self.list {
try_break!(visitor.visit_variable(variable));
visitor.visit_variable(variable)?;
}
ControlFlow::Continue(())
}
Expand All @@ -207,7 +206,7 @@ impl VisitWith for VariableList {
V: VisitorMut<'a>,
{
for variable in &mut *self.list {
try_break!(visitor.visit_variable_mut(variable));
visitor.visit_variable_mut(variable)?;
}
ControlFlow::Continue(())
}
Expand Down Expand Up @@ -309,9 +308,9 @@ impl VisitWith for Variable {
where
V: Visitor<'a>,
{
try_break!(visitor.visit_binding(&self.binding));
visitor.visit_binding(&self.binding)?;
if let Some(init) = &self.init {
try_break!(visitor.visit_expression(init));
visitor.visit_expression(init)?;
}
ControlFlow::Continue(())
}
Expand All @@ -320,9 +319,9 @@ impl VisitWith for Variable {
where
V: VisitorMut<'a>,
{
try_break!(visitor.visit_binding_mut(&mut self.binding));
visitor.visit_binding_mut(&mut self.binding)?;
if let Some(init) = &mut self.init {
try_break!(visitor.visit_expression_mut(init));
visitor.visit_expression_mut(init)?;
}
ControlFlow::Continue(())
}
Expand Down
9 changes: 4 additions & 5 deletions core/ast/src/expression/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use crate::expression::Expression;
use crate::function::PrivateName;
use crate::try_break;
use crate::visitor::{VisitWith, Visitor, VisitorMut};
use boa_interner::{Interner, Sym, ToInternedString};
use core::ops::ControlFlow;
Expand Down Expand Up @@ -188,15 +187,15 @@ impl VisitWith for SimplePropertyAccess {
where
V: Visitor<'a>,
{
try_break!(visitor.visit_expression(&self.target));
visitor.visit_expression(&self.target)?;
visitor.visit_property_access_field(&self.field)
}

fn visit_with_mut<'a, V>(&'a mut self, visitor: &mut V) -> ControlFlow<V::BreakTy>
where
V: VisitorMut<'a>,
{
try_break!(visitor.visit_expression_mut(&mut self.target));
visitor.visit_expression_mut(&mut self.target)?;
visitor.visit_property_access_field_mut(&mut self.field)
}
}
Expand Down Expand Up @@ -268,15 +267,15 @@ impl VisitWith for PrivatePropertyAccess {
where
V: Visitor<'a>,
{
try_break!(visitor.visit_expression(&self.target));
visitor.visit_expression(&self.target)?;
visitor.visit_private_name(&self.field)
}

fn visit_with_mut<'a, V>(&'a mut self, visitor: &mut V) -> ControlFlow<V::BreakTy>
where
V: VisitorMut<'a>,
{
try_break!(visitor.visit_expression_mut(&mut self.target));
visitor.visit_expression_mut(&mut self.target)?;
visitor.visit_private_name_mut(&mut self.field)
}
}
Expand Down
13 changes: 6 additions & 7 deletions core/ast/src/expression/call.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::join_nodes;
use crate::try_break;
use crate::visitor::{VisitWith, Visitor, VisitorMut};
use boa_interner::{Interner, ToInternedString};
use core::ops::ControlFlow;
Expand Down Expand Up @@ -77,9 +76,9 @@ impl VisitWith for Call {
where
V: Visitor<'a>,
{
try_break!(visitor.visit_expression(&self.function));
visitor.visit_expression(&self.function)?;
for expr in &*self.args {
try_break!(visitor.visit_expression(expr));
visitor.visit_expression(expr)?;
}
ControlFlow::Continue(())
}
Expand All @@ -88,9 +87,9 @@ impl VisitWith for Call {
where
V: VisitorMut<'a>,
{
try_break!(visitor.visit_expression_mut(&mut self.function));
visitor.visit_expression_mut(&mut self.function)?;
for expr in &mut *self.args {
try_break!(visitor.visit_expression_mut(expr));
visitor.visit_expression_mut(expr)?;
}
ControlFlow::Continue(())
}
Expand Down Expand Up @@ -147,7 +146,7 @@ impl VisitWith for SuperCall {
V: Visitor<'a>,
{
for expr in &*self.args {
try_break!(visitor.visit_expression(expr));
visitor.visit_expression(expr)?;
}
ControlFlow::Continue(())
}
Expand All @@ -157,7 +156,7 @@ impl VisitWith for SuperCall {
V: VisitorMut<'a>,
{
for expr in &mut *self.args {
try_break!(visitor.visit_expression_mut(expr));
visitor.visit_expression_mut(expr)?;
}
ControlFlow::Continue(())
}
Expand Down
5 changes: 2 additions & 3 deletions core/ast/src/expression/literal/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::expression::operator::assign::{AssignOp, AssignTarget};
use crate::expression::Expression;
use crate::pattern::{ArrayPattern, ArrayPatternElement, Pattern};
use crate::try_break;
use crate::visitor::{VisitWith, Visitor, VisitorMut};
use boa_interner::{Interner, Sym, ToInternedString};
use core::ops::ControlFlow;
Expand Down Expand Up @@ -223,7 +222,7 @@ impl VisitWith for ArrayLiteral {
V: Visitor<'a>,
{
for expr in self.arr.iter().flatten() {
try_break!(visitor.visit_expression(expr));
visitor.visit_expression(expr)?;
}
ControlFlow::Continue(())
}
Expand All @@ -233,7 +232,7 @@ impl VisitWith for ArrayLiteral {
V: VisitorMut<'a>,
{
for expr in self.arr.iter_mut().flatten() {
try_break!(visitor.visit_expression_mut(expr));
visitor.visit_expression_mut(expr)?;
}
ControlFlow::Continue(())
}
Expand Down
21 changes: 10 additions & 11 deletions core/ast/src/expression/literal/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{
pattern::{ObjectPattern, ObjectPatternElement},
property::{MethodDefinitionKind, PropertyName},
scope::FunctionScopes,
try_break,
visitor::{VisitWith, Visitor, VisitorMut},
};
use boa_interner::{Interner, Sym, ToIndentedString, ToInternedString};
Expand Down Expand Up @@ -266,7 +265,7 @@ impl VisitWith for ObjectLiteral {
V: Visitor<'a>,
{
for pd in &*self.properties {
try_break!(visitor.visit_property_definition(pd));
visitor.visit_property_definition(pd)?;
}
ControlFlow::Continue(())
}
Expand All @@ -276,7 +275,7 @@ impl VisitWith for ObjectLiteral {
V: VisitorMut<'a>,
{
for pd in &mut *self.properties {
try_break!(visitor.visit_property_definition_mut(pd));
visitor.visit_property_definition_mut(pd)?;
}
ControlFlow::Continue(())
}
Expand Down Expand Up @@ -359,13 +358,13 @@ impl VisitWith for PropertyDefinition {
match self {
Self::IdentifierReference(id) => visitor.visit_identifier(id),
Self::Property(pn, expr) => {
try_break!(visitor.visit_property_name(pn));
visitor.visit_property_name(pn)?;
visitor.visit_expression(expr)
}
Self::MethodDefinition(m) => visitor.visit_object_method_definition(m),
Self::SpreadObject(expr) => visitor.visit_expression(expr),
Self::CoverInitializedName(id, expr) => {
try_break!(visitor.visit_identifier(id));
visitor.visit_identifier(id)?;
visitor.visit_expression(expr)
}
}
Expand All @@ -378,13 +377,13 @@ impl VisitWith for PropertyDefinition {
match self {
Self::IdentifierReference(id) => visitor.visit_identifier_mut(id),
Self::Property(pn, expr) => {
try_break!(visitor.visit_property_name_mut(pn));
visitor.visit_property_name_mut(pn)?;
visitor.visit_expression_mut(expr)
}
Self::MethodDefinition(m) => visitor.visit_object_method_definition_mut(m),
Self::SpreadObject(expr) => visitor.visit_expression_mut(expr),
Self::CoverInitializedName(id, expr) => {
try_break!(visitor.visit_identifier_mut(id));
visitor.visit_identifier_mut(id)?;
visitor.visit_expression_mut(expr)
}
}
Expand Down Expand Up @@ -501,17 +500,17 @@ impl VisitWith for ObjectMethodDefinition {
where
V: Visitor<'a>,
{
try_break!(visitor.visit_property_name(&self.name));
try_break!(visitor.visit_formal_parameter_list(&self.parameters));
visitor.visit_property_name(&self.name)?;
visitor.visit_formal_parameter_list(&self.parameters)?;
visitor.visit_function_body(&self.body)
}

fn visit_with_mut<'a, V>(&'a mut self, visitor: &mut V) -> ControlFlow<V::BreakTy>
where
V: VisitorMut<'a>,
{
try_break!(visitor.visit_property_name_mut(&mut self.name));
try_break!(visitor.visit_formal_parameter_list_mut(&mut self.parameters));
visitor.visit_property_name_mut(&mut self.name)?;
visitor.visit_formal_parameter_list_mut(&mut self.parameters)?;
visitor.visit_function_body_mut(&mut self.body)
}
}
Loading
Loading