From 7896837d07fcbd80bddd0296d9c8d93d8912588e Mon Sep 17 00:00:00 2001 From: SteveBeeblebrox <41750582+SteveBeeblebrox@users.noreply.github.com> Date: Sun, 5 Jun 2022 21:28:42 -0600 Subject: [PATCH] Finished minify flag --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/compilers.rs | 41 ++++++++++++++++++++++++++++++++++++----- src/main.rs | 2 +- test.ts | 14 ++++++++++++++ 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 086e02f..43038f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -519,7 +519,7 @@ dependencies = [ [[package]] name = "mtsc" -version = "4.6.3" +version = "4.7.3" dependencies = [ "backtrace", "clap", diff --git a/Cargo.toml b/Cargo.toml index 2f3edd2..f9333c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mtsc" -version = "4.6.3" +version = "4.7.3" edition = "2018" authors = ["S. Beeblebrox"] # license = "MIT" diff --git a/src/compilers.rs b/src/compilers.rs index df9a628..f911ddb 100644 --- a/src/compilers.rs +++ b/src/compilers.rs @@ -313,13 +313,44 @@ pub fn minify_javascript(text: &str, options: MinifyOptions) -> Option { let args = v8::Object::new(scope); - /*let target_prop_name = v8::String::new(scope, "target")?.into(); - let target_prop_value = v8::String::new(scope, options.target.as_str())?.into(); - args.set(scope, target_prop_name, target_prop_value); + // Compile Options + let compress_prop_name = v8::String::new(scope, "compress")?.into(); + let compress_prop_value = v8::Object::new(scope); + + + let ecma_prop_name = v8::String::new(scope, "ecma")?.into(); + let ecma_prop_value = v8::String::new(scope, options.target.to_lowercase().strip_prefix("es")?)?.into(); + compress_prop_value.set(scope, ecma_prop_name, ecma_prop_value); let module_prop_name = v8::String::new(scope, "module")?.into(); - let module_prop_value = v8::String::new(scope, options.module.as_str())?.into(); - args.set(scope, module_prop_name, module_prop_value);*/ + let module_prop_value = v8::Boolean::new(scope, options.module != "none").into(); + compress_prop_value.set(scope, module_prop_name, module_prop_value); + + args.set(scope, compress_prop_name, compress_prop_value.into()); + + // Mangle Options + let mangle_prop_name = v8::String::new(scope, "mangle")?.into(); + let mangle_prop_value = v8::Object::new(scope); + + let module_prop_name = v8::String::new(scope, "module")?.into(); + let module_prop_value = v8::Boolean::new(scope, options.module != "none").into(); + mangle_prop_value.set(scope, module_prop_name, module_prop_value); + + args.set(scope, mangle_prop_name, mangle_prop_value.into()); + + // Format Options + let format_prop_name = v8::String::new(scope, "format")?.into(); + let format_prop_value = v8::Object::new(scope); + + let ecma_prop_name = v8::String::new(scope, "ecma")?.into(); + let ecma_prop_value = v8::String::new(scope, options.target.to_lowercase().strip_prefix("es")?)?.into(); + format_prop_value.set(scope, ecma_prop_name, ecma_prop_value); + + let comment_prop_name = v8::String::new(scope, "comments")?.into(); + let comment_prop_value = v8::String::new(scope, "/^!/")?.into(); + format_prop_value.set(scope, comment_prop_name, comment_prop_value); + + args.set(scope, format_prop_name, format_prop_value.into()); let result = minify_function.call(scope, terser_obj, &[text, args.into()])?; diff --git a/src/main.rs b/src/main.rs index 9d9e6e0..47e1fb9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ fn main() { let matches = App::new("MTSC") .version(clap::crate_version!()) .author(clap::crate_authors!()) - .about("A standalone TypeScript compiler") + .about("A standalone TypeScript compiler with support for JSX, HTML script tags, and minification") .arg(Arg::with_name("target") .short("t") diff --git a/test.ts b/test.ts index 01fff7f..01de1b0 100644 --- a/test.ts +++ b/test.ts @@ -1,5 +1,19 @@ +// discard +//! Comment to Keep +var v + type NumberLike = number | string const x: NumberLike = '7'; function doStuff(...args: string[]): boolean { return +x === 7; +} +let y = true +{ + let foo = 1 +} + +let xx = { + foo() { + console.log(1+1) + } } \ No newline at end of file