@@ -578,10 +578,8 @@ impl Transform {
578
578
}
579
579
580
580
/// Note:
581
- /// Const exported declarations are transformed into immutable bindings.
582
- /// `export` from `export let` / ` export var` will be stripped,
583
- /// and a mutable binding will be transformed into assignment to the
584
- /// namespace. All references to the mutable binding will be replaced with
581
+ /// All exported variable declarations are transformed into assignment to the
582
+ /// namespace. All references to the exported binding will be replaced with
585
583
/// qualified access to the namespace property.
586
584
///
587
585
/// Exported function and class will be treat as const exported which is in
@@ -592,7 +590,7 @@ impl Transform {
592
590
///
593
591
/// Input:
594
592
/// ```TypeScript
595
- /// export const foo = init, { bar: baz } = init;
593
+ /// export const foo = init, { bar: baz = init } = init;
596
594
///
597
595
/// export function a() {}
598
596
///
@@ -601,7 +599,7 @@ impl Transform {
601
599
///
602
600
/// Output:
603
601
/// ```TypeScript
604
- /// const foo = NS.foo = init, { bar: baz } = { bar: NS.baz } = init;
602
+ /// NS.foo = init, { bar: NS. baz = init } = init;
605
603
///
606
604
/// function a() {}
607
605
/// NS.a = a;
@@ -640,18 +638,14 @@ impl Transform {
640
638
) -> Option < Stmt > {
641
639
debug_assert ! ( !var_decl. declare) ;
642
640
643
- var_decl. decls . iter_mut ( ) . for_each ( |var_declarator| {
644
- Self :: assign_init_to_ns_id ( var_declarator, id) ;
645
- } ) ;
646
-
647
- if var_decl. kind == VarDeclKind :: Const {
648
- return Some ( var_decl. into ( ) ) ;
649
- }
650
-
651
641
let mut collector = ExportedIdentCollector :: default ( ) ;
652
642
var_decl. visit_with ( & mut collector) ;
653
643
mutable_export_ids. extend ( collector. export_list ) ;
654
644
645
+ var_decl. decls . visit_mut_with ( & mut ExportedPatRewriter {
646
+ id : id. clone ( ) . into ( ) ,
647
+ } ) ;
648
+
655
649
let mut expr_list: Vec < Box < Expr > > =
656
650
var_decl. decls . into_iter ( ) . filter_map ( |d| d. init ) . collect ( ) ;
657
651
@@ -672,31 +666,6 @@ impl Transform {
672
666
673
667
Some ( Stmt :: Expr ( ExprStmt { span, expr } ) )
674
668
}
675
-
676
- /// Input:
677
- /// ```TypeScript
678
- /// const foo = init;
679
- /// ```
680
- /// Output:
681
- /// ```TypeScript
682
- /// const foo = NS.foo = init;
683
- /// ```
684
- fn assign_init_to_ns_id ( var_declarator : & mut VarDeclarator , id : & Id ) {
685
- let Some ( right) = var_declarator. init . take ( ) else {
686
- return ;
687
- } ;
688
-
689
- let mut left = var_declarator. name . clone ( ) ;
690
- left. visit_mut_with ( & mut ExportedPatRewriter {
691
- id : id. clone ( ) . into ( ) ,
692
- } ) ;
693
-
694
- var_declarator. init = Some (
695
- right
696
- . make_assign_to ( op ! ( "=" ) , PatOrExpr :: Pat ( left. into ( ) ) )
697
- . into ( ) ,
698
- ) ;
699
- }
700
669
}
701
670
702
671
impl Transform {
@@ -1135,6 +1104,21 @@ struct ExportedPatRewriter {
1135
1104
impl VisitMut for ExportedPatRewriter {
1136
1105
noop_visit_mut_type ! ( ) ;
1137
1106
1107
+ fn visit_mut_var_declarator ( & mut self , n : & mut VarDeclarator ) {
1108
+ let Some ( right) = n. init . take ( ) else {
1109
+ return ;
1110
+ } ;
1111
+
1112
+ let mut left = n. name . take ( ) ;
1113
+ left. visit_mut_with ( self ) ;
1114
+
1115
+ n. init = Some (
1116
+ right
1117
+ . make_assign_to ( op ! ( "=" ) , PatOrExpr :: Pat ( left. into ( ) ) )
1118
+ . into ( ) ,
1119
+ ) ;
1120
+ }
1121
+
1138
1122
fn visit_mut_pat ( & mut self , n : & mut Pat ) {
1139
1123
if let Pat :: Ident ( BindingIdent { id, .. } ) = n {
1140
1124
* n = Pat :: Expr ( Box :: new ( self . id . clone ( ) . make_member ( id. take ( ) ) ) ) ;
@@ -1145,10 +1129,23 @@ impl VisitMut for ExportedPatRewriter {
1145
1129
}
1146
1130
1147
1131
fn visit_mut_object_pat_prop ( & mut self , n : & mut ObjectPatProp ) {
1148
- if let ObjectPatProp :: Assign ( AssignPatProp { key, .. } ) = n {
1132
+ if let ObjectPatProp :: Assign ( AssignPatProp { key, value, .. } ) = n {
1133
+ let left = Box :: new ( Pat :: Expr ( self . id . clone ( ) . make_member ( key. clone ( ) ) . into ( ) ) ) ;
1134
+
1135
+ let value = if let Some ( right) = value. take ( ) {
1136
+ Pat :: Assign ( AssignPat {
1137
+ span : DUMMY_SP ,
1138
+ left,
1139
+ right,
1140
+ } )
1141
+ . into ( )
1142
+ } else {
1143
+ left
1144
+ } ;
1145
+
1149
1146
* n = ObjectPatProp :: KeyValue ( KeyValuePatProp {
1150
1147
key : PropName :: Ident ( key. clone ( ) ) ,
1151
- value : Box :: new ( Pat :: Expr ( self . id . clone ( ) . make_member ( key . clone ( ) ) . into ( ) ) ) ,
1148
+ value,
1152
1149
} ) ;
1153
1150
return ;
1154
1151
}
1 commit comments
github-actions[bot] commentedon Sep 29, 2023
Benchmark
es/full/bugs-1
276721
ns/iter (± 6210
)275102
ns/iter (± 2583
)1.01
es/full/minify/libraries/antd
1285832357
ns/iter (± 12153756
)1318521059
ns/iter (± 15535694
)0.98
es/full/minify/libraries/d3
270680100
ns/iter (± 3067727
)273599669
ns/iter (± 7159486
)0.99
es/full/minify/libraries/echarts
1034147287
ns/iter (± 4018881
)1045250218
ns/iter (± 9958916
)0.99
es/full/minify/libraries/jquery
83346969
ns/iter (± 109023
)83977148
ns/iter (± 329319
)0.99
es/full/minify/libraries/lodash
96544472
ns/iter (± 188095
)97436571
ns/iter (± 157526
)0.99
es/full/minify/libraries/moment
49280804
ns/iter (± 115809
)49720752
ns/iter (± 357443
)0.99
es/full/minify/libraries/react
17882682
ns/iter (± 80684
)18005136
ns/iter (± 92710
)0.99
es/full/minify/libraries/terser
214825610
ns/iter (± 1737310
)216751277
ns/iter (± 583051
)0.99
es/full/minify/libraries/three
380392231
ns/iter (± 1724691
)384344625
ns/iter (± 1901744
)0.99
es/full/minify/libraries/typescript
2581755264
ns/iter (± 18434478
)2645353468
ns/iter (± 10687292
)0.98
es/full/minify/libraries/victory
565202909
ns/iter (± 5042799
)567467876
ns/iter (± 4184440
)1.00
es/full/minify/libraries/vue
117959671
ns/iter (± 168678
)119417047
ns/iter (± 2683822
)0.99
es/full/codegen/es3
34115
ns/iter (± 139
)34329
ns/iter (± 141
)0.99
es/full/codegen/es5
33998
ns/iter (± 105
)34275
ns/iter (± 140
)0.99
es/full/codegen/es2015
34119
ns/iter (± 103
)34362
ns/iter (± 65
)0.99
es/full/codegen/es2016
34020
ns/iter (± 117
)34254
ns/iter (± 122
)0.99
es/full/codegen/es2017
33987
ns/iter (± 183
)34247
ns/iter (± 82
)0.99
es/full/codegen/es2018
34061
ns/iter (± 166
)34364
ns/iter (± 157
)0.99
es/full/codegen/es2019
33954
ns/iter (± 154
)34283
ns/iter (± 129
)0.99
es/full/codegen/es2020
34095
ns/iter (± 140
)34308
ns/iter (± 99
)0.99
es/full/all/es3
163536715
ns/iter (± 848902
)165651725
ns/iter (± 710876
)0.99
es/full/all/es5
156870098
ns/iter (± 1035393
)158321742
ns/iter (± 1141284
)0.99
es/full/all/es2015
116050191
ns/iter (± 650928
)118194302
ns/iter (± 1816704
)0.98
es/full/all/es2016
115686831
ns/iter (± 796787
)117275947
ns/iter (± 600779
)0.99
es/full/all/es2017
114922968
ns/iter (± 1153785
)115455982
ns/iter (± 681033
)1.00
es/full/all/es2018
113076497
ns/iter (± 699821
)113896739
ns/iter (± 519485
)0.99
es/full/all/es2019
112606016
ns/iter (± 785839
)113517013
ns/iter (± 1355946
)0.99
es/full/all/es2020
107782843
ns/iter (± 543518
)109968865
ns/iter (± 720229
)0.98
es/full/parser
482436
ns/iter (± 5552
)494442
ns/iter (± 4356
)0.98
es/full/base/fixer
17875
ns/iter (± 105
)21039
ns/iter (± 230
)0.85
es/full/base/resolver_and_hygiene
80623
ns/iter (± 421
)81898
ns/iter (± 115
)0.98
serialization of serde
284
ns/iter (± 3
)287
ns/iter (± 0
)0.99
This comment was automatically generated by workflow using github-action-benchmark.