Skip to content

Commit

Permalink
Finished minify flag
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveBeeblebrox committed Jun 6, 2022
1 parent 4bde20c commit 7896837
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mtsc"
version = "4.6.3"
version = "4.7.3"
edition = "2018"
authors = ["S. Beeblebrox"] # <[email protected]>
license = "MIT"
Expand Down
41 changes: 36 additions & 5 deletions src/compilers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,44 @@ pub fn minify_javascript(text: &str, options: MinifyOptions) -> Option<String> {

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()])?;

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 7896837

Please sign in to comment.