Skip to content

Commit

Permalink
feat: introduce Expression::is_writable() and `Expression::is_reada…
Browse files Browse the repository at this point in the history
…ble()` methods (#25)
  • Loading branch information
KennedyTedesco committed Jan 11, 2023
1 parent 39471c6 commit 1b9ee4f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/tree/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,41 @@ impl Expression {
_ => false,
}
}

/// Return true if the expression is writable
pub fn is_writable(&self) -> bool {
match self {
Expression::Variable(_)
| Expression::ArrayOperation(ArrayOperationExpression::Push { .. })
| Expression::ArrayOperation(ArrayOperationExpression::Access { .. })
| Expression::ObjectOperation(ObjectOperationExpression::PropertyFetch { .. })
| Expression::ClassOperation(ClassOperationExpression::StaticPropertyFetch {
..
}) => true,
Expression::Tuple(TupleExpression { elements, .. }) => {
elements.inner.iter().all(|element| element.is_writable())
}
_ => false,
}
}

/// Return true if the expression is readable
pub fn is_readable(&self) -> bool {
match self {
Expression::AssignmentOperation(..)
| Expression::ExitConstruct(..)
| Expression::ExceptionOperation(ExceptionOperationExpression::Throw { .. })
| Expression::ArrayOperation(ArrayOperationExpression::Push { .. }) => false,
Expression::AsyncOperation(AsyncOperationExpression::Concurrently {
expressions,
..
}) => expressions
.inner
.iter()
.all(|expression| expression.is_readable()),
_ => true,
}
}
}

impl Node for Expression {
Expand Down

0 comments on commit 1b9ee4f

Please sign in to comment.