Skip to content

Commit bbee356

Browse files
committed
minor: Add expr_bin constructor to SyntaxFactory
1 parent d69fa5c commit bbee356

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/syntax/src/ast/syntax_factory/constructors.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ impl SyntaxFactory {
5454
ast
5555
}
5656

57+
pub fn expr_bin(&self, lhs: ast::Expr, op: ast::BinaryOp, rhs: ast::Expr) -> ast::BinExpr {
58+
let ast::Expr::BinExpr(ast) =
59+
make::expr_bin_op(lhs.clone(), op, rhs.clone()).clone_for_update()
60+
else {
61+
unreachable!()
62+
};
63+
64+
if let Some(mut mapping) = self.mappings() {
65+
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
66+
builder.map_node(lhs.syntax().clone(), ast.lhs().unwrap().syntax().clone());
67+
builder.map_node(rhs.syntax().clone(), ast.rhs().unwrap().syntax().clone());
68+
builder.finish(&mut mapping);
69+
}
70+
71+
ast
72+
}
73+
5774
pub fn expr_path(&self, path: ast::Path) -> ast::Expr {
5875
let ast::Expr::PathExpr(ast) = make::expr_path(path.clone()).clone_for_update() else {
5976
unreachable!()

0 commit comments

Comments
 (0)