Skip to content

Commit 421656f

Browse files
committed
refactor(ast): shorten serialize code using let chains
1 parent 1c15288 commit 421656f

File tree

1 file changed

+11
-13
lines changed
  • crates/oxc_ast/src/serialize

1 file changed

+11
-13
lines changed

crates/oxc_ast/src/serialize/mod.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,27 +193,25 @@ fn get_ts_start_span(program: &Program<'_>) -> u32 {
193193
return program.span.end;
194194
};
195195

196+
let start = first_stmt.span().start;
196197
match first_stmt {
197198
Statement::ExportNamedDeclaration(decl) => {
198-
let start = decl.span.start;
199-
if let Some(Declaration::ClassDeclaration(class)) = &decl.declaration {
200-
if let Some(decorator) = class.decorators.first() {
201-
return cmp::min(start, decorator.span.start);
202-
}
199+
if let Some(Declaration::ClassDeclaration(class)) = &decl.declaration
200+
&& let Some(decorator) = class.decorators.first()
201+
{
202+
return cmp::min(start, decorator.span.start);
203203
}
204-
start
205204
}
206205
Statement::ExportDefaultDeclaration(decl) => {
207-
let start = decl.span.start;
208-
if let ExportDefaultDeclarationKind::ClassDeclaration(class) = &decl.declaration {
209-
if let Some(decorator) = class.decorators.first() {
210-
return cmp::min(start, decorator.span.start);
211-
}
206+
if let ExportDefaultDeclarationKind::ClassDeclaration(class) = &decl.declaration
207+
&& let Some(decorator) = class.decorators.first()
208+
{
209+
return cmp::min(start, decorator.span.start);
212210
}
213-
start
214211
}
215-
_ => first_stmt.span().start,
212+
_ => {}
216213
}
214+
start
217215
}
218216

219217
/// Serialize `value` field of `Comment`.

0 commit comments

Comments
 (0)