Przeglądaj źródła

added Array.map/filter compat for IE8, fixed DCE issues with abstract types

Nicolas Cannasse 12 lat temu
rodzic
commit
e6855aa88e
4 zmienionych plików z 35 dodań i 4 usunięć
  1. 1 1
      common.ml
  2. 11 3
      dce.ml
  3. 2 0
      main.ml
  4. 21 0
      std/js/_std/Std.hx

+ 1 - 1
common.ml

@@ -552,7 +552,7 @@ let rec has_feature com f =
 			let r = (try
 				let path = List.rev pack, cl in
 				(match List.find (fun t -> t_path t = path && not (has_meta ":realPath" (t_infos t).mt_meta)) com.types with
-				| t when meth = "*" -> has_meta ":used" (t_infos t).mt_meta
+				| t when meth = "*" -> (match t with TAbstractDecl a -> has_meta ":valueUsed" a.a_meta | _ -> has_meta ":used" (t_infos t).mt_meta)
 				| TClassDecl c -> PMap.exists meth c.cl_statics || PMap.exists meth c.cl_fields
 				| _ -> false)
 			with Not_found ->

+ 11 - 3
dce.ml

@@ -62,7 +62,7 @@ let keep_whole_class dce c =
 	|| not (dce.full || is_std_file dce c.cl_module.m_extra.m_file)
 	|| super_forces_keep c
 	|| (match c with
-		| { cl_extern = true; cl_path = ([],"Math")} when dce.com.platform = Js -> false
+		| { cl_extern = true; cl_path = ([],("Math"|"Array"))} when dce.com.platform = Js -> false
 		| { cl_extern = true }
 		| { cl_path = ["flash";"_Boot"],"RealBoot" } -> true
 		| { cl_path = [],"String" }
@@ -160,6 +160,8 @@ let mark_mt dce mt = match mt with
 	| TEnumDecl e ->
 		mark_enum dce e
 	| TAbstractDecl a ->
+		(* abstract 'feature' is defined as the abstract type beeing used as a value, not as a type *)
+		if not (has_meta ":valueUsed" a.a_meta) then a.a_meta <- (":valueUsed",[],a.a_pos) :: a.a_meta;
 		mark_abstract dce a
 	| TTypeDecl _ ->
 		()
@@ -399,8 +401,14 @@ let run com main full =
 			(match c.cl_constructor with Some cf when not (keep_field dce cf) -> c.cl_constructor <- None | _ -> ());
 			(* we keep a class if it was used or has a used field *)
 			if has_meta ":used" c.cl_meta || c.cl_ordered_statics <> [] || c.cl_ordered_fields <> [] then loop (mt :: acc) l else begin
-				if dce.debug then print_endline ("[DCE] Removed class " ^ (s_type_path c.cl_path));
-				loop acc l
+				(match c.cl_init with
+				| Some f when has_meta ":keepInit" c.cl_meta ->
+					(* it means that we only need the __init__ block *)
+					c.cl_extern <- true;
+					loop (mt :: acc) l
+				| _ ->
+					if dce.debug then print_endline ("[DCE] Removed class " ^ (s_type_path c.cl_path));
+					loop acc l)
 			end
  		| (TEnumDecl e) as mt :: l when has_meta ":used" e.e_meta || has_meta ":keep" e.e_meta || e.e_extern || not (dce.full || is_std_file dce e.e_module.m_extra.m_file) ->
 			loop (mt :: acc) l

+ 2 - 0
main.ml

@@ -538,6 +538,8 @@ and wait_loop boot_com host port =
 								| x :: l -> loop (x::acc) l
 							in
 							loop [] e.e_meta
+						| TAbstractDecl a ->
+							a.a_meta <- List.filter (fun (m,_,_) -> m <> ":valueUsed") a.a_meta
 						| _ -> ()
 					) m.m_types;
 					Typeload.add_module ctx m p;

+ 21 - 0
std/js/_std/Std.hx

@@ -21,6 +21,7 @@
  */
 import js.Boot;
 
+@:keepInit
 @:coreApi class Std {
 
 	public static inline function is( v : Dynamic, t : Dynamic ) : Bool {
@@ -91,6 +92,26 @@ import js.Boot;
 		__feature__("Void.*",{
 			var Void = __feature__("Type.resolveEnum", $hxClasses["Void"] = { __ename__ : ["Void"] }, { __ename__ : ["Void"] });
 		});
+		__feature__("Array.map",
+			if( Array.prototype.map == null )
+				Array.prototype.map = function(f) {
+					var a = [];
+					for( i in 0...__this__.length )
+						a[i] = f(__this__[i]);
+					return a;
+				}
+		);
+		__feature__("Array.filter",
+			if( Array.prototype.filter == null )
+				Array.prototype.filter = function(f) {
+					var a = [];
+					for( i in 0...__this__.length ) {
+						var e = __this__[i];
+						if( f(e) ) a.push(e);
+					}
+					return a;
+				}
+		);
 	}
 
 }