Function minifier::js::clean_tokens_except
source · pub fn clean_tokens_except<'a, F: Fn(&Token<'a>) -> bool>(
tokens: Tokens<'a>,
f: F
) -> Tokens<'a>
Expand description
Same as clean_tokens
except that if a token is considered as not desired,
the callback is called. If the callback returns false
as well, it will
be removed.
Example
extern crate minifier;
use minifier::js::{clean_tokens_except, simple_minify, ReservedChar};
use std::fs;
fn main() {
let content = fs::read("some_file.js").expect("file not found");
let source = String::from_utf8_lossy(&content);
let s = simple_minify(&source); // First we get the tokens list.
let s = s.apply(|f| {
clean_tokens_except(f, |c| {
c.get_char() != Some(ReservedChar::Backline)
})
}); // We now have a cleaned token list which kept backlines!
println!("result: {:?}", s);
}