[][src]Function minifier::js::aggregate_strings_into_array

pub fn aggregate_strings_into_array<'a>(
    tokens: Tokens<'a>,
    array_name: &str
) -> Tokens<'a>

Aggregate litteral strings. For instance, if the string litteral "Oh look over there!" appears more than once, it will be added to the generated array and used everywhere the string appears. Of course, this replacement is only performed when it allows to take less space.

Example

extern crate minifier;
use minifier::js::{aggregate_strings_into_array, clean_tokens, simple_minify};
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_into_array(f, "R")) // This `apply` aggregates string litterals.
             .apply(clean_tokens)      // This one is used to remove useless chars.
             .to_string();             // And we finally convert to string.
    println!("result: {}", s);
}