@@ -50,40 +50,45 @@ impl Task for TransformTask {
50
50
51
51
let error_format = options. experimental . error_format . unwrap_or_default ( ) ;
52
52
53
- try_with (
54
- self . c . cm . clone ( ) ,
55
- !options. config . error . filename . into_bool ( ) ,
56
- error_format,
57
- |handler| {
58
- self . c . run ( || match & self . input {
59
- Input :: Program ( ref s) => {
60
- let program: Program =
61
- deserialize_json ( s) . expect ( "failed to deserialize Program" ) ;
62
- // TODO: Source map
63
- self . c . process_js ( handler, program, & options)
64
- }
65
-
66
- Input :: File ( ref path) => {
67
- let fm = self . c . cm . load_file ( path) . context ( "failed to load file" ) ?;
68
- self . c . process_js_file ( fm, handler, & options)
69
- }
70
-
71
- Input :: Source { src } => {
72
- let fm = self . c . cm . new_source_file (
73
- if options. filename . is_empty ( ) {
74
- FileName :: Anon
75
- } else {
76
- FileName :: Real ( options. filename . clone ( ) . into ( ) )
77
- } ,
78
- src. to_string ( ) ,
79
- ) ;
80
-
81
- self . c . process_js_file ( fm, handler, & options)
82
- }
83
- } )
84
- } ,
85
- )
86
- . convert_err ( )
53
+ tokio:: runtime:: Runtime :: new ( )
54
+ . unwrap ( )
55
+ . block_on ( async move {
56
+ try_with (
57
+ self . c . cm . clone ( ) ,
58
+ !options. config . error . filename . into_bool ( ) ,
59
+ error_format,
60
+ |handler| {
61
+ self . c . run ( || match & self . input {
62
+ Input :: Program ( ref s) => {
63
+ let program: Program =
64
+ deserialize_json ( s) . expect ( "failed to deserialize Program" ) ;
65
+ // TODO: Source map
66
+ self . c . process_js ( handler, program, & options)
67
+ }
68
+
69
+ Input :: File ( ref path) => {
70
+ let fm =
71
+ self . c . cm . load_file ( path) . context ( "failed to load file" ) ?;
72
+ self . c . process_js_file ( fm, handler, & options)
73
+ }
74
+
75
+ Input :: Source { src } => {
76
+ let fm = self . c . cm . new_source_file (
77
+ if options. filename . is_empty ( ) {
78
+ FileName :: Anon
79
+ } else {
80
+ FileName :: Real ( options. filename . clone ( ) . into ( ) )
81
+ } ,
82
+ src. to_string ( ) ,
83
+ ) ;
84
+
85
+ self . c . process_js_file ( fm, handler, & options)
86
+ }
87
+ } )
88
+ } ,
89
+ )
90
+ } )
91
+ . convert_err ( )
87
92
}
88
93
89
94
fn resolve ( & mut self , _env : Env , result : Self :: Output ) -> napi:: Result < Self :: JsValue > {
@@ -137,31 +142,35 @@ pub fn transform_sync(s: String, is_module: bool, opts: Buffer) -> napi::Result<
137
142
138
143
let error_format = options. experimental . error_format . unwrap_or_default ( ) ;
139
144
140
- try_with (
141
- c. cm . clone ( ) ,
142
- !options. config . error . filename . into_bool ( ) ,
143
- error_format,
144
- |handler| {
145
- c. run ( || {
146
- if is_module {
147
- let program: Program =
148
- deserialize_json ( s. as_str ( ) ) . context ( "failed to deserialize Program" ) ?;
149
- c. process_js ( handler, program, & options)
150
- } else {
151
- let fm = c. cm . new_source_file (
152
- if options. filename . is_empty ( ) {
153
- FileName :: Anon
145
+ tokio:: runtime:: Runtime :: new ( )
146
+ . unwrap ( )
147
+ . block_on ( async move {
148
+ try_with (
149
+ c. cm . clone ( ) ,
150
+ !options. config . error . filename . into_bool ( ) ,
151
+ error_format,
152
+ |handler| {
153
+ c. run ( || {
154
+ if is_module {
155
+ let program: Program = deserialize_json ( s. as_str ( ) )
156
+ . context ( "failed to deserialize Program" ) ?;
157
+ c. process_js ( handler, program, & options)
154
158
} else {
155
- FileName :: Real ( options. filename . clone ( ) . into ( ) )
156
- } ,
157
- s,
158
- ) ;
159
- c. process_js_file ( fm, handler, & options)
160
- }
161
- } )
162
- } ,
163
- )
164
- . convert_err ( )
159
+ let fm = c. cm . new_source_file (
160
+ if options. filename . is_empty ( ) {
161
+ FileName :: Anon
162
+ } else {
163
+ FileName :: Real ( options. filename . clone ( ) . into ( ) )
164
+ } ,
165
+ s,
166
+ ) ;
167
+ c. process_js_file ( fm, handler, & options)
168
+ }
169
+ } )
170
+ } ,
171
+ )
172
+ } )
173
+ . convert_err ( )
165
174
}
166
175
167
176
#[ napi]
@@ -203,22 +212,26 @@ pub fn transform_file_sync(
203
212
204
213
let error_format = options. experimental . error_format . unwrap_or_default ( ) ;
205
214
206
- try_with (
207
- c. cm . clone ( ) ,
208
- !options. config . error . filename . into_bool ( ) ,
209
- error_format,
210
- |handler| {
211
- c. run ( || {
212
- if is_module {
213
- let program: Program =
214
- deserialize_json ( s. as_str ( ) ) . context ( "failed to deserialize Program" ) ?;
215
- c. process_js ( handler, program, & options)
216
- } else {
217
- let fm = c. cm . load_file ( Path :: new ( & s) ) . expect ( "failed to load file" ) ;
218
- c. process_js_file ( fm, handler, & options)
219
- }
220
- } )
221
- } ,
222
- )
223
- . convert_err ( )
215
+ tokio:: runtime:: Runtime :: new ( )
216
+ . unwrap ( )
217
+ . block_on ( async move {
218
+ try_with (
219
+ c. cm . clone ( ) ,
220
+ !options. config . error . filename . into_bool ( ) ,
221
+ error_format,
222
+ |handler| {
223
+ c. run ( || {
224
+ if is_module {
225
+ let program: Program = deserialize_json ( s. as_str ( ) )
226
+ . context ( "failed to deserialize Program" ) ?;
227
+ c. process_js ( handler, program, & options)
228
+ } else {
229
+ let fm = c. cm . load_file ( Path :: new ( & s) ) . expect ( "failed to load file" ) ;
230
+ c. process_js_file ( fm, handler, & options)
231
+ }
232
+ } )
233
+ } ,
234
+ )
235
+ } )
236
+ . convert_err ( )
224
237
}
0 commit comments