@@ -11,11 +11,12 @@ use crate::visit::DevupVisitor;
1111use oxc_allocator:: Allocator ;
1212use oxc_ast:: ast:: Expression ;
1313use oxc_ast_visit:: VisitMut ;
14- use oxc_codegen:: Codegen ;
14+ use oxc_codegen:: { Codegen , CodegenOptions } ;
1515use oxc_parser:: { Parser , ParserReturn } ;
1616use oxc_span:: SourceType ;
1717use std:: collections:: { BTreeMap , HashSet } ;
1818use std:: error:: Error ;
19+ use std:: path:: PathBuf ;
1920#[ derive( Debug ) ]
2021pub enum ExtractStyleProp < ' a > {
2122 Static ( ExtractStyleValue ) ,
@@ -80,6 +81,8 @@ pub struct ExtractOutput {
8081
8182 // output source
8283 pub code : String ,
84+
85+ pub map : Option < String > ,
8386}
8487
8588pub struct ExtractOption {
@@ -98,6 +101,7 @@ pub fn extract(
98101 return Ok ( ExtractOutput {
99102 styles : HashSet :: new ( ) ,
100103 code : code. to_string ( ) ,
104+ map : None ,
101105 } ) ;
102106 }
103107 let allocator = Allocator :: default ( ) ;
@@ -113,16 +117,22 @@ pub fn extract(
113117 let mut visitor = DevupVisitor :: new (
114118 & allocator,
115119 & option. package ,
116- option
120+ & option
117121 . css_file
118- . unwrap_or ( format ! ( "{}/devup-ui.css" , option. package) )
119- . as_str ( ) ,
122+ . unwrap_or ( format ! ( "{}/devup-ui.css" , option. package) ) ,
120123 ) ;
121124 visitor. visit_program ( & mut program) ;
125+ let result = Codegen :: new ( )
126+ . with_options ( CodegenOptions {
127+ source_map_path : Some ( PathBuf :: from ( filename) ) ,
128+ ..Default :: default ( )
129+ } )
130+ . build ( & program) ;
122131
123132 Ok ( ExtractOutput {
124133 styles : visitor. styles ,
125- code : Codegen :: new ( ) . build ( & program) . code ,
134+ code : result. code ,
135+ map : result. map . map ( |m| m. to_json_string ( ) ) ,
126136 } )
127137}
128138
0 commit comments