@@ -65,7 +65,7 @@ fn transform(ctx: CallContext) -> napi::Result<JsBuffer> {
6565 let opts = ctx. get :: < JsObject > ( 0 ) ?;
6666 let config: Config = ctx. env . from_js_value ( opts) ?;
6767 let code = unsafe { std:: str:: from_utf8_unchecked ( & config. code ) } ;
68- let res = compile ( code, config. minify . unwrap_or ( false ) , config. targets ) ;
68+ let res = compile ( code, config. minify . unwrap_or ( false ) , config. targets ) . unwrap ( ) ;
6969
7070 Ok ( ctx. env . create_buffer_with_data ( res. into_bytes ( ) ) ?. into_raw ( ) )
7171}
@@ -89,7 +89,7 @@ struct Config {
8989 pub minify : Option < bool >
9090}
9191
92- fn compile ( code : & str , minify : bool , targets : Option < Browsers > ) -> String {
92+ fn compile ( code : & str , minify : bool , targets : Option < Browsers > ) -> Result < String , std :: fmt :: Error > {
9393 let mut input = ParserInput :: new ( & code) ;
9494 let mut parser = Parser :: new ( & mut input) ;
9595 let rule_list = RuleListParser :: new_for_stylesheet ( & mut parser, TopLevelRuleParser { } ) ;
@@ -202,14 +202,14 @@ fn compile(code: &str, minify: bool, targets: Option<Browsers>) -> String {
202202 if first {
203203 first = false ;
204204 } else {
205- printer. newline ( ) ;
205+ printer. newline ( ) ? ;
206206 }
207207
208- rule. to_css ( & mut printer) ;
209- printer. newline ( ) ;
208+ rule. to_css ( & mut printer) ? ;
209+ printer. newline ( ) ? ;
210210 }
211211
212- dest
212+ Ok ( dest)
213213}
214214
215215#[ cfg( test) ]
@@ -219,17 +219,17 @@ mod tests {
219219 use self :: indoc:: indoc;
220220
221221 fn test ( source : & str , expected : & str ) {
222- let res = compile ( source, false , None ) ;
222+ let res = compile ( source, false , None ) . unwrap ( ) ;
223223 assert_eq ! ( res, expected) ;
224224 }
225225
226226 fn minify_test ( source : & str , expected : & str ) {
227- let res = compile ( source, true , None ) ;
227+ let res = compile ( source, true , None ) . unwrap ( ) ;
228228 assert_eq ! ( res, expected) ;
229229 }
230230
231231 fn prefix_test ( source : & str , expected : & str , targets : Browsers ) {
232- let res = compile ( source, false , Some ( targets) ) ;
232+ let res = compile ( source, false , Some ( targets) ) . unwrap ( ) ;
233233 assert_eq ! ( res, expected) ;
234234 }
235235
@@ -1927,7 +1927,7 @@ mod tests {
19271927 font-variant-caps: small-caps;
19281928 line-height: 1.2em;
19291929 }
1930- "# , indoc ! { ".foo{font:italic small-caps 700 50 % 12px/1.2em Helvetica,Times New Roman,sans-serif}"
1930+ "# , indoc ! { ".foo{font:italic small-caps 700 125 % 12px/1.2em Helvetica,Times New Roman,sans-serif}"
19311931 } ) ;
19321932
19331933 test ( r#"
@@ -1948,7 +1948,7 @@ mod tests {
19481948 font-size: 12px;
19491949 font-stretch: expanded;
19501950 }
1951- "# , indoc ! { ".foo{font-family:Helvetica,Times New Roman,sans-serif;font-size:12px;font-stretch:50 %}"
1951+ "# , indoc ! { ".foo{font-family:Helvetica,Times New Roman,sans-serif;font-size:12px;font-stretch:125 %}"
19521952 } ) ;
19531953
19541954 test ( r#"
0 commit comments