Skip to content

Commit

Permalink
refactor(rust): backport v1.82.0 changes to main branch first
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] authored and Boshen committed Oct 19, 2024
1 parent ce25c45 commit a57ff56
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 39 deletions.
73 changes: 35 additions & 38 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,46 +846,43 @@ impl<'a> Gen for ExportNamedDeclaration<'a> {
if self.export_kind.is_type() {
p.print_str("type ");
}
match &self.declaration {
Some(decl) => {
match decl {
Declaration::VariableDeclaration(decl) => decl.print(p, ctx),
Declaration::FunctionDeclaration(decl) => decl.print(p, ctx),
Declaration::ClassDeclaration(decl) => decl.print(p, ctx),
Declaration::TSModuleDeclaration(decl) => decl.print(p, ctx),
Declaration::TSTypeAliasDeclaration(decl) => decl.print(p, ctx),
Declaration::TSInterfaceDeclaration(decl) => decl.print(p, ctx),
Declaration::TSEnumDeclaration(decl) => decl.print(p, ctx),
Declaration::TSImportEqualsDeclaration(decl) => decl.print(p, ctx),
}
if matches!(
decl,
Declaration::VariableDeclaration(_)
| Declaration::TSTypeAliasDeclaration(_)
| Declaration::TSImportEqualsDeclaration(_)
) {
p.print_semicolon_after_statement();
} else {
p.print_soft_newline();
p.needs_semicolon = false;
}
}
None => {
p.print_ascii_byte(b'{');
if !self.specifiers.is_empty() {
p.print_soft_space();
p.print_list(&self.specifiers, ctx);
p.print_soft_space();
}
p.print_ascii_byte(b'}');
if let Some(source) = &self.source {
p.print_soft_space();
p.print_str("from");
p.print_soft_space();
source.print(p, ctx);
}
if let Some(decl) = &self.declaration {
match decl {
Declaration::VariableDeclaration(decl) => decl.print(p, ctx),
Declaration::FunctionDeclaration(decl) => decl.print(p, ctx),
Declaration::ClassDeclaration(decl) => decl.print(p, ctx),
Declaration::TSModuleDeclaration(decl) => decl.print(p, ctx),
Declaration::TSTypeAliasDeclaration(decl) => decl.print(p, ctx),
Declaration::TSInterfaceDeclaration(decl) => decl.print(p, ctx),
Declaration::TSEnumDeclaration(decl) => decl.print(p, ctx),
Declaration::TSImportEqualsDeclaration(decl) => decl.print(p, ctx),
}
if matches!(
decl,
Declaration::VariableDeclaration(_)
| Declaration::TSTypeAliasDeclaration(_)
| Declaration::TSImportEqualsDeclaration(_)
) {
p.print_semicolon_after_statement();
} else {
p.print_soft_newline();
p.needs_semicolon = false;
}
} else {
p.print_ascii_byte(b'{');
if !self.specifiers.is_empty() {
p.print_soft_space();
p.print_list(&self.specifiers, ctx);
p.print_soft_space();
}
p.print_ascii_byte(b'}');
if let Some(source) = &self.source {
p.print_soft_space();
p.print_str("from");
p.print_soft_space();
source.print(p, ctx);
}
p.print_semicolon_after_statement();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl<'a, 'b> PeepholeFoldConstants {
| (ValueType::Boolean, ValueType::Boolean) => {
let left_number = ctx.get_number_value(left)?;
let right_number = ctx.get_number_value(right)?;
let Ok(value) = TryInto::<f64>::try_into(left_number + right_number) else { return None };
let value = left_number + right_number;
// Float if value has a fractional part, otherwise Decimal
let number_base = if is_exact_int64(value) { NumberBase::Decimal } else { NumberBase::Float };
// todo: add raw &str
Expand Down

0 comments on commit a57ff56

Please sign in to comment.