Function minifier::js::aggregate_strings_with_separation
source · pub fn aggregate_strings_with_separation<'a, 'b: 'a>(
tokens: Tokens<'a>,
separation_token: Token<'b>,
) -> Tokens<'a>
Expand description
Exactly like aggregate_strings
except this one expects a separation token
to be passed. This token will be placed between the created variables for the
strings aggregation and the rest.
§Example
Let’s add a backline between the created variables and the rest of the code:
extern crate minifier;
use minifier::js::{
aggregate_strings_with_separation,
clean_tokens,
simple_minify,
Token,
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| {
aggregate_strings_with_separation(f, Token::Char(ReservedChar::Backline))
}) // We add a backline between the variable and the rest.
.apply(clean_tokens) // We clean the tokens.
.to_string(); // And we finally convert to string.
println!("result: {}", s);
}