From ecce03e4fe79ac6634ebeabce6692e65a743e8cf Mon Sep 17 00:00:00 2001 From: Wilson Lin Date: Mon, 25 Dec 2023 14:28:50 +1100 Subject: [PATCH] Minor fixes --- README.md | 3 +-- format | 2 +- rust/src/emit/tests/mod.rs | 2 +- rust/src/minify/lexical_lifetimes.rs | 3 ++- rust/src/minify/pass1.rs | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0454024..5163856 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,9 @@ Comparison with esbuild, run on [common libraries](./bench). - Data is backed by a fast reusable bump allocation arena. - Supports JSX. - Analyses scopes and variable visibilities. -- Minification of identifiers. +- Minifies identifiers. - Omits semicolons, spaces, parentheses, and braces where possible. - Transforms functions to arrow functions when `new`, `this`, `arguments`, and `prototype` aren't used. -- Moves repeated usages of constants to one shared variable. - Transforms `if` statements to expressions. ## Usage diff --git a/format b/format index 55d7d55..a1c4ef5 100755 --- a/format +++ b/format @@ -6,6 +6,6 @@ pushd "$(dirname "$0")" >/dev/null npx prettier@2.3.2 -w 'version' '.github/**/*.yaml' 'nodejs/*.{js,json,ts}' -cargo fmt +cargo +nightly fmt popd >/dev/null diff --git a/rust/src/emit/tests/mod.rs b/rust/src/emit/tests/mod.rs index c70d88a..85ad1ac 100644 --- a/rust/src/emit/tests/mod.rs +++ b/rust/src/emit/tests/mod.rs @@ -298,6 +298,6 @@ fn test_advanced_if_minification() { } } "#, - r#"var foo=(a=>{if(a)return 1,2,3,4,cond?5:(6,7,8);9;10;return 11})"#, + r#"var foo=(a=>{var d,c;if(!a)return d=3,d;var b=1;if(cond)return c=2,c;return b})"#, ); } diff --git a/rust/src/minify/lexical_lifetimes.rs b/rust/src/minify/lexical_lifetimes.rs index 0382e08..0fd2df9 100644 --- a/rust/src/minify/lexical_lifetimes.rs +++ b/rust/src/minify/lexical_lifetimes.rs @@ -97,7 +97,8 @@ impl<'a, 'b> LexicalLifetimesPass<'a, 'b> { impl<'a, 'b> Visitor<'a> for LexicalLifetimesPass<'a, 'b> { fn on_syntax_down(&mut self, node: &mut NodeData<'a>, ctl: &mut JourneyControls) -> () { let usage_scope = node.scope; - let Some(usage_closure_scope) = usage_scope.find_self_or_ancestor(|s| s.is_closure_or_class()) else { + let Some(usage_closure_scope) = usage_scope.find_self_or_ancestor(|s| s.is_closure_or_class()) + else { // TODO Assert we're at the top level. return; }; diff --git a/rust/src/minify/pass1.rs b/rust/src/minify/pass1.rs index 552c162..9ff579c 100644 --- a/rust/src/minify/pass1.rs +++ b/rust/src/minify/pass1.rs @@ -12,12 +12,12 @@ use parse_js::visit::Visitor; use std::str::from_utf8_unchecked; // - Detect all usages of JSX components, as React determines `` to be the HTML tag and `` to be the variable `Link` as a component, so we cannot minify `Link` to `link` or `a0` or `bb` (i.e. make capitalised JSX elements uncapitalised). -// - Find all references of variables so we can determine inherited variables (see `MinifiedNameGenerator` and `MinifyScope`). This is because JS allows variables to be lexically references before they're used, so we cannot do this in the same pass. For example, `let b = 1; { let a = () => b; let b = 2; }`. +// - Find all references of variables so we can determine inherited variables (see `MinifiedNameGenerator` and `MinifyScope`). This is because JS allows variables to be lexically referenced before they're used, so we cannot do this in the same pass. For example, `let b = 1; { let a = () => b; let b = 2; }`. // - Find uses of `new ` and set `is_used_as_constructor`. // - Find uses of `.prototype` and set `has_prototype`. // - Combine consecutive expression statements into one. // - Convert `if (x) { expr; }` to `x && expr`. -// - Convert `if (x) { expr1; } else { expr2; }` to `x ? expr1 ; expr2`. +// - Convert `if (x) { expr1; } else { expr2; }` to `x ? expr1 : expr2`. // - Concatenate addition of two literal strings. // - Unwrap unnecessary block statements. // - Drop debugger statements.