Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ description = "A collection of JavaScript tools written in Rust."
edition = "2024"
# MSRV Policy N-2 (12 weeks).
# Balance between the core contributors enjoying the latest version of rustc, while waiting for dependents to catch up.
rust-version = "1.87.0"
rust-version = "1.88.0"

# <https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html>
[workspace.lints.rust]
Expand Down
21 changes: 10 additions & 11 deletions apps/oxfmt/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ impl ignore::ParallelVisitor for WalkVisitor {
match entry {
Ok(entry) => {
// Skip if we can't get file type or if it's a directory
if let Some(file_type) = entry.file_type() {
if !file_type.is_dir() {
if let Some(source_type) = get_supported_source_type(entry.path()) {
let walk_entry =
WalkEntry { path: entry.path().as_os_str().into(), source_type };
// Send each entry immediately through the channel
// If send fails, the receiver has been dropped, so stop walking
if self.sender.send(walk_entry).is_err() {
return ignore::WalkState::Quit;
}
}
if let Some(file_type) = entry.file_type()
&& !file_type.is_dir()
&& let Some(source_type) = get_supported_source_type(entry.path())
{
let walk_entry =
WalkEntry { path: entry.path().as_os_str().into(), source_type };
// Send each entry immediately through the channel
// If send fails, the receiver has been dropped, so stop walking
if self.sender.send(walk_entry).is_err() {
return ignore::WalkState::Quit;
}
}
ignore::WalkState::Continue
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_allocator/src/vec2/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,10 @@ impl<T, A: Alloc> RawVec<'_, T, A> {
/// Not sure what safety invariants of this method are! TODO
pub unsafe fn dealloc_buffer(&mut self) {
let elem_size = mem::size_of::<T>();
if elem_size != 0 {
if let Some(layout) = self.current_layout() {
self.alloc.dealloc(self.ptr.cast(), layout);
}
if elem_size != 0
&& let Some(layout) = self.current_layout()
{
self.alloc.dealloc(self.ptr.cast(), layout);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1537,20 +1537,20 @@ impl FunctionBody<'_> {
impl<'a> ArrowFunctionExpression<'a> {
/// Get expression part of `ArrowFunctionExpression`: `() => expression_part`.
pub fn get_expression(&self) -> Option<&Expression<'a>> {
if self.expression {
if let Statement::ExpressionStatement(expr_stmt) = &self.body.statements[0] {
return Some(&expr_stmt.expression);
}
if self.expression
&& let Statement::ExpressionStatement(expr_stmt) = &self.body.statements[0]
{
return Some(&expr_stmt.expression);
}
None
}

/// Get expression part of `ArrowFunctionExpression`: `() => expression_part`.
pub fn get_expression_mut(&mut self) -> Option<&mut Expression<'a>> {
if self.expression {
if let Statement::ExpressionStatement(expr_stmt) = &mut self.body.statements[0] {
return Some(&mut expr_stmt.expression);
}
if self.expression
&& let Statement::ExpressionStatement(expr_stmt) = &mut self.body.statements[0]
{
return Some(&mut expr_stmt.expression);
}
None
}
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_ast/src/ast_impl/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ impl StringLiteral<'_> {
while let Some(c) = chars.next() {
if c == '\\' && chars.next() == Some('u') {
let hex = &chars.as_str()[..4];
if let Ok(hex) = u32::from_str_radix(hex, 16) {
if (0xd800..=0xdfff).contains(&hex) {
return false;
}
if let Ok(hex) = u32::from_str_radix(hex, 16)
&& (0xd800..=0xdfff).contains(&hex)
{
return false;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_ast/src/ast_impl/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ impl<'a> TSTypeName<'a> {

/// Returns `true` if this is a reference to `const`.
pub fn is_const(&self) -> bool {
if let TSTypeName::IdentifierReference(ident) = self {
if ident.name == "const" {
return true;
}
if let TSTypeName::IdentifierReference(ident) = self
&& ident.name == "const"
{
return true;
}
false
}
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_ast_macros/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ fn modify_struct(item: &mut ItemStruct, args: TokenStream) -> TokenStream {
/// Mutates `item` in place, re-ordering its fields.
fn reorder_struct_fields(item: &mut ItemStruct, args: TokenStream) -> Result<(), &'static str> {
// Skip foreign types
if let Some(TokenTree::Ident(ident)) = args.into_iter().next() {
if ident == "foreign" {
return Ok(());
}
if let Some(TokenTree::Ident(ident)) = args.into_iter().next()
&& ident == "foreign"
{
return Ok(());
}

// Get struct data
Expand Down
9 changes: 4 additions & 5 deletions crates/oxc_cfg/src/builder/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ impl<'a, 'c> QueryCtx<'a, 'c> {

// mark the upper label continue jump point the same as ours if it isn't already assigned,
// NOTE: if it is already assigned there's a resolution before this context.
if let Some(jmp) = continue_jmp {
if let Some(label_ctx @ RefCtxCursor(Ctx { continue_jmp: None, .. })) =
if let Some(jmp) = continue_jmp
&& let Some(label_ctx @ RefCtxCursor(Ctx { continue_jmp: None, .. })) =
self.0.immediate_labeled_ctx()
{
label_ctx.mark_continue(jmp);
}
{
label_ctx.mark_continue(jmp);
}
}

Expand Down
16 changes: 8 additions & 8 deletions crates/oxc_codegen/src/binary_expr_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ impl<'a> BinaryExpressionVisitor<'a> {

match self.operator {
BinaryishOperator::Logical(LogicalOperator::Coalesce) => {
if let Expression::LogicalExpression(logical_expr) = e.left() {
if matches!(logical_expr.operator, LogicalOperator::And | LogicalOperator::Or) {
self.left_precedence = Precedence::Prefix;
}
if let Expression::LogicalExpression(logical_expr) = e.left()
&& matches!(logical_expr.operator, LogicalOperator::And | LogicalOperator::Or)
{
self.left_precedence = Precedence::Prefix;
}
if let Expression::LogicalExpression(logical_expr) = e.right() {
if matches!(logical_expr.operator, LogicalOperator::And | LogicalOperator::Or) {
self.right_precedence = Precedence::Prefix;
}
if let Expression::LogicalExpression(logical_expr) = e.right()
&& matches!(logical_expr.operator, LogicalOperator::And | LogicalOperator::Or)
{
self.right_precedence = Precedence::Prefix;
}
}
BinaryishOperator::Binary(BinaryOperator::Exponential) => {
Expand Down
54 changes: 27 additions & 27 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,10 +945,11 @@ impl Gen for ImportAttribute<'_> {
impl Gen for ExportNamedDeclaration<'_> {
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
p.print_comments_at(self.span.start);
if let Some(Declaration::FunctionDeclaration(func)) = &self.declaration {
if func.pure && p.options.print_annotation_comment() {
p.print_str(NO_SIDE_EFFECTS_NEW_LINE_COMMENT);
}
if let Some(Declaration::FunctionDeclaration(func)) = &self.declaration
&& func.pure
&& p.options.print_annotation_comment()
{
p.print_str(NO_SIDE_EFFECTS_NEW_LINE_COMMENT);
}
p.add_source_mapping(self.span);
p.print_indent();
Expand Down Expand Up @@ -1092,10 +1093,11 @@ impl Gen for ExportAllDeclaration<'_> {
impl Gen for ExportDefaultDeclaration<'_> {
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
p.print_comments_at(self.span.start);
if let ExportDefaultDeclarationKind::FunctionDeclaration(func) = &self.declaration {
if func.pure && p.options.print_annotation_comment() {
p.print_str(NO_SIDE_EFFECTS_NEW_LINE_COMMENT);
}
if let ExportDefaultDeclarationKind::FunctionDeclaration(func) = &self.declaration
&& func.pure
&& p.options.print_annotation_comment()
{
p.print_str(NO_SIDE_EFFECTS_NEW_LINE_COMMENT);
}
p.add_source_mapping(self.span);
p.print_indent();
Expand Down Expand Up @@ -1586,23 +1588,22 @@ impl Gen for ObjectProperty<'_> {
if let PropertyKey::StaticIdentifier(key) = &self.key {
if key.name == "__proto__" {
shorthand = self.shorthand;
} else if let Expression::Identifier(ident) = self.value.without_parentheses() {
if key.name == p.get_identifier_reference_name(ident) {
shorthand = true;
}
} else if let Expression::Identifier(ident) = self.value.without_parentheses()
&& key.name == p.get_identifier_reference_name(ident)
{
shorthand = true;
}
}

let mut computed = self.computed;

// "{ -1: 0 }" must be printed as "{ [-1]: 0 }"
// "{ 1/0: 0 }" must be printed as "{ [1/0]: 0 }"
if !computed {
if let Some(Expression::NumericLiteral(n)) = self.key.as_expression() {
if n.value.is_sign_negative() || n.value.is_infinite() {
computed = true;
}
}
if !computed
&& let Some(Expression::NumericLiteral(n)) = self.key.as_expression()
&& (n.value.is_sign_negative() || n.value.is_infinite())
{
computed = true;
}

if !shorthand {
Expand Down Expand Up @@ -2811,10 +2812,9 @@ impl Gen for BindingProperty<'_> {
BindingPatternKind::AssignmentPattern(assignment_pattern) => {
if let BindingPatternKind::BindingIdentifier(ident) =
&assignment_pattern.left.kind
&& key.name == p.get_binding_identifier_name(ident)
{
if key.name == p.get_binding_identifier_name(ident) {
shorthand = true;
}
shorthand = true;
}
}
_ => {}
Expand Down Expand Up @@ -3205,12 +3205,12 @@ impl Gen for TSTemplateLiteralType<'_> {
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
p.print_str("`");
for (index, item) in self.quasis.iter().enumerate() {
if index != 0 {
if let Some(types) = self.types.get(index - 1) {
p.print_str("${");
types.print(p, ctx);
p.print_str("}");
}
if index != 0
&& let Some(types) = self.types.get(index - 1)
{
p.print_str("${");
types.print(p, ctx);
p.print_str("}");
}
p.print_str(item.value.raw.as_str());
}
Expand Down
91 changes: 46 additions & 45 deletions crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,16 +575,17 @@ impl<'a> Codegen<'a> {

// Ensure first string literal is not a directive.
let mut first_needs_parens = false;
if directives.is_empty() && !self.options.minify {
if let Statement::ExpressionStatement(s) = first {
let s = s.expression.without_parentheses();
if matches!(s, Expression::StringLiteral(_)) {
first_needs_parens = true;
self.print_ascii_byte(b'(');
s.print_expr(self, Precedence::Lowest, ctx);
self.print_ascii_byte(b')');
self.print_semicolon_after_statement();
}
if directives.is_empty()
&& !self.options.minify
&& let Statement::ExpressionStatement(s) = first
{
let s = s.expression.without_parentheses();
if matches!(s, Expression::StringLiteral(_)) {
first_needs_parens = true;
self.print_ascii_byte(b'(');
s.print_expr(self, Precedence::Lowest, ctx);
self.print_ascii_byte(b')');
self.print_semicolon_after_statement();
}
}

Expand Down Expand Up @@ -674,24 +675,23 @@ impl<'a> Codegen<'a> {
}

fn get_identifier_reference_name(&self, reference: &IdentifierReference<'a>) -> &'a str {
if let Some(scoping) = &self.scoping {
if let Some(reference_id) = reference.reference_id.get() {
if let Some(name) = scoping.get_reference_name(reference_id) {
// SAFETY: Hack the lifetime to be part of the allocator.
return unsafe { std::mem::transmute_copy(&name) };
}
}
if let Some(scoping) = &self.scoping
&& let Some(reference_id) = reference.reference_id.get()
&& let Some(name) = scoping.get_reference_name(reference_id)
{
// SAFETY: Hack the lifetime to be part of the allocator.
return unsafe { std::mem::transmute_copy(&name) };
}
reference.name.as_str()
}

fn get_binding_identifier_name(&self, ident: &BindingIdentifier<'a>) -> &'a str {
if let Some(scoping) = &self.scoping {
if let Some(symbol_id) = ident.symbol_id.get() {
let name = scoping.symbol_name(symbol_id);
// SAFETY: Hack the lifetime to be part of the allocator.
return unsafe { std::mem::transmute_copy(&name) };
}
if let Some(scoping) = &self.scoping
&& let Some(symbol_id) = ident.symbol_id.get()
{
let name = scoping.symbol_name(symbol_id);
// SAFETY: Hack the lifetime to be part of the allocator.
return unsafe { std::mem::transmute_copy(&name) };
}
ident.name.as_str()
}
Expand Down Expand Up @@ -800,16 +800,17 @@ impl<'a> Codegen<'a> {
// Check for numbers ending with zeros (but not hex numbers)
// The `!is_hex` check is necessary to prevent hex numbers like `0x8000000000000000`
// from being incorrectly converted to scientific notation
if !is_hex && best_candidate.ends_with('0') {
if let Some(len) = best_candidate.bytes().rev().position(|c| c != b'0') {
let base = &best_candidate[0..best_candidate.len() - len];
let exp_str_len = itoa::Buffer::new().format(len).len();
// Calculate expected length: base + 'e' + len
let expected_len = base.len() + 1 + exp_str_len;
if expected_len < best_candidate.len() {
best_candidate = format!("{base}e{len}").into();
debug_assert_eq!(best_candidate.len(), expected_len);
}
if !is_hex
&& best_candidate.ends_with('0')
&& let Some(len) = best_candidate.bytes().rev().position(|c| c != b'0')
{
let base = &best_candidate[0..best_candidate.len() - len];
let exp_str_len = itoa::Buffer::new().format(len).len();
// Calculate expected length: base + 'e' + len
let expected_len = base.len() + 1 + exp_str_len;
if expected_len < best_candidate.len() {
best_candidate = format!("{base}e{len}").into();
debug_assert_eq!(best_candidate.len(), expected_len);
}
}

Expand All @@ -836,26 +837,26 @@ impl<'a> Codegen<'a> {
}

fn add_source_mapping(&mut self, span: Span) {
if let Some(sourcemap_builder) = self.sourcemap_builder.as_mut() {
if !span.is_empty() {
sourcemap_builder.add_source_mapping(self.code.as_bytes(), span.start, None);
}
if let Some(sourcemap_builder) = self.sourcemap_builder.as_mut()
&& !span.is_empty()
{
sourcemap_builder.add_source_mapping(self.code.as_bytes(), span.start, None);
}
}

fn add_source_mapping_end(&mut self, span: Span) {
if let Some(sourcemap_builder) = self.sourcemap_builder.as_mut() {
if !span.is_empty() {
sourcemap_builder.add_source_mapping(self.code.as_bytes(), span.end, None);
}
if let Some(sourcemap_builder) = self.sourcemap_builder.as_mut()
&& !span.is_empty()
{
sourcemap_builder.add_source_mapping(self.code.as_bytes(), span.end, None);
}
}

fn add_source_mapping_for_name(&mut self, span: Span, name: &str) {
if let Some(sourcemap_builder) = self.sourcemap_builder.as_mut() {
if !span.is_empty() {
sourcemap_builder.add_source_mapping_for_name(self.code.as_bytes(), span, name);
}
if let Some(sourcemap_builder) = self.sourcemap_builder.as_mut()
&& !span.is_empty()
{
sourcemap_builder.add_source_mapping_for_name(self.code.as_bytes(), span, name);
}
}
}
Loading
Loading