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

[Merged by Bors] - Restructure lint lists in boa_ast #2433

Closed
wants to merge 2 commits into from
Closed
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
36 changes: 18 additions & 18 deletions boa_ast/src/declaration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ pub enum Declaration {
impl ToIndentedString for Declaration {
fn to_indented_string(&self, interner: &Interner, indentation: usize) -> String {
match self {
Declaration::Function(f) => f.to_indented_string(interner, indentation),
Declaration::Generator(g) => g.to_indented_string(interner, indentation),
Declaration::AsyncFunction(af) => af.to_indented_string(interner, indentation),
Declaration::AsyncGenerator(ag) => ag.to_indented_string(interner, indentation),
Declaration::Class(c) => c.to_indented_string(interner, indentation),
Declaration::Lexical(l) => {
Self::Function(f) => f.to_indented_string(interner, indentation),
Self::Generator(g) => g.to_indented_string(interner, indentation),
Self::AsyncFunction(af) => af.to_indented_string(interner, indentation),
Self::AsyncGenerator(ag) => ag.to_indented_string(interner, indentation),
Self::Class(c) => c.to_indented_string(interner, indentation),
Self::Lexical(l) => {
let mut s = l.to_interned_string(interner);
s.push(';');
s
Expand All @@ -72,12 +72,12 @@ impl VisitWith for Declaration {
V: Visitor<'a>,
{
match self {
Declaration::Function(f) => visitor.visit_function(f),
Declaration::Generator(g) => visitor.visit_generator(g),
Declaration::AsyncFunction(af) => visitor.visit_async_function(af),
Declaration::AsyncGenerator(ag) => visitor.visit_async_generator(ag),
Declaration::Class(c) => visitor.visit_class(c),
Declaration::Lexical(ld) => visitor.visit_lexical_declaration(ld),
Self::Function(f) => visitor.visit_function(f),
Self::Generator(g) => visitor.visit_generator(g),
Self::AsyncFunction(af) => visitor.visit_async_function(af),
Self::AsyncGenerator(ag) => visitor.visit_async_generator(ag),
Self::Class(c) => visitor.visit_class(c),
Self::Lexical(ld) => visitor.visit_lexical_declaration(ld),
}
}

Expand All @@ -86,12 +86,12 @@ impl VisitWith for Declaration {
V: VisitorMut<'a>,
{
match self {
Declaration::Function(f) => visitor.visit_function_mut(f),
Declaration::Generator(g) => visitor.visit_generator_mut(g),
Declaration::AsyncFunction(af) => visitor.visit_async_function_mut(af),
Declaration::AsyncGenerator(ag) => visitor.visit_async_generator_mut(ag),
Declaration::Class(c) => visitor.visit_class_mut(c),
Declaration::Lexical(ld) => visitor.visit_lexical_declaration_mut(ld),
Self::Function(f) => visitor.visit_function_mut(f),
Self::Generator(g) => visitor.visit_generator_mut(g),
Self::AsyncFunction(af) => visitor.visit_async_function_mut(af),
Self::AsyncGenerator(ag) => visitor.visit_async_generator_mut(ag),
Self::Class(c) => visitor.visit_class_mut(c),
Self::Lexical(ld) => visitor.visit_lexical_declaration_mut(ld),
}
}
}
46 changes: 21 additions & 25 deletions boa_ast/src/declaration/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct VarDeclaration(pub VariableList);

impl From<VarDeclaration> for Statement {
fn from(var: VarDeclaration) -> Self {
Statement::Var(var)
Self::Var(var)
}
}

Expand Down Expand Up @@ -110,16 +110,16 @@ pub enum LexicalDeclaration {
impl LexicalDeclaration {
/// Gets the inner variable list of the `LexicalDeclaration`
#[must_use]
pub fn variable_list(&self) -> &VariableList {
pub const fn variable_list(&self) -> &VariableList {
match self {
LexicalDeclaration::Const(list) | LexicalDeclaration::Let(list) => list,
Self::Const(list) | Self::Let(list) => list,
}
}
}

impl From<LexicalDeclaration> for Declaration {
fn from(lex: LexicalDeclaration) -> Self {
Declaration::Lexical(lex)
Self::Lexical(lex)
}
}

Expand All @@ -128,8 +128,8 @@ impl ToInternedString for LexicalDeclaration {
format!(
"{} {}",
match &self {
LexicalDeclaration::Let(_) => "let",
LexicalDeclaration::Const(_) => "const",
Self::Let(_) => "let",
Self::Const(_) => "const",
},
self.variable_list().to_interned_string(interner)
)
Expand All @@ -142,9 +142,7 @@ impl VisitWith for LexicalDeclaration {
V: Visitor<'a>,
{
match self {
LexicalDeclaration::Const(vars) | LexicalDeclaration::Let(vars) => {
visitor.visit_variable_list(vars)
}
Self::Const(vars) | Self::Let(vars) => visitor.visit_variable_list(vars),
}
}

Expand All @@ -153,9 +151,7 @@ impl VisitWith for LexicalDeclaration {
V: VisitorMut<'a>,
{
match self {
LexicalDeclaration::Const(vars) | LexicalDeclaration::Let(vars) => {
visitor.visit_variable_list_mut(vars)
}
Self::Const(vars) | Self::Let(vars) => visitor.visit_variable_list_mut(vars),
}
}
}
Expand All @@ -176,7 +172,7 @@ impl VariableList {
return None;
}

Some(VariableList { list })
Some(Self { list })
}
}

Expand Down Expand Up @@ -228,15 +224,15 @@ impl TryFrom<Box<[Variable]>> for VariableList {
type Error = TryFromVariableListError;

fn try_from(value: Box<[Variable]>) -> Result<Self, Self::Error> {
VariableList::new(value).ok_or(TryFromVariableListError(()))
Self::new(value).ok_or(TryFromVariableListError(()))
}
}

impl TryFrom<Vec<Variable>> for VariableList {
type Error = TryFromVariableListError;

fn try_from(value: Vec<Variable>) -> Result<Self, Self::Error> {
VariableList::try_from(value.into_boxed_slice())
Self::try_from(value.into_boxed_slice())
}
}

Expand Down Expand Up @@ -275,7 +271,7 @@ impl Variable {
/// Creates a new variable declaration from a `BindingIdentifier`.
#[inline]
#[must_use]
pub fn from_identifier(ident: Identifier, init: Option<Expression>) -> Self {
pub const fn from_identifier(ident: Identifier, init: Option<Expression>) -> Self {
Self {
binding: Binding::Identifier(ident),
init,
Expand All @@ -285,22 +281,22 @@ impl Variable {
/// Creates a new variable declaration from a `Pattern`.
#[inline]
#[must_use]
pub fn from_pattern(pattern: Pattern, init: Option<Expression>) -> Self {
pub const fn from_pattern(pattern: Pattern, init: Option<Expression>) -> Self {
Self {
binding: Binding::Pattern(pattern),
init,
}
}
/// Gets the variable declaration binding.
#[must_use]
pub fn binding(&self) -> &Binding {
pub const fn binding(&self) -> &Binding {
&self.binding
}

/// Gets the initialization expression for the variable declaration, if any.
#[inline]
#[must_use]
pub fn init(&self) -> Option<&Expression> {
pub const fn init(&self) -> Option<&Expression> {
self.init.as_ref()
}
}
Expand Down Expand Up @@ -360,8 +356,8 @@ impl From<Pattern> for Binding {
impl ToInternedString for Binding {
fn to_interned_string(&self, interner: &Interner) -> String {
match self {
Binding::Identifier(id) => id.to_interned_string(interner),
Binding::Pattern(ref pattern) => pattern.to_interned_string(interner),
Self::Identifier(id) => id.to_interned_string(interner),
Self::Pattern(ref pattern) => pattern.to_interned_string(interner),
}
}
}
Expand All @@ -372,8 +368,8 @@ impl VisitWith for Binding {
V: Visitor<'a>,
{
match self {
Binding::Identifier(id) => visitor.visit_identifier(id),
Binding::Pattern(pattern) => visitor.visit_pattern(pattern),
Self::Identifier(id) => visitor.visit_identifier(id),
Self::Pattern(pattern) => visitor.visit_pattern(pattern),
}
}

Expand All @@ -382,8 +378,8 @@ impl VisitWith for Binding {
V: VisitorMut<'a>,
{
match self {
Binding::Identifier(id) => visitor.visit_identifier_mut(id),
Binding::Pattern(pattern) => visitor.visit_pattern_mut(pattern),
Self::Identifier(id) => visitor.visit_identifier_mut(id),
Self::Pattern(pattern) => visitor.visit_pattern_mut(pattern),
}
}
}
38 changes: 19 additions & 19 deletions boa_ast/src/expression/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl VisitWith for PropertyAccessField {
V: Visitor<'a>,
{
match self {
PropertyAccessField::Const(sym) => visitor.visit_sym(sym),
PropertyAccessField::Expr(expr) => visitor.visit_expression(expr),
Self::Const(sym) => visitor.visit_sym(sym),
Self::Expr(expr) => visitor.visit_expression(expr),
}
}

Expand All @@ -63,8 +63,8 @@ impl VisitWith for PropertyAccessField {
V: VisitorMut<'a>,
{
match self {
PropertyAccessField::Const(sym) => visitor.visit_sym_mut(sym),
PropertyAccessField::Expr(expr) => visitor.visit_expression_mut(&mut *expr),
Self::Const(sym) => visitor.visit_sym_mut(sym),
Self::Expr(expr) => visitor.visit_expression_mut(&mut *expr),
}
}
}
Expand All @@ -88,9 +88,9 @@ impl ToInternedString for PropertyAccess {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
match self {
PropertyAccess::Simple(s) => s.to_interned_string(interner),
PropertyAccess::Private(p) => p.to_interned_string(interner),
PropertyAccess::Super(s) => s.to_interned_string(interner),
Self::Simple(s) => s.to_interned_string(interner),
Self::Private(p) => p.to_interned_string(interner),
Self::Super(s) => s.to_interned_string(interner),
}
}
}
Expand All @@ -108,9 +108,9 @@ impl VisitWith for PropertyAccess {
V: Visitor<'a>,
{
match self {
PropertyAccess::Simple(spa) => visitor.visit_simple_property_access(spa),
PropertyAccess::Private(ppa) => visitor.visit_private_property_access(ppa),
PropertyAccess::Super(supa) => visitor.visit_super_property_access(supa),
Self::Simple(spa) => visitor.visit_simple_property_access(spa),
Self::Private(ppa) => visitor.visit_private_property_access(ppa),
Self::Super(supa) => visitor.visit_super_property_access(supa),
}
}

Expand All @@ -119,9 +119,9 @@ impl VisitWith for PropertyAccess {
V: VisitorMut<'a>,
{
match self {
PropertyAccess::Simple(spa) => visitor.visit_simple_property_access_mut(spa),
PropertyAccess::Private(ppa) => visitor.visit_private_property_access_mut(ppa),
PropertyAccess::Super(supa) => visitor.visit_super_property_access_mut(supa),
Self::Simple(spa) => visitor.visit_simple_property_access_mut(spa),
Self::Private(ppa) => visitor.visit_private_property_access_mut(ppa),
Self::Super(supa) => visitor.visit_super_property_access_mut(supa),
}
}
}
Expand All @@ -139,14 +139,14 @@ impl SimplePropertyAccess {
/// Gets the target object of the property access.
#[inline]
#[must_use]
pub fn target(&self) -> &Expression {
pub const fn target(&self) -> &Expression {
&self.target
}

/// Gets the accessed field of the target object.
#[inline]
#[must_use]
pub fn field(&self) -> &PropertyAccessField {
pub const fn field(&self) -> &PropertyAccessField {
&self.field
}

Expand Down Expand Up @@ -233,14 +233,14 @@ impl PrivatePropertyAccess {
/// Gets the original object from where to get the field from.
#[inline]
#[must_use]
pub fn target(&self) -> &Expression {
pub const fn target(&self) -> &Expression {
&self.target
}

/// Gets the name of the field to retrieve.
#[inline]
#[must_use]
pub fn field(&self) -> Sym {
pub const fn field(&self) -> Sym {
self.field
}
}
Expand Down Expand Up @@ -298,14 +298,14 @@ pub struct SuperPropertyAccess {
impl SuperPropertyAccess {
/// Creates a new property access field node.
#[must_use]
pub fn new(field: PropertyAccessField) -> Self {
pub const fn new(field: PropertyAccessField) -> Self {
Self { field }
}

/// Gets the name of the field to retrieve.
#[inline]
#[must_use]
pub fn field(&self) -> &PropertyAccessField {
pub const fn field(&self) -> &PropertyAccessField {
&self.field
}
}
Expand Down
2 changes: 1 addition & 1 deletion boa_ast/src/expression/await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Await {
/// Return the target expression that should be awaited.
#[inline]
#[must_use]
pub fn target(&self) -> &Expression {
pub const fn target(&self) -> &Expression {
&self.target
}
}
Expand Down
6 changes: 3 additions & 3 deletions boa_ast/src/expression/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ impl Call {
/// Gets the target function of this call expression.
#[inline]
#[must_use]
pub fn function(&self) -> &Expression {
pub const fn function(&self) -> &Expression {
&self.function
}

/// Retrieves the arguments passed to the function.
#[inline]
#[must_use]
pub fn args(&self) -> &[Expression] {
pub const fn args(&self) -> &[Expression] {
&self.args
}
}
Expand Down Expand Up @@ -122,7 +122,7 @@ impl SuperCall {

/// Retrieves the arguments of the super call.
#[must_use]
pub fn arguments(&self) -> &[Expression] {
pub const fn arguments(&self) -> &[Expression] {
&self.args
}
}
Expand Down
4 changes: 2 additions & 2 deletions boa_ast/src/expression/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ impl Identifier {
/// Creates a new identifier AST Expression.
#[inline]
#[must_use]
pub fn new(ident: Sym) -> Self {
pub const fn new(ident: Sym) -> Self {
Self { ident }
}

/// Retrieves the identifier's string symbol in the interner.
#[inline]
#[must_use]
pub fn sym(self) -> Sym {
pub const fn sym(self) -> Sym {
self.ident
}
}
Expand Down
2 changes: 1 addition & 1 deletion boa_ast/src/expression/literal/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl ArrayLiteral {
/// Indicates if a spread operator in the array literal has a trailing comma.
/// This is a syntax error in some cases.
#[must_use]
pub fn has_trailing_comma_spread(&self) -> bool {
pub const fn has_trailing_comma_spread(&self) -> bool {
self.has_trailing_comma_spread
}

Expand Down
Loading