@@ -212,6 +212,7 @@ pub fn parser_args(
212212 version : & str ,
213213 workspace_root : & Option < String > ,
214214 root_path : & str ,
215+ contents : & str ,
215216) -> ( String , Vec < String > ) {
216217 let file = & filename. to_string ( ) ;
217218 let path = PathBuf :: from ( filename) ;
@@ -223,7 +224,7 @@ pub fn parser_args(
223224 } else {
224225 format ! ( "{}/node_modules" , & root_path)
225226 } ,
226- & filter_ppx_flags ( & config. ppx_flags ) ,
227+ & filter_ppx_flags ( & config. ppx_flags , contents ) ,
227228 & config. name ,
228229 ) ;
229230 let jsx_args = root_config. get_jsx_args ( ) ;
@@ -263,6 +264,9 @@ fn generate_ast(
263264 bsc_path : & str ,
264265 workspace_root : & Option < String > ,
265266) -> 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+
266270 let build_path_abs = package. get_build_path ( ) ;
267271 let ( ast_path, parser_args) = parser_args (
268272 & package. bsconfig ,
@@ -271,6 +275,7 @@ fn generate_ast(
271275 version,
272276 workspace_root,
273277 & root_package. path ,
278+ & contents,
274279 ) ;
275280
276281 /* Create .ast */
@@ -309,19 +314,28 @@ fn path_to_ast_extension(path: &Path) -> &str {
309314 }
310315}
311316
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 > > > {
313332 // 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- } ;
318333 ppx_flags. as_ref ( ) . map ( |flags| {
319334 flags
320335 . 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) ,
325339 } )
326340 . map ( |x| x. to_owned ( ) )
327341 . collect :: < Vec < OneOrMore < String > > > ( )
0 commit comments