Browse Source

[macro] apply exception filters to macro code

Aleksandr Kuzmenko 5 years ago
parent
commit
54ff127c04
2 changed files with 12 additions and 14 deletions
  1. 5 12
      src/context/common.ml
  2. 7 2
      src/typing/macroContext.ml

+ 5 - 12
src/context/common.ml

@@ -350,8 +350,8 @@ let default_config =
 		pf_exceptions = {
 		pf_exceptions = {
 			ec_native_throws = [];
 			ec_native_throws = [];
 			ec_native_catches = [];
 			ec_native_catches = [];
-			ec_wildcard_catch = ([],"Dynamic");
-			ec_base_throw = ([],"Dynamic");
+			ec_wildcard_catch = (["StdTypes"],"Dynamic");
+			ec_base_throw = (["StdTypes"],"Dynamic");
 		};
 		};
 		pf_nested_function_scoping = Independent;
 		pf_nested_function_scoping = Independent;
 	}
 	}
@@ -369,14 +369,11 @@ let get_config com =
 			pf_capture_policy = CPLoopVars;
 			pf_capture_policy = CPLoopVars;
 			pf_reserved_type_paths = [([],"Object");([],"Error")];
 			pf_reserved_type_paths = [([],"Object");([],"Error")];
 			pf_this_before_super = (get_es_version com) < 6; (* cannot access `this` before `super()` when generating ES6 classes *)
 			pf_this_before_super = (get_es_version com) < 6; (* cannot access `this` before `super()` when generating ES6 classes *)
-			pf_exceptions = {
+			pf_exceptions = { default_config.pf_exceptions with
 				ec_native_throws = [
 				ec_native_throws = [
 					["js";"lib"],"Error";
 					["js";"lib"],"Error";
 					["haxe"],"Exception";
 					["haxe"],"Exception";
 				];
 				];
-				ec_native_catches = [];
-				ec_wildcard_catch = ([],"Dynamic");
-				ec_base_throw = ([],"Dynamic");
 			};
 			};
 			pf_nested_function_scoping = Hoisted;
 			pf_nested_function_scoping = Hoisted;
 		}
 		}
@@ -403,7 +400,7 @@ let get_config com =
 			pf_capture_policy = CPLoopVars;
 			pf_capture_policy = CPLoopVars;
 			pf_can_skip_non_nullable_argument = false;
 			pf_can_skip_non_nullable_argument = false;
 			pf_reserved_type_paths = [([],"Object");([],"Error")];
 			pf_reserved_type_paths = [([],"Object");([],"Error")];
-			pf_exceptions = {
+			pf_exceptions = { default_config.pf_exceptions with
 				ec_native_throws = [
 				ec_native_throws = [
 					["flash";"errors"],"Error";
 					["flash";"errors"],"Error";
 					["haxe"],"Exception";
 					["haxe"],"Exception";
@@ -412,8 +409,6 @@ let get_config com =
 					["flash";"errors"],"Error";
 					["flash";"errors"],"Error";
 					["haxe"],"Exception";
 					["haxe"],"Exception";
 				];
 				];
-				ec_wildcard_catch = ([],"Dynamic");
-				ec_base_throw = ([],"Dynamic");
 			}
 			}
 		}
 		}
 	| Php ->
 	| Php ->
@@ -509,15 +504,13 @@ let get_config com =
 			pf_capture_policy = CPWrapRef;
 			pf_capture_policy = CPWrapRef;
 			pf_pad_nulls = true;
 			pf_pad_nulls = true;
 			pf_supports_threads = true;
 			pf_supports_threads = true;
-			pf_exceptions = {
+			pf_exceptions = { default_config.pf_exceptions with
 				ec_native_throws = [
 				ec_native_throws = [
 					["haxe"],"Exception";
 					["haxe"],"Exception";
 				];
 				];
 				ec_native_catches = [
 				ec_native_catches = [
 					["haxe"],"Exception";
 					["haxe"],"Exception";
 				];
 				];
-				ec_wildcard_catch = ([],"Dynamic");
-				ec_base_throw = ([],"Dynamic");
 			}
 			}
 		}
 		}
 	| Eval ->
 	| Eval ->

+ 7 - 2
src/typing/macroContext.ml

@@ -420,8 +420,12 @@ and flush_macro_context mint ctx =
 	mctx.com.types <- types;
 	mctx.com.types <- types;
 	mctx.com.Common.modules <- modules;
 	mctx.com.Common.modules <- modules;
 	(* we should maybe ensure that all filters in Main are applied. Not urgent atm *)
 	(* we should maybe ensure that all filters in Main are applied. Not urgent atm *)
-	let expr_filters = [VarLazifier.apply mctx.com;AbstractCast.handle_abstract_casts mctx; CapturedVars.captured_vars mctx.com;] in
-
+	let expr_filters = [
+		VarLazifier.apply mctx.com;
+		AbstractCast.handle_abstract_casts mctx;
+		Exceptions.filter mctx;
+		CapturedVars.captured_vars mctx.com;
+	] in
 	(*
 	(*
 		some filters here might cause side effects that would break compilation server.
 		some filters here might cause side effects that would break compilation server.
 		let's save the minimal amount of information we need
 		let's save the minimal amount of information we need
@@ -436,6 +440,7 @@ and flush_macro_context mint ctx =
 			()
 			()
 	in
 	in
 	let type_filters = [
 	let type_filters = [
+		Exceptions.patch_constructors mctx;
 		Filters.add_field_inits (StringMap.empty) mctx;
 		Filters.add_field_inits (StringMap.empty) mctx;
 		minimal_restore;
 		minimal_restore;
 		Filters.apply_native_paths mctx
 		Filters.apply_native_paths mctx