Skip to content

Commit cf86daa

Browse files
committed
chore(rust): change indentation to tabs
The 4 spaces indentation uses too much screen width in the deep indentation of transforming, and with tabs people can configure their own visible width.
1 parent bfd433d commit cf86daa

24 files changed

+6040
-6041
lines changed

packages/qwik/src/napi/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
extern crate napi_build;
22

33
fn main() {
4-
napi_build::setup();
4+
napi_build::setup();
55
}

packages/qwik/src/napi/src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
1515
#[allow(clippy::needless_pass_by_value)]
1616
#[js_function(1)]
1717
fn transform_fs(ctx: CallContext) -> Result<JsUnknown> {
18-
let opts = ctx.get::<JsObject>(0)?;
19-
let config: qwik_core::TransformFsOptions = ctx.env.from_js_value(opts)?;
18+
let opts = ctx.get::<JsObject>(0)?;
19+
let config: qwik_core::TransformFsOptions = ctx.env.from_js_value(opts)?;
2020

21-
let result = qwik_core::transform_fs(config).unwrap();
22-
ctx.env.to_js_value(&result)
21+
let result = qwik_core::transform_fs(config).unwrap();
22+
ctx.env.to_js_value(&result)
2323
}
2424

2525
#[allow(clippy::needless_pass_by_value)]
2626
#[js_function(1)]
2727
fn transform_modules(ctx: CallContext) -> Result<JsUnknown> {
28-
let opts = ctx.get::<JsObject>(0)?;
29-
let config: qwik_core::TransformModulesOptions = ctx.env.from_js_value(opts)?;
28+
let opts = ctx.get::<JsObject>(0)?;
29+
let config: qwik_core::TransformModulesOptions = ctx.env.from_js_value(opts)?;
3030

31-
let result = qwik_core::transform_modules(config).unwrap();
32-
ctx.env.to_js_value(&result)
31+
let result = qwik_core::transform_modules(config).unwrap();
32+
ctx.env.to_js_value(&result)
3333
}
3434

3535
#[module_exports]
3636
fn init(mut exports: JsObject) -> Result<()> {
37-
exports.create_named_method("transform_fs", transform_fs)?;
38-
exports.create_named_method("transform_modules", transform_modules)?;
37+
exports.create_named_method("transform_fs", transform_fs)?;
38+
exports.create_named_method("transform_modules", transform_modules)?;
3939

40-
Ok(())
40+
Ok(())
4141
}

packages/qwik/src/optimizer/cli/src/main.rs

+86-86
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ use path_absolutize::Absolutize;
99
use qwik_core::{transform_fs, EmitMode, EntryStrategy, MinifyMode, TransformFsOptions};
1010

1111
struct OptimizerInput {
12-
glob: Option<String>,
13-
manifest: Option<String>,
14-
core_module: Option<String>,
15-
scope: Option<String>,
16-
src: PathBuf,
17-
dest: PathBuf,
18-
mode: EmitMode,
19-
strategy: EntryStrategy,
20-
transpile_ts: bool,
21-
transpile_jsx: bool,
22-
preserve_filenames: bool,
23-
minify: MinifyMode,
24-
sourcemaps: bool,
25-
explicit_extensions: bool,
12+
glob: Option<String>,
13+
manifest: Option<String>,
14+
core_module: Option<String>,
15+
scope: Option<String>,
16+
src: PathBuf,
17+
dest: PathBuf,
18+
mode: EmitMode,
19+
strategy: EntryStrategy,
20+
transpile_ts: bool,
21+
transpile_jsx: bool,
22+
preserve_filenames: bool,
23+
minify: MinifyMode,
24+
sourcemaps: bool,
25+
explicit_extensions: bool,
2626
}
2727

2828
fn main() -> Result<(), Box<dyn std::error::Error>> {
29-
let matches = Command::new("qwik")
29+
let matches = Command::new("qwik")
3030
.version("1.0")
3131
.arg_required_else_help(true)
3232
.subcommand_required(true)
@@ -85,85 +85,85 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
8585
)
8686
.get_matches();
8787

88-
// You can check for the existence of subcommands, and if found use their
89-
// matches just as you would the top level app
90-
if let Some(matches) = matches.subcommand_matches("optimize") {
91-
// "$ myapp test" was run
92-
let strategy = match matches.value_of("strategy") {
93-
Some("inline") => EntryStrategy::Inline,
94-
Some("hook") => EntryStrategy::Hook,
95-
Some("single") => EntryStrategy::Single,
96-
Some("component") => EntryStrategy::Component,
97-
Some("smart") | None => EntryStrategy::Smart,
98-
_ => panic!("Invalid strategy option"),
99-
};
88+
// You can check for the existence of subcommands, and if found use their
89+
// matches just as you would the top level app
90+
if let Some(matches) = matches.subcommand_matches("optimize") {
91+
// "$ myapp test" was run
92+
let strategy = match matches.value_of("strategy") {
93+
Some("inline") => EntryStrategy::Inline,
94+
Some("hook") => EntryStrategy::Hook,
95+
Some("single") => EntryStrategy::Single,
96+
Some("component") => EntryStrategy::Component,
97+
Some("smart") | None => EntryStrategy::Smart,
98+
_ => panic!("Invalid strategy option"),
99+
};
100100

101-
let minify = match matches.value_of("minify") {
102-
Some("none") => MinifyMode::None,
103-
Some("simplify") | None => MinifyMode::Simplify,
104-
_ => panic!("Invalid minify option"),
105-
};
101+
let minify = match matches.value_of("minify") {
102+
Some("none") => MinifyMode::None,
103+
Some("simplify") | None => MinifyMode::Simplify,
104+
_ => panic!("Invalid minify option"),
105+
};
106106

107-
let mode = match matches.value_of("mode") {
108-
Some("dev") => EmitMode::Dev,
109-
Some("prod") => EmitMode::Prod,
110-
Some("lib") | None => EmitMode::Lib,
111-
_ => panic!("Invalid mode option"),
112-
};
113-
optimize(OptimizerInput {
114-
src: matches.value_of_t_or_exit("src"),
115-
dest: matches.value_of_t_or_exit("dest"),
116-
manifest: matches.value_of("manifest").map(|s| s.into()),
117-
core_module: matches.value_of("core_module").map(|s| s.into()),
118-
scope: matches.value_of("scope").map(|s| s.into()),
119-
mode,
120-
glob: None,
121-
strategy,
122-
minify,
123-
explicit_extensions: matches.is_present("extensions"),
124-
transpile_jsx: !matches.is_present("no-jsx"),
125-
transpile_ts: !matches.is_present("no-ts"),
126-
preserve_filenames: matches.is_present("preserve-filenames"),
127-
sourcemaps: matches.is_present("sourcemaps"),
128-
})?;
129-
}
130-
Ok(())
107+
let mode = match matches.value_of("mode") {
108+
Some("dev") => EmitMode::Dev,
109+
Some("prod") => EmitMode::Prod,
110+
Some("lib") | None => EmitMode::Lib,
111+
_ => panic!("Invalid mode option"),
112+
};
113+
optimize(OptimizerInput {
114+
src: matches.value_of_t_or_exit("src"),
115+
dest: matches.value_of_t_or_exit("dest"),
116+
manifest: matches.value_of("manifest").map(|s| s.into()),
117+
core_module: matches.value_of("core_module").map(|s| s.into()),
118+
scope: matches.value_of("scope").map(|s| s.into()),
119+
mode,
120+
glob: None,
121+
strategy,
122+
minify,
123+
explicit_extensions: matches.is_present("extensions"),
124+
transpile_jsx: !matches.is_present("no-jsx"),
125+
transpile_ts: !matches.is_present("no-ts"),
126+
preserve_filenames: matches.is_present("preserve-filenames"),
127+
sourcemaps: matches.is_present("sourcemaps"),
128+
})?;
129+
}
130+
Ok(())
131131
}
132132

133133
fn optimize(
134-
optimizer_input: OptimizerInput,
134+
optimizer_input: OptimizerInput,
135135
) -> Result<qwik_core::TransformOutput, Box<dyn std::error::Error>> {
136-
let current_dir = std::env::current_dir()?;
137-
let src_dir = current_dir.join(optimizer_input.src).canonicalize()?;
136+
let current_dir = std::env::current_dir()?;
137+
let src_dir = current_dir.join(optimizer_input.src).canonicalize()?;
138138

139-
let result = transform_fs(TransformFsOptions {
140-
src_dir: src_dir.to_string_lossy().to_string(),
141-
vendor_roots: vec![],
142-
glob: optimizer_input.glob,
143-
source_maps: optimizer_input.sourcemaps,
144-
minify: optimizer_input.minify,
145-
transpile_jsx: optimizer_input.transpile_jsx,
146-
transpile_ts: optimizer_input.transpile_ts,
147-
preserve_filenames: optimizer_input.preserve_filenames,
148-
entry_strategy: optimizer_input.strategy,
149-
explicit_extensions: optimizer_input.explicit_extensions,
150-
core_module: optimizer_input.core_module,
151-
root_dir: None,
139+
let result = transform_fs(TransformFsOptions {
140+
src_dir: src_dir.to_string_lossy().to_string(),
141+
vendor_roots: vec![],
142+
glob: optimizer_input.glob,
143+
source_maps: optimizer_input.sourcemaps,
144+
minify: optimizer_input.minify,
145+
transpile_jsx: optimizer_input.transpile_jsx,
146+
transpile_ts: optimizer_input.transpile_ts,
147+
preserve_filenames: optimizer_input.preserve_filenames,
148+
entry_strategy: optimizer_input.strategy,
149+
explicit_extensions: optimizer_input.explicit_extensions,
150+
core_module: optimizer_input.core_module,
151+
root_dir: None,
152152

153-
mode: optimizer_input.mode,
154-
scope: optimizer_input.scope,
153+
mode: optimizer_input.mode,
154+
scope: optimizer_input.scope,
155155

156-
manual_chunks: None,
157-
strip_exports: None,
158-
strip_ctx_name: None,
159-
strip_event_handlers: false,
160-
reg_ctx_name: None,
161-
is_server: None,
162-
})?;
156+
manual_chunks: None,
157+
strip_exports: None,
158+
strip_ctx_name: None,
159+
strip_event_handlers: false,
160+
reg_ctx_name: None,
161+
is_server: None,
162+
})?;
163163

164-
result.write_to_fs(
165-
&current_dir.join(optimizer_input.dest).absolutize()?,
166-
optimizer_input.manifest,
167-
)?;
168-
Ok(result)
164+
result.write_to_fs(
165+
&current_dir.join(optimizer_input.dest).absolutize()?,
166+
optimizer_input.manifest,
167+
)?;
168+
Ok(result)
169169
}

packages/qwik/src/optimizer/core/benches/transform.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use test::Bencher;
77

88
#[bench]
99
fn transform_todo_app(b: &mut Bencher) {
10-
b.iter(|| {
10+
b.iter(|| {
1111
let code = r#"
1212
import {
1313
Fragment,

packages/qwik/src/optimizer/core/src/add_side_effect.rs

+45-45
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,56 @@ use swc_ecmascript::ast;
1010
use swc_ecmascript::visit::{VisitMut, VisitMutWith};
1111

1212
pub struct SideEffectVisitor<'a> {
13-
global_collector: &'a GlobalCollect,
14-
imports: HashSet<JsWord>,
15-
path_data: &'a PathData,
16-
src_dir: &'a Path,
13+
global_collector: &'a GlobalCollect,
14+
imports: HashSet<JsWord>,
15+
path_data: &'a PathData,
16+
src_dir: &'a Path,
1717
}
1818

1919
impl<'a> SideEffectVisitor<'a> {
20-
pub fn new(
21-
global_collector: &'a GlobalCollect,
22-
path_data: &'a PathData,
23-
src_dir: &'a Path,
24-
) -> Self {
25-
Self {
26-
global_collector,
27-
path_data,
28-
src_dir,
29-
imports: HashSet::new(),
30-
}
31-
}
20+
pub fn new(
21+
global_collector: &'a GlobalCollect,
22+
path_data: &'a PathData,
23+
src_dir: &'a Path,
24+
) -> Self {
25+
Self {
26+
global_collector,
27+
path_data,
28+
src_dir,
29+
imports: HashSet::new(),
30+
}
31+
}
3232
}
3333

3434
impl<'a> VisitMut for SideEffectVisitor<'a> {
35-
fn visit_mut_import_decl(&mut self, node: &mut ast::ImportDecl) {
36-
if node.src.value.starts_with('.') {
37-
self.imports.insert(node.src.value.clone());
38-
}
39-
}
40-
fn visit_mut_module(&mut self, node: &mut ast::Module) {
41-
node.visit_mut_children_with(self);
42-
let mut imports: Vec<_> = self.global_collector.imports.values().collect();
43-
imports.sort_by_key(|i| i.source.clone());
35+
fn visit_mut_import_decl(&mut self, node: &mut ast::ImportDecl) {
36+
if node.src.value.starts_with('.') {
37+
self.imports.insert(node.src.value.clone());
38+
}
39+
}
40+
fn visit_mut_module(&mut self, node: &mut ast::Module) {
41+
node.visit_mut_children_with(self);
42+
let mut imports: Vec<_> = self.global_collector.imports.values().collect();
43+
imports.sort_by_key(|i| i.source.clone());
4444

45-
for import in imports {
46-
if import.source.starts_with('.') && !self.imports.contains(&import.source) {
47-
let abs_dir = self.path_data.abs_dir.to_slash_lossy();
48-
let relative = relative_path::RelativePath::new(&abs_dir);
49-
let final_path = relative.join(import.source.as_ref()).normalize();
50-
if final_path.starts_with(self.src_dir.to_str().unwrap()) {
51-
node.body.insert(
52-
0,
53-
ast::ModuleItem::ModuleDecl(ast::ModuleDecl::Import(ast::ImportDecl {
54-
asserts: None,
55-
span: DUMMY_SP,
56-
specifiers: vec![],
57-
type_only: false,
58-
src: Box::new(ast::Str::from(import.source.clone())),
59-
})),
60-
);
61-
}
62-
}
63-
}
64-
}
45+
for import in imports {
46+
if import.source.starts_with('.') && !self.imports.contains(&import.source) {
47+
let abs_dir = self.path_data.abs_dir.to_slash_lossy();
48+
let relative = relative_path::RelativePath::new(&abs_dir);
49+
let final_path = relative.join(import.source.as_ref()).normalize();
50+
if final_path.starts_with(self.src_dir.to_str().unwrap()) {
51+
node.body.insert(
52+
0,
53+
ast::ModuleItem::ModuleDecl(ast::ModuleDecl::Import(ast::ImportDecl {
54+
asserts: None,
55+
span: DUMMY_SP,
56+
specifiers: vec![],
57+
type_only: false,
58+
src: Box::new(ast::Str::from(import.source.clone())),
59+
})),
60+
);
61+
}
62+
}
63+
}
64+
}
6565
}

0 commit comments

Comments
 (0)