@@ -212,6 +212,7 @@ pub fn parser_args(
212
212
version : & str ,
213
213
workspace_root : & Option < String > ,
214
214
root_path : & str ,
215
+ contents : & str ,
215
216
) -> ( String , Vec < String > ) {
216
217
let file = & filename. to_string ( ) ;
217
218
let path = PathBuf :: from ( filename) ;
@@ -223,7 +224,7 @@ pub fn parser_args(
223
224
} else {
224
225
format ! ( "{}/node_modules" , & root_path)
225
226
} ,
226
- & filter_ppx_flags ( & config. ppx_flags ) ,
227
+ & filter_ppx_flags ( & config. ppx_flags , contents ) ,
227
228
& config. name ,
228
229
) ;
229
230
let jsx_args = root_config. get_jsx_args ( ) ;
@@ -263,6 +264,9 @@ fn generate_ast(
263
264
bsc_path : & str ,
264
265
workspace_root : & Option < String > ,
265
266
) -> Result < ( String , Option < String > ) , String > {
267
+ let file_path = PathBuf :: from ( & package. path ) . join ( filename) ;
268
+ let contents = helpers:: read_file ( & file_path) . expect ( "Error reading file" ) ;
269
+
266
270
let build_path_abs = package. get_build_path ( ) ;
267
271
let ( ast_path, parser_args) = parser_args (
268
272
& package. bsconfig ,
@@ -271,6 +275,7 @@ fn generate_ast(
271
275
version,
272
276
workspace_root,
273
277
& root_package. path ,
278
+ & contents,
274
279
) ;
275
280
276
281
/* Create .ast */
@@ -309,19 +314,28 @@ fn path_to_ast_extension(path: &Path) -> &str {
309
314
}
310
315
}
311
316
312
- fn filter_ppx_flags ( ppx_flags : & Option < Vec < OneOrMore < String > > > ) -> Option < Vec < OneOrMore < String > > > {
317
+ fn include_ppx ( flag : & str , contents : & str ) -> bool {
318
+ if flag. contains ( "bisect" ) {
319
+ return std:: env:: var ( "BISECT_ENABLE" ) . is_ok ( ) ;
320
+ } else if flag. contains ( "graphql-ppx" ) && !contents. contains ( "%graphql" ) {
321
+ return false ;
322
+ } else if flag. contains ( "spice" ) && !contents. contains ( "@spice" ) {
323
+ return false ;
324
+ }
325
+ return true ;
326
+ }
327
+
328
+ fn filter_ppx_flags (
329
+ ppx_flags : & Option < Vec < OneOrMore < String > > > ,
330
+ contents : & str ,
331
+ ) -> Option < Vec < OneOrMore < String > > > {
313
332
// get the environment variable "BISECT_ENABLE" if it exists set the filter to "bisect"
314
- let filter = match std:: env:: var ( "BISECT_ENABLE" ) {
315
- Ok ( _) => None ,
316
- Err ( _) => Some ( "bisect" ) ,
317
- } ;
318
333
ppx_flags. as_ref ( ) . map ( |flags| {
319
334
flags
320
335
. iter ( )
321
- . filter ( |flag| match ( flag, filter) {
322
- ( bsconfig:: OneOrMore :: Single ( str) , Some ( filter) ) => !str. contains ( filter) ,
323
- ( bsconfig:: OneOrMore :: Multiple ( str) , Some ( filter) ) => !str. first ( ) . unwrap ( ) . contains ( filter) ,
324
- _ => true ,
336
+ . filter ( |flag| match flag {
337
+ bsconfig:: OneOrMore :: Single ( str) => include_ppx ( str, contents) ,
338
+ bsconfig:: OneOrMore :: Multiple ( str) => include_ppx ( str. first ( ) . unwrap ( ) , contents) ,
325
339
} )
326
340
. map ( |x| x. to_owned ( ) )
327
341
. collect :: < Vec < OneOrMore < String > > > ( )
0 commit comments