mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(codegen): minify const [foo] = bar -> const[foo]=bar (#8079)
This commit is contained in:
parent
e3f78fba0b
commit
1d5ae817d7
4 changed files with 20 additions and 12 deletions
|
|
@ -684,7 +684,7 @@ impl Gen for VariableDeclaration<'_> {
|
||||||
VariableDeclarationKind::AwaitUsing => "await using",
|
VariableDeclarationKind::AwaitUsing => "await using",
|
||||||
});
|
});
|
||||||
if !self.declarations.is_empty() {
|
if !self.declarations.is_empty() {
|
||||||
p.print_hard_space();
|
p.print_soft_space();
|
||||||
}
|
}
|
||||||
p.print_list(&self.declarations, ctx);
|
p.print_list(&self.declarations, ctx);
|
||||||
}
|
}
|
||||||
|
|
@ -1228,6 +1228,7 @@ impl Gen for IdentifierName<'_> {
|
||||||
impl Gen for BindingIdentifier<'_> {
|
impl Gen for BindingIdentifier<'_> {
|
||||||
fn gen(&self, p: &mut Codegen, _ctx: Context) {
|
fn gen(&self, p: &mut Codegen, _ctx: Context) {
|
||||||
let name = p.get_binding_identifier_name(self);
|
let name = p.get_binding_identifier_name(self);
|
||||||
|
p.print_space_before_identifier();
|
||||||
p.add_source_mapping_for_name(self.span, name);
|
p.add_source_mapping_for_name(self.span, name);
|
||||||
p.print_str(name);
|
p.print_str(name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,13 @@ use oxc_codegen::CodegenOptions;
|
||||||
|
|
||||||
use crate::tester::{test, test_minify, test_minify_same, test_options};
|
use crate::tester::{test, test_minify, test_minify_same, test_options};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn decl() {
|
||||||
|
test_minify("const [foo] = bar", "const[foo]=bar;");
|
||||||
|
test_minify("const {foo} = bar", "const{foo}=bar;");
|
||||||
|
test_minify("const foo = bar", "const foo=bar;");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn module_decl() {
|
fn module_decl() {
|
||||||
test("export * as foo from 'foo'", "export * as foo from \"foo\";\n");
|
test("export * as foo from 'foo'", "export * as foo from \"foo\";\n");
|
||||||
|
|
|
||||||
|
|
@ -5,23 +5,23 @@ Original | minified | minified | gzip | gzip | Fixture
|
||||||
|
|
||||||
173.90 kB | 61.60 kB | 59.82 kB | 19.54 kB | 19.33 kB | moment.js
|
173.90 kB | 61.60 kB | 59.82 kB | 19.54 kB | 19.33 kB | moment.js
|
||||||
|
|
||||||
287.63 kB | 92.61 kB | 90.07 kB | 32.27 kB | 31.95 kB | jquery.js
|
287.63 kB | 92.60 kB | 90.07 kB | 32.27 kB | 31.95 kB | jquery.js
|
||||||
|
|
||||||
342.15 kB | 121.57 kB | 118.14 kB | 44.64 kB | 44.37 kB | vue.js
|
342.15 kB | 121.56 kB | 118.14 kB | 44.64 kB | 44.37 kB | vue.js
|
||||||
|
|
||||||
544.10 kB | 73.37 kB | 72.48 kB | 26.14 kB | 26.20 kB | lodash.js
|
544.10 kB | 73.32 kB | 72.48 kB | 26.13 kB | 26.20 kB | lodash.js
|
||||||
|
|
||||||
555.77 kB | 276.21 kB | 270.13 kB | 91.16 kB | 90.80 kB | d3.js
|
555.77 kB | 276.08 kB | 270.13 kB | 91.14 kB | 90.80 kB | d3.js
|
||||||
|
|
||||||
1.01 MB | 467.13 kB | 458.89 kB | 126.76 kB | 126.71 kB | bundle.min.js
|
1.01 MB | 467.00 kB | 458.89 kB | 126.74 kB | 126.71 kB | bundle.min.js
|
||||||
|
|
||||||
1.25 MB | 662.63 kB | 646.76 kB | 164.01 kB | 163.73 kB | three.js
|
1.25 MB | 661.60 kB | 646.76 kB | 163.94 kB | 163.73 kB | three.js
|
||||||
|
|
||||||
2.14 MB | 740.53 kB | 724.14 kB | 181.38 kB | 181.07 kB | victory.js
|
2.14 MB | 740.48 kB | 724.14 kB | 181.35 kB | 181.07 kB | victory.js
|
||||||
|
|
||||||
3.20 MB | 1.02 MB | 1.01 MB | 332.11 kB | 331.56 kB | echarts.js
|
3.20 MB | 1.02 MB | 1.01 MB | 332.01 kB | 331.56 kB | echarts.js
|
||||||
|
|
||||||
6.69 MB | 2.39 MB | 2.31 MB | 495.63 kB | 488.28 kB | antd.js
|
6.69 MB | 2.39 MB | 2.31 MB | 495.62 kB | 488.28 kB | antd.js
|
||||||
|
|
||||||
10.95 MB | 3.55 MB | 3.49 MB | 909.73 kB | 915.50 kB | typescript.js
|
10.95 MB | 3.54 MB | 3.49 MB | 909.70 kB | 915.50 kB | typescript.js
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue