@@ -190,14 +190,13 @@ impl Gen for Statement<'_> {
190190impl Gen for ExpressionStatement < ' _ > {
191191 fn r#gen ( & self , p : & mut Codegen , _ctx : Context ) {
192192 p. print_comments_at ( self . span . start ) ;
193- p. print_indent ( ) ;
193+ if !p. options . minify && ( p. indent > 0 || p. print_next_indent_as_space ) {
194+ p. add_source_mapping ( self . span ) ;
195+ p. print_indent ( ) ;
196+ }
194197 p. start_of_stmt = p. code_len ( ) ;
195198 p. print_expression ( & self . expression ) ;
196- if self . expression . is_specific_id ( "let" ) {
197- p. print_semicolon ( ) ;
198- } else {
199- p. print_semicolon_after_statement ( ) ;
200- }
199+ p. print_semicolon_after_statement ( ) ;
201200 }
202201}
203202
@@ -761,6 +760,7 @@ impl Gen for FunctionBody<'_> {
761760
762761impl Gen for FormalParameter < ' _ > {
763762 fn r#gen ( & self , p : & mut Codegen , ctx : Context ) {
763+ p. add_source_mapping ( self . span ) ;
764764 p. print_decorators ( & self . decorators , ctx) ;
765765 if let Some ( accessibility) = self . accessibility {
766766 p. print_space_before_identifier ( ) ;
@@ -903,7 +903,6 @@ impl Gen for ImportDeclaration<'_> {
903903 p. print_soft_space ( ) ;
904904 with_clause. print ( p, ctx) ;
905905 }
906- p. add_source_mapping_end ( self . span ) ;
907906 p. print_semicolon_after_statement ( ) ;
908907 }
909908}
@@ -923,8 +922,8 @@ impl Gen for WithClause<'_> {
923922 p. print_list ( & self . with_entries , ctx) ;
924923 p. print_soft_space ( ) ;
925924 }
926- p. add_source_mapping_end ( self . span ) ;
927925 p. print_ascii_byte ( b'}' ) ;
926+ p. add_source_mapping_end ( self . span ) ;
928927 }
929928}
930929
@@ -1204,7 +1203,7 @@ impl Gen for IdentifierReference<'_> {
12041203impl Gen for IdentifierName < ' _ > {
12051204 fn r#gen ( & self , p : & mut Codegen , _ctx : Context ) {
12061205 p. print_space_before_identifier ( ) ;
1207- p. add_source_mapping ( self . span ) ;
1206+ p. add_source_mapping_for_name ( self . span , & self . name ) ;
12081207 p. print_str ( self . name . as_str ( ) ) ;
12091208 }
12101209}
@@ -1399,6 +1398,7 @@ impl GenExpr for CallExpression<'_> {
13991398
14001399 p. wrap ( wrap, |p| {
14011400 if pure {
1401+ p. add_source_mapping ( self . span ) ;
14021402 p. print_str ( PURE_COMMENT ) ;
14031403 }
14041404 if is_export_default {
@@ -1414,7 +1414,6 @@ impl GenExpr for CallExpression<'_> {
14141414 type_parameters. print ( p, ctx) ;
14151415 }
14161416 p. print_arguments ( self . span , & self . arguments , ctx) ;
1417- p. add_source_mapping_end ( self . span ) ;
14181417 } ) ;
14191418 }
14201419}
@@ -1474,8 +1473,8 @@ impl Gen for ArrayExpression<'_> {
14741473 p. dedent ( ) ;
14751474 p. print_indent ( ) ;
14761475 }
1477- p. add_source_mapping_end ( self . span ) ;
14781476 p. print_ascii_byte ( b']' ) ;
1477+ p. add_source_mapping_end ( self . span ) ;
14791478 }
14801479}
14811480
@@ -1517,8 +1516,8 @@ impl GenExpr for ObjectExpression<'_> {
15171516 } else if len > 0 {
15181517 p. print_soft_space ( ) ;
15191518 }
1520- p. add_source_mapping_end ( self . span ) ;
15211519 p. print_ascii_byte ( b'}' ) ;
1520+ p. add_source_mapping_end ( self . span ) ;
15221521 } ) ;
15231522 }
15241523}
@@ -1539,13 +1538,11 @@ impl Gen for ObjectProperty<'_> {
15391538 let is_accessor = match & self . kind {
15401539 PropertyKind :: Init => false ,
15411540 PropertyKind :: Get => {
1542- p. add_source_mapping ( self . span ) ;
15431541 p. print_str ( "get" ) ;
15441542 p. print_soft_space ( ) ;
15451543 true
15461544 }
15471545 PropertyKind :: Set => {
1548- p. add_source_mapping ( self . span ) ;
15491546 p. print_str ( "set" ) ;
15501547 p. print_soft_space ( ) ;
15511548 true
@@ -1649,7 +1646,6 @@ impl GenExpr for ArrowFunctionExpression<'_> {
16491646 if let Some ( type_parameters) = & self . type_parameters {
16501647 type_parameters. print ( p, ctx) ;
16511648 }
1652- p. add_source_mapping ( self . span ) ;
16531649 let remove_params_wrap = p. options . minify
16541650 && self . params . items . len ( ) == 1
16551651 && self . params . rest . is_none ( )
@@ -1708,14 +1704,15 @@ impl GenExpr for UpdateExpression<'_> {
17081704 let operator = self . operator . as_str ( ) ;
17091705 p. wrap ( precedence >= self . precedence ( ) , |p| {
17101706 if self . prefix {
1711- p. add_source_mapping ( self . span ) ;
17121707 p. print_space_before_operator ( self . operator . into ( ) ) ;
1708+ p. add_source_mapping ( self . span ) ;
17131709 p. print_str ( operator) ;
17141710 p. prev_op = Some ( self . operator . into ( ) ) ;
17151711 p. prev_op_end = p. code ( ) . len ( ) ;
17161712 self . argument . print_expr ( p, Precedence :: Prefix , ctx) ;
17171713 } else {
17181714 p. print_space_before_operator ( self . operator . into ( ) ) ;
1715+ p. add_source_mapping ( self . span ) ;
17191716 self . argument . print_expr ( p, Precedence :: Postfix , ctx) ;
17201717 p. print_str ( operator) ;
17211718 p. prev_op = Some ( self . operator . into ( ) ) ;
@@ -1779,6 +1776,7 @@ impl GenExpr for BinaryExpression<'_> {
17791776impl GenExpr for PrivateInExpression < ' _ > {
17801777 fn gen_expr ( & self , p : & mut Codegen , precedence : Precedence , ctx : Context ) {
17811778 p. wrap ( precedence >= Precedence :: Compare , |p| {
1779+ p. add_source_mapping ( self . span ) ;
17821780 self . left . print ( p, ctx) ;
17831781 p. print_str ( " in " ) ;
17841782 self . right . print_expr ( p, Precedence :: Equals , Context :: FORBID_IN ) ;
@@ -1833,6 +1831,7 @@ impl GenExpr for AssignmentExpression<'_> {
18331831 let wrap = ( p. start_of_stmt == n || p. start_of_arrow_expr == n)
18341832 && matches ! ( self . left, AssignmentTarget :: ObjectAssignmentTarget ( _) ) ;
18351833 p. wrap ( wrap || precedence >= self . precedence ( ) , |p| {
1834+ p. add_source_mapping ( self . span ) ;
18361835 self . left . print ( p, ctx) ;
18371836 p. print_soft_space ( ) ;
18381837 p. print_str ( self . operator . as_str ( ) ) ;
@@ -1903,7 +1902,6 @@ impl Gen for ArrayAssignmentTarget<'_> {
19031902 if !self . elements . is_empty ( ) {
19041903 p. print_soft_space ( ) ;
19051904 }
1906- p. add_source_mapping ( self . span ) ;
19071905 target. print ( p, ctx) ;
19081906 }
19091907 p. print_ascii_byte ( b']' ) ;
@@ -1921,7 +1919,6 @@ impl Gen for ObjectAssignmentTarget<'_> {
19211919 p. print_comma ( ) ;
19221920 p. print_soft_space ( ) ;
19231921 }
1924- p. add_source_mapping ( self . span ) ;
19251922 target. print ( p, ctx) ;
19261923 }
19271924 p. print_ascii_byte ( b'}' ) ;
@@ -2093,27 +2090,17 @@ impl Gen for TemplateLiteral<'_> {
20932090 fn r#gen ( & self , p : & mut Codegen , _ctx : Context ) {
20942091 p. add_source_mapping ( self . span ) ;
20952092 p. print_ascii_byte ( b'`' ) ;
2096-
20972093 debug_assert_eq ! ( self . quasis. len( ) , self . expressions. len( ) + 1 ) ;
2098-
20992094 let ( first_quasi, remaining_quasis) = self . quasis . split_first ( ) . unwrap ( ) ;
2100-
2101- p. add_source_mapping ( first_quasi. span ) ;
21022095 p. print_str_escaping_script_close_tag ( first_quasi. value . raw . as_str ( ) ) ;
2103- p. add_source_mapping_end ( first_quasi. span ) ;
2104-
21052096 for ( expr, quasi) in self . expressions . iter ( ) . zip ( remaining_quasis) {
21062097 p. print_str ( "${" ) ;
21072098 p. print_expression ( expr) ;
21082099 p. print_ascii_byte ( b'}' ) ;
2109-
21102100 p. add_source_mapping ( quasi. span ) ;
21112101 p. print_str_escaping_script_close_tag ( quasi. value . raw . as_str ( ) ) ;
2112- p. add_source_mapping_end ( quasi. span ) ;
21132102 }
2114-
21152103 p. print_ascii_byte ( b'`' ) ;
2116- p. add_source_mapping_end ( self . span ) ;
21172104 }
21182105}
21192106
@@ -2267,7 +2254,6 @@ impl Gen for MetaProperty<'_> {
22672254
22682255impl Gen for Class < ' _ > {
22692256 fn r#gen ( & self , p : & mut Codegen , ctx : Context ) {
2270- p. add_source_mapping ( self . span ) ;
22712257 let n = p. code_len ( ) ;
22722258 let wrap = self . is_expression ( ) && ( p. start_of_stmt == n || p. start_of_default_export == n) ;
22732259 p. wrap ( wrap, |p| {
@@ -2588,33 +2574,28 @@ impl Gen for MethodDefinition<'_> {
25882574 }
25892575 if self . r#static {
25902576 p. print_space_before_identifier ( ) ;
2591- p. add_source_mapping ( self . span ) ;
25922577 p. print_str ( "static" ) ;
25932578 p. print_soft_space ( ) ;
25942579 }
25952580 match & self . kind {
25962581 MethodDefinitionKind :: Constructor | MethodDefinitionKind :: Method => { }
25972582 MethodDefinitionKind :: Get => {
25982583 p. print_space_before_identifier ( ) ;
2599- p. add_source_mapping ( self . span ) ;
26002584 p. print_str ( "get" ) ;
26012585 p. print_soft_space ( ) ;
26022586 }
26032587 MethodDefinitionKind :: Set => {
26042588 p. print_space_before_identifier ( ) ;
2605- p. add_source_mapping ( self . span ) ;
26062589 p. print_str ( "set" ) ;
26072590 p. print_soft_space ( ) ;
26082591 }
26092592 }
26102593 if self . value . r#async {
26112594 p. print_space_before_identifier ( ) ;
2612- p. add_source_mapping ( self . span ) ;
26132595 p. print_str ( "async" ) ;
26142596 p. print_soft_space ( ) ;
26152597 }
26162598 if self . value . generator {
2617- p. add_source_mapping ( self . span ) ;
26182599 p. print_str ( "*" ) ;
26192600 }
26202601 if self . computed {
@@ -2675,7 +2656,6 @@ impl Gen for PropertyDefinition<'_> {
26752656 }
26762657 if self . r#static {
26772658 p. print_space_before_identifier ( ) ;
2678- p. add_source_mapping ( self . span ) ;
26792659 p. print_str ( "static" ) ;
26802660 p. print_soft_space ( ) ;
26812661 }
@@ -2714,7 +2694,6 @@ impl Gen for AccessorProperty<'_> {
27142694 p. print_decorators ( & self . decorators , ctx) ;
27152695 if self . r#type . is_abstract ( ) {
27162696 p. print_space_before_identifier ( ) ;
2717- p. add_source_mapping ( self . span ) ;
27182697 p. print_str ( "abstract" ) ;
27192698 p. print_soft_space ( ) ;
27202699 }
@@ -2725,7 +2704,6 @@ impl Gen for AccessorProperty<'_> {
27252704 }
27262705 if self . r#static {
27272706 p. print_space_before_identifier ( ) ;
2728- p. add_source_mapping ( self . span ) ;
27292707 p. print_str ( "static" ) ;
27302708 p. print_soft_space ( ) ;
27312709 }
@@ -2762,8 +2740,8 @@ impl Gen for AccessorProperty<'_> {
27622740
27632741impl Gen for PrivateIdentifier < ' _ > {
27642742 fn r#gen ( & self , p : & mut Codegen , _ctx : Context ) {
2765- p. add_source_mapping_for_name ( self . span , & self . name ) ;
27662743 p. print_ascii_byte ( b'#' ) ;
2744+ p. add_source_mapping_for_name ( self . span , & self . name ) ;
27672745 p. print_str ( self . name . as_str ( ) ) ;
27682746 }
27692747}
@@ -2817,7 +2795,6 @@ impl Gen for ObjectPattern<'_> {
28172795
28182796impl Gen for BindingProperty < ' _ > {
28192797 fn r#gen ( & self , p : & mut Codegen , ctx : Context ) {
2820- p. add_source_mapping ( self . span ) ;
28212798 if self . computed {
28222799 p. print_ascii_byte ( b'[' ) ;
28232800 }
@@ -3816,7 +3793,6 @@ impl GenExpr for V8IntrinsicExpression<'_> {
38163793 p. print_ascii_byte ( b'%' ) ;
38173794 self . name . print ( p, Context :: empty ( ) ) ;
38183795 p. print_arguments ( self . span , & self . arguments , ctx) ;
3819- p. add_source_mapping_end ( self . span ) ;
38203796 } ) ;
38213797 }
38223798}
0 commit comments