Skip to content

Commit 9f94427

Browse files
committed
fmt
1 parent 6a7de93 commit 9f94427

File tree

3 files changed

+45
-44
lines changed

3 files changed

+45
-44
lines changed

crates/swc_ecma_preset_env/build.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
use std::fs;
2-
use std::io::{ self, Write };
3-
use std::path::Path;
4-
use std::collections::{ HashMap, BTreeMap };
1+
use std::{
2+
collections::{BTreeMap, HashMap},
3+
fs,
4+
io::{self, Write},
5+
path::Path,
6+
};
7+
58
use anyhow::Context;
69

710
fn main() -> anyhow::Result<()> {
@@ -10,21 +13,20 @@ fn main() -> anyhow::Result<()> {
1013

1114
fn es_preset_env_corejs3_entry() -> anyhow::Result<()> {
1215
const SEED: u64 = 16416001479773392852;
13-
16+
1417
let crate_dir = std::env::var("CARGO_MANIFEST_DIR")?;
1518
let crate_dir = Path::new(&crate_dir);
1619

1720
let out_dir = std::env::var("OUT_DIR").unwrap();
1821
let out_dir = Path::new(&out_dir);
1922
let out_dir = out_dir.join("corejs3_entries");
2023

21-
2224
let entry_path = crate_dir.join("data/core-js-compat/entries.json");
2325
println!("cargo::rerun-if-changed={}", entry_path.display());
24-
26+
2527
let entry_data = fs::read_to_string(entry_path)?;
26-
let entry_data: BTreeMap<&str, Vec<&str>> = serde_json::from_str(&entry_data)
27-
.context("failed to parse entries.json from core js 3")?;
28+
let entry_data: BTreeMap<&str, Vec<&str>> =
29+
serde_json::from_str(&entry_data).context("failed to parse entries.json from core js 3")?;
2830
let (keys, values): (Vec<_>, Vec<_>) = entry_data.into_iter().unzip();
2931

3032
let mut strpool = StrPool::default();
@@ -43,47 +45,46 @@ fn es_preset_env_corejs3_entry() -> anyhow::Result<()> {
4345
let mapout = precomputed_map::builder::MapBuilder::<&str>::new()
4446
.set_seed(SEED)
4547
.set_hash(&|seed, &v| {
46-
use std::hash::{ Hash, Hasher };
47-
48-
let mut hasher = foldhash::fast::FoldHasher::with_seed(seed, foldhash::SharedSeed::global_fixed());
48+
use std::hash::{Hash, Hasher};
49+
50+
let mut hasher =
51+
foldhash::fast::FoldHasher::with_seed(seed, foldhash::SharedSeed::global_fixed());
4952
v.as_bytes().hash(&mut hasher);
5053
hasher.finish()
5154
})
52-
.set_next_seed(|seed, c| {
53-
seed + c
54-
})
55+
.set_next_seed(|seed, c| seed + c)
5556
.build(&keys)?;
5657

57-
if let Some(seed) = mapout.seed() {
58-
if seed != SEED {
59-
println!("cargo::warning=The seed has changed, please update the seed to {} for faster builds", seed);
60-
}
58+
if let Some(seed) = mapout.seed().filter(|&seed| seed != SEED) {
59+
println!(
60+
"cargo::warning=The seed has changed, please update the seed to {seed} for faster \
61+
builds"
62+
);
6163
}
6264

6365
// clean file
6466
{
65-
fs::remove_dir_all(&out_dir)
66-
.or_else(|err| match err.kind() {
67-
io::ErrorKind::NotFound => Ok(()),
68-
_ => Err(err)
69-
})?;
67+
fs::remove_dir_all(&out_dir).or_else(|err| match err.kind() {
68+
io::ErrorKind::NotFound => Ok(()),
69+
_ => Err(err),
70+
})?;
7071
fs::create_dir(&out_dir)?;
7172
}
7273

7374
let mut u8seq = precomputed_map::builder::U8SeqWriter::new(
7475
"PrecomputedU8Seq".into(),
75-
out_dir.join("u8.bin")
76+
out_dir.join("u8.bin"),
7677
);
7778
let mut u32seq = precomputed_map::builder::U32SeqWriter::new(
7879
"PrecomputedU32Seq".into(),
79-
out_dir.join("u32.bin")
80+
out_dir.join("u32.bin"),
8081
);
81-
82+
8283
let mut builder = precomputed_map::builder::CodeBuilder::new(
8384
"Corejs3Entries".into(),
8485
"SwcFold".into(),
8586
&mut u8seq,
86-
&mut u32seq
87+
&mut u32seq,
8788
);
8889

8990
let k = builder.create_bytes_position_seq("EntryKeys".into(), mapout.reorder(&keys))?;
@@ -97,7 +98,8 @@ fn es_preset_env_corejs3_entry() -> anyhow::Result<()> {
9798

9899
fs::write(out_dir.join("str.bin"), strpool.pool.as_bytes())?;
99100

100-
writeln!(codeout,
101+
writeln!(
102+
codeout,
101103
"static ENTRY_VALUES_STRING_STORE: &str = include_str!(\"str.bin\");
102104
static ENTRY_VALUES_LIST: &[Range<u32>] = &["
103105
)?;
@@ -119,7 +121,7 @@ impl<'s> StrPool<'s> {
119121
pub fn insert(&mut self, s: &'s str) -> u32 {
120122
*self.map.entry(s).or_insert_with(|| {
121123
let offset = self.pool.len();
122-
self.pool.push_str(&s);
124+
self.pool.push_str(s);
123125
let len: u8 = (self.pool.len() - offset).try_into().unwrap();
124126
let offset: u32 = offset.try_into().unwrap();
125127

crates/swc_ecma_preset_env/src/corejs3/entry.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{ops::Range, sync::Arc};
22

33
use indexmap::IndexSet;
44
use preset_env_base::{
@@ -10,27 +10,25 @@ use swc_atoms::atom;
1010
use swc_common::DUMMY_SP;
1111
use swc_ecma_ast::*;
1212
use swc_ecma_visit::VisitMut;
13-
use std::ops::Range;
14-
use crate::util::SwcFold;
1513

1614
use super::{compat::DATA as CORE_JS_COMPAT_DATA, data::MODULES_BY_VERSION};
15+
use crate::util::SwcFold;
1716

1817
include!(concat!(env!("OUT_DIR"), "/corejs3_entries/lib.rs"));
1918

2019
pub struct FeatureSet(Range<u32>);
21-
22-
pub fn entries_get(name: &str) -> Option<FeatureSet> {{
23-
let index = ENTRY_INDEX.get(name.as_bytes())?;
24-
ENTRY_VALUES_LIST
25-
.get(index)
26-
.cloned()
27-
.map(FeatureSet)
28-
}}
20+
21+
pub fn entries_get(name: &str) -> Option<FeatureSet> {
22+
{
23+
let index = ENTRY_INDEX.get(name.as_bytes())?;
24+
ENTRY_VALUES_LIST.get(index).cloned().map(FeatureSet)
25+
}
26+
}
2927

3028
impl FeatureSet {
3129
pub fn iter(&self) -> impl ExactSizeIterator<Item = &'static str> {
3230
use precomputed_map::store::AccessSeq;
33-
31+
3432
self.0
3533
.clone()
3634
.map(|idx| EntryValuesStringId::index(idx as usize).unwrap())

crates/swc_ecma_preset_env/src/util.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,9 @@ pub struct SwcFold;
695695
impl precomputed_map::phf::HashOne for SwcFold {
696696
fn hash_one<T: std::hash::Hash>(k: u64, v: T) -> u64 {
697697
use std::hash::Hasher;
698-
699-
let mut hasher = foldhash::fast::FoldHasher::with_seed(k, foldhash::SharedSeed::global_fixed());
698+
699+
let mut hasher =
700+
foldhash::fast::FoldHasher::with_seed(k, foldhash::SharedSeed::global_fixed());
700701
// let mut hasher = rustc_hash::FxHasher::with_seed(k as usize);
701702
v.hash(&mut hasher);
702703
hasher.finish()

0 commit comments

Comments
 (0)