Created
October 18, 2023 10:10
-
-
Save stormslowly/1c8e3ed5682d49fabfe5f6c777410f08 to your computer and use it in GitHub Desktop.
hash a stylesheet of swc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::hash::{Hash, Hasher}; | |
use swc_common::{FileName, SourceMap}; | |
use swc_common::input::StringInput; | |
use swc_common::sync::Lrc; | |
use std::borrow::Borrow; | |
fn main() { | |
let cm: Lrc<SourceMap> = Default::default(); | |
let fm = cm | |
.new_source_file(FileName::Real("test.css".into()), ".h1 {color : red; }".to_string()); | |
// .new_source_file(FileName::Real("test.css".into()), "".to_string()); // OK | |
let lexer = swc_css_parser::lexer::Lexer::new(StringInput::from(&*fm), None, Default::default()); | |
let mut parser = swc_css_parser::parser::Parser::new(lexer, Default::default()); | |
let stylesheet = parser.parse_all().unwrap(); | |
let mut hasher = std::collections::hash_map::DefaultHasher::new(); | |
stylesheet.hash(&mut hasher); | |
let h = hasher.finish(); | |
println!("hash: {}", h); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment