File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ impl Gen for Program<'_> {
4646 fn r#gen ( & self , p : & mut Codegen , ctx : Context ) {
4747 p. is_jsx = self . source_type . is_jsx ( ) ;
4848
49+ // Allow for inserting comments to the top of the file.
50+ p. print_comments_at ( 0 ) ;
4951 if let Some ( hashbang) = & self . hashbang {
5052 hashbang. print ( p, ctx) ;
5153 }
Original file line number Diff line number Diff line change 11use crate :: tester:: { test, test_same} ;
22
3+ #[ test]
4+ fn test_comment_at_top_of_file ( ) {
5+ use oxc_allocator:: Allocator ;
6+ use oxc_ast:: CommentPosition ;
7+ use oxc_codegen:: Codegen ;
8+ use oxc_parser:: Parser ;
9+ use oxc_span:: SourceType ;
10+ let source_type = SourceType :: mjs ( ) ;
11+ let allocator = Allocator :: default ( ) ;
12+ let mut ret = Parser :: new ( & allocator, "export{} /** comment */" , source_type) . parse ( ) ;
13+ // Move comment to top of the file.
14+ ret. program . comments [ 0 ] . attached_to = 0 ;
15+ ret. program . comments [ 0 ] . position = CommentPosition :: Leading ;
16+ let code = Codegen :: new ( ) . build ( & ret. program ) . code ;
17+ assert_eq ! ( code, "/** comment */ export {};\n " ) ;
18+ }
19+
320#[ test]
421fn unit ( ) {
522 test_same ( "<div>{/* Hello */}</div>;\n " ) ;
You can’t perform that action at this time.
0 commit comments