Skip to content

Commit

Permalink
chore: run cargo +nightly fmt to sort imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Sep 6, 2024
1 parent 88b7ddb commit d7d4a59
Show file tree
Hide file tree
Showing 149 changed files with 779 additions and 541 deletions.
5 changes: 2 additions & 3 deletions crates/oxc/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use oxc_ast::{ast::Program, Trivias};
use oxc_codegen::{CodeGenerator, CodegenOptions, CommentOptions};
use oxc_diagnostics::OxcDiagnostic;
use oxc_mangler::{MangleOptions, Mangler};
use oxc_parser::{ParseOptions, Parser, ParserReturn};
use oxc_span::SourceType;

use oxc_minifier::{CompressOptions, Compressor};
use oxc_parser::{ParseOptions, Parser, ParserReturn};
use oxc_semantic::{ScopeTree, SemanticBuilder, SemanticBuilderReturn, SymbolTable};
use oxc_span::SourceType;
use oxc_transformer::{TransformOptions, Transformer, TransformerReturn};

#[derive(Default)]
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_allocator/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ impl<'a, T> Box<'a, T> {
mod test {
use std::hash::{DefaultHasher, Hash, Hasher};

use crate::Allocator;

use super::Box;
use crate::Allocator;

#[test]
fn box_deref_mut() {
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_allocator/src/clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ where
T: CloneIn<'alloc, Cloned = C>,
{
type Cloned = Option<C>;

fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
self.as_ref().map(|it| it.clone_in(allocator))
}
Expand All @@ -40,6 +41,7 @@ where
T: CloneIn<'new_alloc, Cloned = C>,
{
type Cloned = Box<'new_alloc, C>;

fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Box::new_in(self.as_ref().clone_in(allocator), allocator)
}
Expand All @@ -50,20 +52,23 @@ where
T: CloneIn<'new_alloc, Cloned = C>,
{
type Cloned = Vec<'new_alloc, C>;

fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Vec::from_iter_in(self.iter().map(|it| it.clone_in(allocator)), allocator)
}
}

impl<'alloc, T: Copy> CloneIn<'alloc> for Cell<T> {
type Cloned = Cell<T>;

fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
Cell::new(self.get())
}
}

impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for &'old_alloc str {
type Cloned = &'new_alloc str;

fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
allocator.alloc_str(self)
}
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_allocator/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ impl<'alloc, T: Hash> Hash for Vec<'alloc, T> {

#[cfg(test)]
mod test {
use crate::Allocator;

use super::Vec;
use crate::Allocator;

#[test]
fn vec_debug() {
Expand Down
6 changes: 2 additions & 4 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ use oxc_syntax::{
scope::ScopeId,
symbol::SymbolId,
};

use super::macros::inherit_variants;
use super::*;

#[cfg(feature = "serialize")]
use serde::Serialize;
#[cfg(feature = "serialize")]
use tsify::Tsify;

use super::{macros::inherit_variants, *};

/// Represents the root of a JavaScript abstract syntax tree (AST), containing metadata about the source, directives, top-level statements, and scope information.
#[ast(visit)]
#[scope(
Expand Down
5 changes: 2 additions & 3 deletions crates/oxc_ast/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ pub(crate) mod macros;
pub(crate) mod ts;

use macros::inherit_variants;

pub use self::{js::*, jsx::*, literal::*, ts::*};

// Re-export AST types from other crates
pub use oxc_span::{Atom, Language, LanguageVariant, ModuleKind, SourceType, Span};
pub use oxc_syntax::{
Expand All @@ -193,3 +190,5 @@ pub use oxc_syntax::{
AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator,
},
};

pub use self::{js::*, jsx::*, literal::*, ts::*};
6 changes: 4 additions & 2 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::ast::*;

use std::{borrow::Cow, cell::Cell, fmt};

use oxc_allocator::{Box, FromIn, Vec};
Expand All @@ -8,6 +6,8 @@ use oxc_syntax::{
operator::UnaryOperator, reference::ReferenceId, scope::ScopeFlags, symbol::SymbolId,
};

use crate::ast::*;

#[cfg(feature = "serialize")]
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
const TS_APPEND_CONTENT: &'static str = r#"
Expand Down Expand Up @@ -1079,6 +1079,7 @@ impl<'a> FormalParameters<'a> {
pub fn is_empty(&self) -> bool {
self.items.is_empty()
}

pub fn has_parameter(&self) -> bool {
!self.is_empty() || self.rest.is_some()
}
Expand Down Expand Up @@ -1427,6 +1428,7 @@ impl<'a> ImportDeclarationSpecifier<'a> {
ImportDeclarationSpecifier::ImportDefaultSpecifier(specifier) => &specifier.local,
}
}

pub fn name(&self) -> Cow<'a, str> {
Cow::Borrowed(self.local().name.as_str())
}
Expand Down
7 changes: 5 additions & 2 deletions crates/oxc_ast/src/ast_impl/jsx.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! [JSX](https://facebook.github.io/jsx)

use crate::ast::*;
use oxc_span::{Atom, Span};
use std::fmt;

use oxc_span::{Atom, Span};

use crate::ast::*;

// 1.2 JSX Elements

impl<'a> JSXIdentifier<'a> {
Expand Down Expand Up @@ -91,6 +93,7 @@ impl<'a> JSXAttributeName<'a> {
Self::NamespacedName(_) => None,
}
}

pub fn get_identifier(&self) -> &JSXIdentifier<'a> {
match self {
Self::Identifier(ident) => ident.as_ref(),
Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_ast/src/ast_impl/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// Silence erroneous warnings from Rust Analyser for `#[derive(Tsify)]`
#![allow(non_snake_case)]

use crate::ast::*;

use std::{
borrow::Cow,
fmt,
Expand All @@ -16,6 +14,8 @@ use oxc_regular_expression::ast::Pattern;
use oxc_span::{cmp::ContentEq, hash::ContentHash, Atom, Span};
use oxc_syntax::number::NumberBase;

use crate::ast::*;

impl BooleanLiteral {
pub fn new(span: Span, value: bool) -> Self {
Self { span, value }
Expand Down Expand Up @@ -187,6 +187,7 @@ impl ContentHash for RegExpFlags {

impl<'alloc> CloneIn<'alloc> for RegExpFlags {
type Cloned = Self;

fn clone_in(&self, _: &'alloc oxc_allocator::Allocator) -> Self::Cloned {
*self
}
Expand Down
7 changes: 2 additions & 5 deletions crates/oxc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ mod generated {
}

pub mod visit {
pub use crate::generated::visit::*;
pub use crate::generated::visit_mut::*;
pub use crate::generated::{visit::*, visit_mut::*};
}

pub use generated::ast_builder;
pub use generated::ast_kind;

pub use generated::{ast_builder, ast_kind};
pub use num_bigint::BigUint;

pub use crate::{
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_codegen/src/annotation_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl AnnotationComment {
pub fn span(&self) -> Span {
self.comment.span
}

pub fn kind(&self) -> CommentKind {
self.comment.kind
}
Expand Down
6 changes: 4 additions & 2 deletions crates/oxc_codegen/src/binary_expr_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
use std::ops::Not;

use oxc_ast::ast::{BinaryExpression, Expression, LogicalExpression};
use oxc_syntax::operator::{BinaryOperator, LogicalOperator};
use oxc_syntax::precedence::{GetPrecedence, Precedence};
use oxc_syntax::{
operator::{BinaryOperator, LogicalOperator},
precedence::{GetPrecedence, Precedence},
};

use crate::{
gen::{Gen, GenExpr},
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use oxc_syntax::{
};
use rustc_hash::FxHashMap;

use self::annotation_comment::AnnotationComment;
use crate::{
binary_expr_visitor::BinaryExpressionVisitor, operator::Operator,
sourcemap_builder::SourcemapBuilder,
Expand All @@ -34,8 +35,6 @@ pub use crate::{
gen::{Gen, GenExpr},
};

use self::annotation_comment::AnnotationComment;

/// Code generator without whitespace removal.
pub type CodeGenerator<'a> = Codegen<'a>;

Expand Down Expand Up @@ -563,6 +562,7 @@ impl<'a> Codegen<'a> {
) -> impl DoubleEndedIterator<Item = &'_ Comment> + '_ {
self.trivias.comments_range(start..end)
}

/// In some scenario, we want to move the comment that should be codegened to another position.
/// ```js
/// /* @__NO_SIDE_EFFECTS__ */ export const a = function() {
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_codegen/src/sourcemap_builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use nonmax::NonMaxU32;

use oxc_index::{Idx, IndexVec};
use oxc_span::Span;
use oxc_syntax::identifier::{LS, PS};
Expand Down
30 changes: 20 additions & 10 deletions crates/oxc_codegen/tests/integration/esbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,16 +990,26 @@ fn test_avoid_slash_script() {
test("/*! </script \n </script */", "/*! <\\/script \n <\\/script */\n");
test("/*! </SCRIPT \n </SCRIPT */", "/*! <\\/SCRIPT \n <\\/SCRIPT */\n");
test("/*! </ScRiPt \n </ScRiPt */", "/*! <\\/ScRiPt \n <\\/ScRiPt */\n");
test( "String.raw`</script`",
"import { __template } from \"<runtime>\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/script\"])));\n");
test( "String.raw`</script${a}`",
"import { __template } from \"<runtime>\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/script\", \"\"])), a);\n");
test( "String.raw`${a}</script`",
"import { __template } from \"<runtime>\";\nvar _a;\nString.raw(_a || (_a = __template([\"\", \"<\\/script\"])), a);\n");
test( "String.raw`</SCRIPT`",
"import { __template } from \"<runtime>\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/SCRIPT\"])));\n");
test( "String.raw`</ScRiPt`",
"import { __template } from \"<runtime>\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/ScRiPt\"])));\n");
test(
"String.raw`</script`",
"import { __template } from \"<runtime>\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/script\"])));\n",
);
test(
"String.raw`</script${a}`",
"import { __template } from \"<runtime>\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/script\", \"\"])), a);\n",
);
test(
"String.raw`${a}</script`",
"import { __template } from \"<runtime>\";\nvar _a;\nString.raw(_a || (_a = __template([\"\", \"<\\/script\"])), a);\n",
);
test(
"String.raw`</SCRIPT`",
"import { __template } from \"<runtime>\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/SCRIPT\"])));\n",
);
test(
"String.raw`</ScRiPt`",
"import { __template } from \"<runtime>\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/ScRiPt\"])));\n",
);

// Negative cases
test("x = '</'", "x = \"</\";\n");
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/tests/integration/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn ts() {
"c = foo<string>;",
"d = x satisfies y;",
"export @x declare abstract class C {}",
"div<T>``"
"div<T>``",
];

let snapshot = cases.into_iter().fold(String::new(), |mut w, case| {
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl Diagnostic for OxcDiagnostic {
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.code.is_some().then(|| Box::new(&self.code) as Box<dyn Display>)
}

fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.url.as_ref().map(Box::new).map(|c| c as Box<dyn Display>)
}
Expand Down
28 changes: 15 additions & 13 deletions crates/oxc_index/src/rayon_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
#![allow(clippy::manual_assert)]
/// Disabled lint since we copy code from https://github.com/rayon-rs/rayon/blob/97c1133c2366a301a2d4ab35cf686bca7f74830f/src/vec.rs#L1-L284
use alloc::vec::Vec;
use core::iter;
use core::mem;
use core::ops::{Range, RangeBounds};
use core::ptr;
use core::slice;
use rayon::iter::plumbing::{bridge, Consumer, Producer, ProducerCallback, UnindexedConsumer};
use rayon::iter::{
IndexedParallelIterator, IntoParallelIterator, ParallelDrainRange, ParallelIterator,
use core::{
iter, mem,
ops::{Range, RangeBounds},
ptr, slice,
};
use rayon::slice::{Iter, IterMut};

use crate::Idx;
use crate::IndexVec;
use rayon::{
iter::{
plumbing::{bridge, Consumer, Producer, ProducerCallback, UnindexedConsumer},
IndexedParallelIterator, IntoParallelIterator, ParallelDrainRange, ParallelIterator,
},
slice::{Iter, IterMut},
};

use crate::{Idx, IndexVec};

impl<'data, I: Idx, T: Sync + 'data> IntoParallelIterator for &'data IndexVec<I, T> {
type Item = &'data T;
Expand Down Expand Up @@ -87,8 +89,8 @@ impl<T: Send> IndexedParallelIterator for IntoIter<T> {
}

impl<'data, I: Idx, T: Send> ParallelDrainRange<usize> for &'data mut IndexVec<I, T> {
type Iter = Drain<'data, T>;
type Item = T;
type Iter = Drain<'data, T>;

fn par_drain<R: RangeBounds<usize>>(self, range: R) -> Self::Iter {
Drain { orig_len: self.len(), range: simplify_range(range, self.len()), vec: &mut self.raw }
Expand Down Expand Up @@ -202,8 +204,8 @@ impl<T: Send> DrainProducer<'_, T> {
}

impl<'data, T: 'data + Send> Producer for DrainProducer<'data, T> {
type Item = T;
type IntoIter = SliceDrain<'data, T>;
type Item = T;

fn into_iter(mut self) -> Self::IntoIter {
// replace the slice so we don't drop it twice
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_isolated_declarations/tests/deno/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ export function foo(a: any): number {
);

transform_dts_test(
"export const foo = { str: \"bar\", bool: true, bool2: false, num: 42, nullish: null } as const;",
"export declare const foo: {
"export const foo = { str: \"bar\", bool: true, bool2: false, num: 42, nullish: null } as const;",
"export declare const foo: {
readonly str: \"bar\";
readonly bool: true;
readonly bool2: false;
readonly num: 42;
readonly nullish: null;
};",
);
);

transform_dts_test(
"export const foo = { str: [1, 2] as const } as const;",
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_linter/src/ast_util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::hash::Hasher;

use oxc_ast::ast::BindingIdentifier;
use oxc_ast::AstKind;
use oxc_ast::{ast::BindingIdentifier, AstKind};
use oxc_semantic::{AstNode, AstNodeId, SymbolId};
use oxc_span::{hash::ContentHash, GetSpan, Span};
use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator};
Expand Down
Loading

0 comments on commit d7d4a59

Please sign in to comment.