Skip to content

Commit ce33015

Browse files
committed
fixup: Kevin’s suggestions
1 parent ac9029e commit ce33015

File tree

1 file changed

+11
-16
lines changed
  • packages/async-rewriter3/src

1 file changed

+11
-16
lines changed

packages/async-rewriter3/src/lib.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ impl InsertionList {
6565
}
6666

6767
fn is_block(body: &ExprOrBlock) -> bool {
68-
match body {
69-
ExprOrBlock::Block(_) => { true }
70-
ExprOrBlock::Expr(_) => { false }
71-
}
68+
return matches!(body, ExprOrBlock::Block(_));
7269
}
7370

7471
fn make_start_fn_insertion(offset: TextSize) -> Insertion {
@@ -165,15 +162,13 @@ fn add_all_variables_from_declaration(patterns: impl Iterator<Item = impl Borrow
165162
p.name().map(|name| ret.add_variable(name.to_string()));
166163
},
167164
Pattern::RestPattern(p) => {
168-
let pat = p.pat();
169-
if pat.is_some() {
170-
ret.append(&mut add_all_variables_from_declaration([&pat.unwrap()].into_iter()));
165+
if let Some(pat) = p.pat() {
166+
ret.append(&mut add_all_variables_from_declaration([&pat].into_iter()));
171167
}
172168
},
173169
Pattern::AssignPattern(p) => {
174-
let key = p.key();
175-
if key.is_some() {
176-
ret.append(&mut add_all_variables_from_declaration([&key.unwrap()].into_iter()));
170+
if let Some(key) = p.key() {
171+
ret.append(&mut add_all_variables_from_declaration([&key].into_iter()));
177172
}
178173
},
179174
Pattern::ObjectPattern(p) => {
@@ -183,8 +178,8 @@ fn add_all_variables_from_declaration(patterns: impl Iterator<Item = impl Borrow
183178
ret.append(&mut add_all_variables_from_declaration([&Pattern::AssignPattern(p)].into_iter()));
184179
}
185180
ObjectPatternProp::KeyValuePattern(p) => {
186-
if p.key().is_some() {
187-
match p.key().unwrap() {
181+
if let Some(key) = p.key() {
182+
match key {
188183
PropName::Ident(ident) => {
189184
ret.add_variable(ident.text());
190185
}
@@ -276,12 +271,12 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
276271
if ExprStmt::can_cast(child.kind()) && !has_function_parent {
277272
let as_expr_stmt = ExprStmt::cast(child).unwrap();
278273
let expr_range = as_expr_stmt.expr().map(|e| e.syntax().text_range());
279-
if expr_range.is_some() {
280-
insertions.push_back(Insertion::new(expr_range.unwrap().start(), "_cr = ("));
274+
if let Some(start) = expr_range.map(|r| r.start()) {
275+
insertions.push_back(Insertion::new(start, "_cr = ("));
281276
}
282277
insertions.append(child_insertions);
283-
if expr_range.is_some() {
284-
insertions.push_back(Insertion::new(expr_range.unwrap().end(), ")"));
278+
if let Some(end) = expr_range.map(|r| r.end()) {
279+
insertions.push_back(Insertion::new(end, ")"));
285280
}
286281
continue;
287282
}

0 commit comments

Comments
 (0)