mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +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",
|
||||
});
|
||||
if !self.declarations.is_empty() {
|
||||
p.print_hard_space();
|
||||
p.print_soft_space();
|
||||
}
|
||||
p.print_list(&self.declarations, ctx);
|
||||
}
|
||||
|
|
@ -1228,6 +1228,7 @@ impl Gen for IdentifierName<'_> {
|
|||
impl Gen for BindingIdentifier<'_> {
|
||||
fn gen(&self, p: &mut Codegen, _ctx: Context) {
|
||||
let name = p.get_binding_identifier_name(self);
|
||||
p.print_space_before_identifier();
|
||||
p.add_source_mapping_for_name(self.span, name);
|
||||
p.print_str(name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,4 +196,4 @@ export { default, /* …, */ } from "module-name";
|
|||
export { default as name16 } from "module-name";
|
||||
|
||||
----------
|
||||
import defaultExport from"module-name";import*as name from"module-name";import{export1}from"module-name";import{export1 as alias1}from"module-name";import{default as alias}from"module-name";import{export1,export2}from"module-name";import{export1,export2 as alias2}from"module-name";import{"string name" as alias}from"module-name";import defaultExport,{export1}from"module-name";import defaultExport,*as name from"module-name";import"module-name";import{}from"mod";export let name1,name2;export const name3=1,name4=2;export function functionName(){}export class ClassName{}export function*generatorFunctionName(){}export const {name5,name2:bar}=o;export const [name6,name7]=array;export{name8,name81};export{variable1 as name9,variable2 as name10,name82};export{variable1 as "string name"};export{name1 as default1};export*from"module-name";export*as name11 from"module-name";export{name12,nameN}from"module-name";export{import1 as name13,import2 as name14,name15}from"module-name";export{default}from"module-name";export{default as name16}from"module-name";
|
||||
import defaultExport from"module-name";import*as name from"module-name";import{export1}from"module-name";import{export1 as alias1}from"module-name";import{default as alias}from"module-name";import{export1,export2}from"module-name";import{export1,export2 as alias2}from"module-name";import{"string name" as alias}from"module-name";import defaultExport,{export1}from"module-name";import defaultExport,*as name from"module-name";import"module-name";import{}from"mod";export let name1,name2;export const name3=1,name4=2;export function functionName(){}export class ClassName{}export function*generatorFunctionName(){}export const{name5,name2:bar}=o;export const[name6,name7]=array;export{name8,name81};export{variable1 as name9,variable2 as name10,name82};export{variable1 as "string name"};export{name1 as default1};export*from"module-name";export*as name11 from"module-name";export{name12,nameN}from"module-name";export{import1 as name13,import2 as name14,name15}from"module-name";export{default}from"module-name";export{default as name16}from"module-name";
|
||||
|
|
|
|||
|
|
@ -2,6 +2,13 @@ use oxc_codegen::CodegenOptions;
|
|||
|
||||
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]
|
||||
fn module_decl() {
|
||||
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
|
||||
|
||||
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