File tree Expand file tree Collapse file tree 3 files changed +26
-5
lines changed
Expand file tree Collapse file tree 3 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 22use std:: { env, path:: Path } ;
33
44use oxc_allocator:: Allocator ;
5- use oxc_codegen:: { CodeGenerator , WhitespaceRemover } ;
5+ use oxc_codegen:: { CodeGenerator , CommentOptions , WhitespaceRemover } ;
66use oxc_parser:: Parser ;
77use oxc_span:: SourceType ;
88use pico_args:: Arguments ;
@@ -35,7 +35,14 @@ fn main() -> std::io::Result<()> {
3535 println ! ( "{source_text}" ) ;
3636
3737 println ! ( "First time:" ) ;
38- let printed = CodeGenerator :: new ( ) . build ( & ret. program ) . source_text ;
38+ let printed = CodeGenerator :: new ( )
39+ . enable_comment (
40+ & source_text,
41+ ret. trivias . clone ( ) ,
42+ CommentOptions { preserve_annotate_comments : true } ,
43+ )
44+ . build ( & ret. program )
45+ . source_text ;
3946 println ! ( "{printed}" ) ;
4047
4148 if twice {
@@ -48,7 +55,14 @@ fn main() -> std::io::Result<()> {
4855 }
4956 return Ok ( ( ) ) ;
5057 }
51- let printed = CodeGenerator :: new ( ) . build ( & ret. program ) . source_text ;
58+ let printed = CodeGenerator :: new ( )
59+ . enable_comment (
60+ & source_text,
61+ ret. trivias . clone ( ) ,
62+ CommentOptions { preserve_annotate_comments : true } ,
63+ )
64+ . build ( & ret. program )
65+ . source_text ;
5266 println ! ( "{printed}" ) ;
5367 }
5468
Original file line number Diff line number Diff line change @@ -1419,8 +1419,8 @@ impl<'a, const MINIFY: bool> GenExpr<MINIFY> for CallExpression<'a> {
14191419 fn gen_expr ( & self , p : & mut Codegen < { MINIFY } > , precedence : Precedence , ctx : Context ) {
14201420 let wrap = precedence > self . precedence ( ) || ctx. has_forbid_call ( ) ;
14211421 let ctx = ctx. and_forbid_call ( false ) ;
1422- p. gen_comment ( self . span . start ) ;
14231422 p. wrap ( wrap, |p| {
1423+ p. gen_comment ( self . span . start ) ;
14241424 p. add_source_mapping ( self . span . start ) ;
14251425 self . callee . gen_expr ( p, self . precedence ( ) , ctx) ;
14261426 if self . optional {
@@ -2049,8 +2049,8 @@ impl<'a, const MINIFY: bool> GenExpr<MINIFY> for ChainExpression<'a> {
20492049
20502050impl < ' a , const MINIFY : bool > GenExpr < MINIFY > for NewExpression < ' a > {
20512051 fn gen_expr ( & self , p : & mut Codegen < { MINIFY } > , precedence : Precedence , ctx : Context ) {
2052- p. gen_comment ( self . span . start ) ;
20532052 p. wrap ( precedence > self . precedence ( ) , |p| {
2053+ p. gen_comment ( self . span . start ) ;
20542054 p. add_source_mapping ( self . span . start ) ;
20552055 p. print_str ( "new " ) ;
20562056 self . callee . gen_expr ( p, Precedence :: NewWithoutArgs , ctx. and_forbid_call ( true ) ) ;
Original file line number Diff line number Diff line change @@ -200,4 +200,11 @@ const builtInSymbols = new Set(
200200" ,
201201 "const builtInSymbols = new Set(/*#__PURE__*/ (Object.getOwnPropertyNames(Symbol)).filter((key) => key !== \" arguments\" && key !== \" caller\" ));\n " ,
202202 ) ;
203+
204+ test_comment_helper (
205+ "(/* @__PURE__ */ new Foo()).bar();\n " ,
206+ "(/* @__PURE__ */ new Foo()).bar();\n " ,
207+ ) ;
208+
209+ test_comment_helper ( "(/* @__PURE__ */ Foo()).bar();\n " , "(/* @__PURE__ */ Foo()).bar();\n " ) ;
203210}
You can’t perform that action at this time.
0 commit comments