Skip to content

Commit

Permalink
refactor(transformer): reorder imports (#6582)
Browse files Browse the repository at this point in the history
Re-order `use` statements in order:

1. `std`
2. External crates
3. `oxc_*` crates
4. Current crate `use crate::...`
5. Super `use super::...`
6. Local modules

This order is from "furthest away" to "closest". This makes it clearer to see what is coming from where.
  • Loading branch information
overlookmotel committed Oct 15, 2024
1 parent c5e66e1 commit 8c6afe0
Show file tree
Hide file tree
Showing 30 changed files with 112 additions and 84 deletions.
6 changes: 4 additions & 2 deletions crates/oxc_transformer/src/common/helper_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@
//! ```
//!
//! Based on [@babel/helper](https://github.com/babel/babel/tree/main/packages/babel-helpers).

use std::{borrow::Cow, cell::RefCell};

use rustc_hash::FxHashMap;
use serde::Deserialize;

use oxc_allocator::Vec;
use oxc_ast::ast::{Argument, CallExpression, Expression, Program, TSTypeParameterInstantiation};
use oxc_semantic::{ReferenceFlags, SymbolFlags};
use oxc_span::{Atom, SPAN};
use oxc_traverse::{BoundIdentifier, Traverse, TraverseCtx};
use rustc_hash::FxHashMap;
use serde::Deserialize;

use crate::TransformCtx;

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/env/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod babel;

pub use self::babel::can_enable_plugin;
pub use babel::can_enable_plugin;
8 changes: 3 additions & 5 deletions crates/oxc_transformer/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ mod data;
mod options;
mod targets;

pub use self::{
data::can_enable_plugin,
options::EnvOptions,
targets::{Targets, Versions},
};
pub use data::can_enable_plugin;
pub use options::EnvOptions;
pub use targets::{Targets, Versions};
3 changes: 2 additions & 1 deletion crates/oxc_transformer/src/env/options.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use oxc_diagnostics::Error;
use serde::Deserialize;
use serde_json::Value;

use oxc_diagnostics::Error;

use super::targets::{query::Targets, Versions};

fn default_as_true() -> bool {
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_transformer/src/env/targets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use std::ops::{Deref, DerefMut};
use rustc_hash::FxHashMap;
use serde::Deserialize;

pub use self::query::Targets;
use self::version::Version;
pub mod query;
pub mod version;
pub use query::Targets;
use version::Version;

/// A map of browser names to data for feature support in browser.
///
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_transformer/src/env/targets/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
use std::sync::OnceLock;

use dashmap::DashMap;
use oxc_diagnostics::{Error, OxcDiagnostic};
use rustc_hash::FxHashMap;
use serde::Deserialize;

use oxc_diagnostics::{Error, OxcDiagnostic};

use super::{version::Version, Versions};

#[derive(Debug, Clone, Deserialize)]
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_transformer/src/es2015/arrow_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
//! * Babel plugin implementation: <https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-arrow-functions>
//! * Arrow function specification: <https://tc39.es/ecma262/#sec-arrow-function-definitions>

use serde::Deserialize;

use oxc_allocator::Vec;
use oxc_ast::{ast::*, NONE};
use oxc_data_structures::stack::SparseStack;
Expand All @@ -134,8 +136,6 @@ use oxc_syntax::{
};
use oxc_traverse::{Ancestor, BoundIdentifier, Traverse, TraverseCtx};

use serde::Deserialize;

#[derive(Debug, Default, Clone, Deserialize)]
pub struct ArrowFunctionsOptions {
/// This option enables the following:
Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_transformer/src/es2015/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

mod arrow_functions;
mod options;

pub use arrow_functions::{ArrowFunctions, ArrowFunctionsOptions};
pub use options::ES2015Options;
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

pub struct ES2015<'a> {
options: ES2015Options,
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_transformer/src/es2015/options.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use serde::Deserialize;

use super::ArrowFunctionsOptions;
use crate::env::{can_enable_plugin, Versions};

use super::ArrowFunctionsOptions;

#[derive(Debug, Default, Clone, Deserialize)]
#[serde(default, rename_all = "camelCase", deny_unknown_fields)]
pub struct ES2015Options {
Expand Down
9 changes: 5 additions & 4 deletions crates/oxc_transformer/src/es2016/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

use crate::TransformCtx;

mod exponentiation_operator;
mod options;

pub use exponentiation_operator::ExponentiationOperator;
pub use options::ES2016Options;
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

use crate::TransformCtx;

pub struct ES2016<'a, 'ctx> {
options: ES2016Options,
Expand Down
12 changes: 7 additions & 5 deletions crates/oxc_transformer/src/es2017/async_to_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@
//! * Async / Await TC39 proposal: <https://github.com/tc39/proposal-async-await>
//!

use oxc_ast::ast::{
ArrowFunctionExpression, Expression, Function, FunctionType, Statement, VariableDeclarationKind,
use oxc_ast::{
ast::{
ArrowFunctionExpression, Expression, Function, FunctionType, Statement,
VariableDeclarationKind,
},
NONE,
};
use oxc_ast::NONE;
use oxc_span::{Atom, SPAN};
use oxc_syntax::reference::ReferenceFlags;
use oxc_syntax::symbol::SymbolId;
use oxc_syntax::{reference::ReferenceFlags, symbol::SymbolId};
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};

pub struct AsyncToGenerator;
Expand Down
9 changes: 5 additions & 4 deletions crates/oxc_transformer/src/es2017/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
mod async_to_generator;
pub mod options;
use oxc_ast::ast::{ArrowFunctionExpression, Expression, Statement};
use oxc_traverse::{Traverse, TraverseCtx};

use crate::es2017::async_to_generator::AsyncToGenerator;
use crate::es2017::options::ES2017Options;
use oxc_ast::ast::{ArrowFunctionExpression, Expression, Statement};
use oxc_traverse::{Traverse, TraverseCtx};

mod async_to_generator;
pub mod options;

#[allow(dead_code)]
pub struct ES2017 {
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_transformer/src/es2017/options.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::env::{can_enable_plugin, Versions};
use serde::Deserialize;

use crate::env::{can_enable_plugin, Versions};

#[derive(Debug, Default, Clone, Deserialize)]
#[serde(default, rename_all = "camelCase", deny_unknown_fields)]
pub struct ES2017Options {
Expand Down
9 changes: 5 additions & 4 deletions crates/oxc_transformer/src/es2018/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

use crate::context::TransformCtx;

mod object_rest_spread;
mod options;

pub use object_rest_spread::{ObjectRestSpread, ObjectRestSpreadOptions};
pub use options::ES2018Options;
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

use crate::context::TransformCtx;

pub struct ES2018<'a, 'ctx> {
options: ES2018Options,
Expand Down
7 changes: 4 additions & 3 deletions crates/oxc_transformer/src/es2018/object_rest_spread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@
//! * Babel plugin implementation: <https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-object-rest-spread>
//! * Object rest/spread TC39 proposal: <https://github.com/tc39/proposal-object-rest-spread>

use object_rest::ObjectRest;
use object_spread::ObjectSpread;
use serde::Deserialize;

use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};
use serde::Deserialize;

use crate::context::TransformCtx;

mod object_rest;
mod object_spread;
use object_rest::ObjectRest;
use object_spread::ObjectSpread;

#[derive(Debug, Default, Clone, Copy, Deserialize)]
#[serde(default, rename_all = "camelCase")]
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_transformer/src/es2018/options.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use serde::Deserialize;

use super::ObjectRestSpreadOptions;
use crate::env::{can_enable_plugin, Versions};

use super::ObjectRestSpreadOptions;

#[derive(Debug, Default, Clone, Deserialize)]
#[serde(default, rename_all = "camelCase", deny_unknown_fields)]
pub struct ES2018Options {
Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_transformer/src/es2019/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

mod optional_catch_binding;
mod options;

pub use optional_catch_binding::OptionalCatchBinding;
pub use options::ES2019Options;
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

pub struct ES2019 {
options: ES2019Options,
Expand Down
9 changes: 5 additions & 4 deletions crates/oxc_transformer/src/es2020/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

use crate::TransformCtx;

mod nullish_coalescing_operator;
mod options;

pub use nullish_coalescing_operator::NullishCoalescingOperator;
pub use options::ES2020Options;
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

use crate::TransformCtx;

pub struct ES2020<'a, 'ctx> {
options: ES2020Options,
Expand Down
9 changes: 5 additions & 4 deletions crates/oxc_transformer/src/es2021/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

use crate::TransformCtx;

mod logical_assignment_operators;
mod options;

pub use logical_assignment_operators::LogicalAssignmentOperators;
pub use options::ES2021Options;
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};

use crate::TransformCtx;

pub struct ES2021<'a, 'ctx> {
options: ES2021Options,
Expand Down
22 changes: 12 additions & 10 deletions crates/oxc_transformer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
//! * <https://babel.dev/docs/presets>
//! * <https://github.com/microsoft/TypeScript/blob/main/src/compiler/transformer.ts>

use oxc_ast::AstBuilder;
use std::path::Path;

use oxc_allocator::{Allocator, Vec};
use oxc_ast::{ast::*, AstBuilder};
use oxc_diagnostics::OxcDiagnostic;
use oxc_semantic::{ScopeTree, SymbolTable};
use oxc_span::SPAN;
use oxc_traverse::{traverse_mut, Traverse, TraverseCtx};

// Core
mod common;
Expand All @@ -30,22 +37,18 @@ mod typescript;

mod plugins;

use std::path::Path;

use common::Common;
use context::TransformCtx;
use es2015::ES2015;
use es2016::ES2016;
use es2017::ES2017;
use es2018::ES2018;
use es2019::ES2019;
use es2020::ES2020;
use es2021::ES2021;
use oxc_allocator::{Allocator, Vec};
use oxc_ast::ast::*;
use oxc_diagnostics::OxcDiagnostic;
use oxc_semantic::{ScopeTree, SymbolTable};
use oxc_span::SPAN;
use oxc_traverse::{traverse_mut, Traverse, TraverseCtx};
use react::React;
use regexp::RegExp;
use typescript::TypeScript;

pub use crate::{
compiler_assumptions::CompilerAssumptions,
Expand All @@ -56,7 +59,6 @@ pub use crate::{
react::{JsxOptions, JsxRuntime, ReactRefreshOptions},
typescript::{RewriteExtensionsMode, TypeScriptOptions},
};
use crate::{context::TransformCtx, es2015::ES2015, react::React, typescript::TypeScript};

pub struct TransformerReturn {
pub errors: std::vec::Vec<OxcDiagnostic>,
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_transformer/src/options/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod babel;
mod transformer;

pub use self::{babel::BabelOptions, transformer::TransformOptions};
pub use babel::BabelOptions;
pub use transformer::TransformOptions;
3 changes: 2 additions & 1 deletion crates/oxc_transformer/src/options/transformer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::path::PathBuf;

use oxc_diagnostics::{Error, OxcDiagnostic};
use serde_json::{from_value, json, Value};

use oxc_diagnostics::{Error, OxcDiagnostic};

use crate::{
common::helper_loader::{HelperLoaderMode, HelperLoaderOptions},
compiler_assumptions::CompilerAssumptions,
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_transformer/src/react/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ use oxc_traverse::{BoundIdentifier, Traverse, TraverseCtx};
use crate::TransformCtx;

use super::diagnostics;

pub use super::{
jsx_self::ReactJsxSelf,
jsx_source::ReactJsxSource,
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_transformer/src/react/jsx_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
//!
//! * Babel plugin implementation: <https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-react-jsx-source/src/index.ts>

use ropey::Rope;

use oxc_ast::{ast::*, NONE};
use oxc_diagnostics::OxcDiagnostic;
use oxc_span::{Span, SPAN};
use oxc_syntax::{number::NumberBase, symbol::SymbolFlags};
use oxc_traverse::{BoundIdentifier, Traverse, TraverseCtx};
use ropey::Rope;

use crate::TransformCtx;

Expand Down
Loading

0 comments on commit 8c6afe0

Please sign in to comment.