Skip to content

Commit df37c17

Browse files
chore(format)
Signed-off-by: Nikola Hristov <Nikola@PlayForm.Cloud>
1 parent 5111ff4 commit df37c17

6 files changed

Lines changed: 75 additions & 66 deletions

File tree

Source/Fn/Binary/Command/Parallel.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ pub async fn Fn(Option { Entry, Separator, Pattern, .. }:Option) {
4343

4444
let Queue = futures::stream::FuturesUnordered::new();
4545

46-
let glob = globset::Glob::new(&Pattern)
47-
.expect("Invalid pattern")
48-
.compile_matcher();
46+
let glob = globset::Glob::new(&Pattern).expect("Invalid pattern").compile_matcher();
4947

5048
for Entry in Entry
5149
.into_par_iter()

Source/Fn/Build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub async fn Fn(_Entry:&str) -> Result<DashMap<u64, (String, String)>, Box<dyn s
77
}
88

99
pub mod Group {
10-
pub fn Fn(output: Vec<(String, String)>) {
10+
pub fn Fn(output:Vec<(String, String)>) {
1111
println!("Processed {} files", output.len());
1212
}
1313
}

Source/Fn/SWC.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
async fn Fn() -> anyhow::Result<()> {
33
tracing_subscriber::fmt::init();
44

5-
let args: Vec<String> = std::env::args().collect();
5+
let args:Vec<String> = std::env::args().collect();
66

77
if args.len() != 2 {
88
error!("Usage: {} <directory>", args[0]);
@@ -18,10 +18,10 @@ async fn Fn() -> anyhow::Result<()> {
1818
};
1919

2020
let options = Option {
21-
entry: vec![vec![Path.to_string_lossy().to_string()]],
22-
separator: std::path::MAIN_SEPARATOR,
23-
pattern: ".ts".to_string(),
24-
config: Config.clone(),
21+
entry:vec![vec![Path.to_string_lossy().to_string()]],
22+
separator:std::path::MAIN_SEPARATOR,
23+
pattern:".ts".to_string(),
24+
config:Config.clone(),
2525
};
2626

2727
// Initial compilation
@@ -41,4 +41,5 @@ pub mod Watch;
4141

4242
use tokio::fs;
4343
use tracing::{error, info};
44+
4445
use crate::Struct::SWC::{CompilerConfig, Option};

Source/Fn/SWC/Watch.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod Compile;
22

33
#[tracing::instrument]
4-
pub async fn Fn(Path: PathBuf, Option: Option) -> anyhow::Result<()> {
4+
pub async fn Fn(Path:PathBuf, Option:Option) -> anyhow::Result<()> {
55
let (tx, mut rx) = mpsc::unbounded_channel();
66

77
let mut watcher = notify::RecommendedWatcher::new(
@@ -12,7 +12,7 @@ pub async fn Fn(Path: PathBuf, Option: Option) -> anyhow::Result<()> {
1212
},
1313
notify::Config::default(),
1414
)?;
15-
15+
1616
use notify::Watcher; // trait import
1717
watcher.watch(Path.as_ref(), notify::RecursiveMode::Recursive)?;
1818

@@ -32,7 +32,7 @@ pub async fn Fn(Path: PathBuf, Option: Option) -> anyhow::Result<()> {
3232
let rt = tokio::runtime::Handle::current();
3333
rt.block_on(async {
3434
if let Err(e) = Compile::Fn(crate::Struct::SWC::Option {
35-
entry: vec![vec![path.to_string_lossy().to_string()]],
35+
entry:vec![vec![path.to_string_lossy().to_string()]],
3636
..Option
3737
})
3838
.await
@@ -53,6 +53,8 @@ pub async fn Fn(Path: PathBuf, Option: Option) -> anyhow::Result<()> {
5353
}
5454

5555
use std::path::PathBuf;
56+
5657
use tokio::sync::mpsc;
5758
use tracing::error;
59+
5860
use crate::Struct::SWC::Option;

Source/Fn/SWC/Watch/Compile.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[tracing::instrument(skip(Option))]
2-
pub async fn Fn(Option: super::Option) -> anyhow::Result<()> {
2+
pub async fn Fn(Option:super::Option) -> anyhow::Result<()> {
33
let (Allow, mut Mark) = mpsc::unbounded_channel();
44
let Queue = FuturesUnordered::new();
55
let Compiler = Arc::new(crate::Struct::SWC::Compiler::new(Option.config.clone()));
@@ -23,30 +23,30 @@ pub async fn Fn(Option: super::Option) -> anyhow::Result<()> {
2323
Ok(input) => {
2424
// Use spawn_blocking for CPU-intensive compilation
2525
let file_clone = file.clone();
26-
let result = tokio::task::spawn_blocking(move || {
27-
Compiler.compile_file(&file_clone, input)
28-
}).await;
26+
let result = tokio::task::spawn_blocking(move || Compiler.compile_file(&file_clone, input)).await;
2927

3028
match result {
31-
Ok(inner_result) => match inner_result {
32-
Ok(output) => {
33-
if let Err(e) = Allow.send((file.clone(), Ok(output))) {
34-
error!("Cannot send compilation result: {}", e);
35-
}
36-
},
37-
Err(e) => {
38-
error!("Compilation error for {}: {}", file, e);
39-
if let Err(e) = Allow.send((file.clone(), Err(e))) {
40-
error!("Cannot send compilation error: {}", e);
41-
}
42-
},
29+
Ok(inner_result) => {
30+
match inner_result {
31+
Ok(output) => {
32+
if let Err(e) = Allow.send((file.clone(), Ok(output))) {
33+
error!("Cannot send compilation result: {}", e);
34+
}
35+
},
36+
Err(e) => {
37+
error!("Compilation error for {}: {}", file, e);
38+
if let Err(e) = Allow.send((file.clone(), Err(e))) {
39+
error!("Cannot send compilation error: {}", e);
40+
}
41+
},
42+
}
4343
},
4444
Err(join_err) => {
4545
error!("Task join error for {}: {}", file, join_err);
4646
if let Err(e) = Allow.send((file.clone(), Err(anyhow::anyhow!(join_err)))) {
4747
error!("Cannot send join error: {}", e);
4848
}
49-
}
49+
},
5050
}
5151
},
5252
Err(e) => {
@@ -91,6 +91,7 @@ pub async fn Fn(Option: super::Option) -> anyhow::Result<()> {
9191
}
9292

9393
use std::sync::Arc;
94+
9495
use futures::stream::{FuturesUnordered, StreamExt};
9596
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
9697
use tokio::sync::mpsc;

Source/Struct/SWC.rs

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
#[derive(Debug, Clone, Serialize, Deserialize)]
22
pub struct FileInfo {
3-
path: PathBuf,
4-
last_modified: SystemTime,
3+
path:PathBuf,
4+
last_modified:SystemTime,
55
}
66

77
#[derive(Debug, Clone, Serialize, Deserialize)]
88
pub struct CompilerConfig {
9-
pub Target: String,
10-
pub Module: String,
11-
pub Strict: bool,
12-
pub EmitDecoratorsMetadata: bool,
9+
pub Target:String,
10+
pub Module:String,
11+
pub Strict:bool,
12+
pub EmitDecoratorsMetadata:bool,
1313
}
1414

1515
#[derive(Debug, Clone)]
1616
pub struct Option {
17-
pub entry: Vec<Vec<String>>,
18-
pub separator: char,
19-
pub pattern: String,
20-
pub config: CompilerConfig,
17+
pub entry:Vec<Vec<String>>,
18+
pub separator:char,
19+
pub pattern:String,
20+
pub config:CompilerConfig,
2121
}
2222

2323
#[derive(Debug, Default)]
2424
pub struct CompilerMetrics {
25-
pub Count: usize,
26-
pub Elapsed: Duration,
27-
pub Error: usize,
25+
pub Count:usize,
26+
pub Elapsed:Duration,
27+
pub Error:usize,
2828
}
2929

3030
impl Default for CompilerConfig {
3131
fn default() -> Self {
3232
Self {
33-
Target: "es2022".to_string(),
34-
Module: "commonjs".to_string(),
35-
Strict: true,
36-
EmitDecoratorsMetadata: true,
33+
Target:"es2022".to_string(),
34+
Module:"commonjs".to_string(),
35+
Strict:true,
36+
EmitDecoratorsMetadata:true,
3737
}
3838
}
3939
}
4040

4141
#[derive(Debug)]
4242
pub struct Compiler {
43-
pub config: CompilerConfig,
44-
pub Outlook: Arc<Mutex<CompilerMetrics>>,
43+
pub config:CompilerConfig,
44+
pub Outlook:Arc<Mutex<CompilerMetrics>>,
4545
}
4646

4747
impl Compiler {
48-
pub fn new(config: CompilerConfig) -> Self {
49-
Self { config, Outlook: Arc::new(Mutex::new(CompilerMetrics::default())) }
48+
pub fn new(config:CompilerConfig) -> Self {
49+
Self { config, Outlook:Arc::new(Mutex::new(CompilerMetrics::default())) }
5050
}
5151

5252
#[tracing::instrument(skip(self, input))]
53-
pub fn compile_file(&self, File: &str, input: String) -> anyhow::Result<String> {
53+
pub fn compile_file(&self, File:&str, input:String) -> anyhow::Result<String> {
5454
let Begin = Instant::now();
5555

5656
let cm = Arc::new(SourceMap::new(FilePathMapping::empty()));
@@ -64,7 +64,9 @@ impl Compiler {
6464
None,
6565
));
6666

67-
let module = parser.parse_module().map_err(|e| anyhow::anyhow!("Failed to parse TypeScript module: {:?}", e))?;
67+
let module = parser
68+
.parse_module()
69+
.map_err(|e| anyhow::anyhow!("Failed to parse TypeScript module: {:?}", e))?;
6870

6971
let Unresolved = Mark::new();
7072
let Top = Mark::new();
@@ -73,7 +75,7 @@ impl Compiler {
7375
let mut program = swc_ecma_ast::Program::Module(module);
7476

7577
// Apply transforms using process() or visit_mut_with()
76-
78+
7779
// 1. Resolver
7880
{
7981
let mut pass = swc_ecma_transforms_base::resolver(Unresolved, Top, true);
@@ -85,13 +87,13 @@ impl Compiler {
8587
let mut pass = swc_ecma_transforms_typescript::strip(Unresolved, Top);
8688
pass.process(&mut program);
8789
}
88-
90+
8991
// 3. Decorators
9092
{
9193
let mut pass = decorators::decorators(decorators::Config {
92-
legacy: false,
93-
emit_metadata: self.config.EmitDecoratorsMetadata,
94-
use_define_for_class_fields: true,
94+
legacy:false,
95+
emit_metadata:self.config.EmitDecoratorsMetadata,
96+
use_define_for_class_fields:true,
9597
..Default::default()
9698
});
9799
pass.process(&mut program);
@@ -112,13 +114,15 @@ impl Compiler {
112114
let mut Output = vec![];
113115

114116
let mut Emitter = Emitter {
115-
cfg: swc_ecma_codegen::Config::default(),
116-
cm: cm.clone(),
117-
comments: None,
118-
wr: JsWriter::new(cm.clone(), "\n", &mut Output, None),
117+
cfg:swc_ecma_codegen::Config::default(),
118+
cm:cm.clone(),
119+
comments:None,
120+
wr:JsWriter::new(cm.clone(), "\n", &mut Output, None),
119121
};
120122

121-
Emitter.emit_module(&module).map_err(|e| anyhow::anyhow!("Failed to emit JavaScript: {:?}", e))?;
123+
Emitter
124+
.emit_module(&module)
125+
.map_err(|e| anyhow::anyhow!("Failed to emit JavaScript: {:?}", e))?;
122126

123127
let Path = Path::new(File).with_extension("js");
124128

@@ -138,12 +142,15 @@ impl Compiler {
138142
}
139143
}
140144

141-
use std::path::{Path, PathBuf};
142-
use std::sync::{Arc, Mutex};
143-
use std::time::{Duration, Instant, SystemTime};
145+
use std::{
146+
path::{Path, PathBuf},
147+
sync::{Arc, Mutex},
148+
time::{Duration, Instant, SystemTime},
149+
};
150+
144151
use serde::{Deserialize, Serialize};
145152
use tracing::debug;
146-
use swc_common::{SourceMap, FilePathMapping, FileName, Mark};
153+
use swc_common::{FileName, FilePathMapping, Mark, SourceMap};
147154
use swc_ecma_ast::{EsVersion, Pass};
148155
use swc_ecma_parser::{Parser, StringInput, Syntax, lexer::Lexer};
149156
use swc_ecma_codegen::{Emitter, text_writer::JsWriter};

0 commit comments

Comments
 (0)