swc/crates/swc_atoms/build.rs
Donny/강동윤 84cec8766d
refactor(atoms): Remove usage of js_word! to drop string-cache (#7976)
**Description:**

This PR is to prepare removal of `string-cache`. Actually, this PR does not remove it. Instead, this PR only removes direct usages of `js_word!`s, especially in patterns.



**Related issue:**

 - #4946.
2023-10-08 00:39:51 +00:00

30 lines
875 B
Rust

use std::{env, path::Path};
fn main() {
let strs = include_str!("words.txt")
.lines()
.map(|l| l.trim())
.collect::<Vec<_>>();
gen("internal_word", "InternalWord", &strs);
}
fn gen(mac_name: &str, type_name: &str, atoms: &[&str]) {
string_cache_codegen::AtomType::new(type_name, &format!("{}!", mac_name))
.atoms(atoms)
.with_atom_doc(
"
[JsWord] is an interned string.
This type should be used instead of [String] for values, because lots of
values are duplicated. For example, if an identifier is named `myVariable`,
there will be lots of identifier usages with the value `myVariable`.
This type
- makes equality comparison faster.
- reduces memory usage.
",
)
.write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join(format!("{}.rs", mac_name)))
.unwrap();
}