瀏覽代碼

[js] Cleanup some unused code (#7528)

* [js][dce] only emit fromCodePoint polyfill when fromCharCode used (requires #7527)

* [js][dce] only emit $hxEnums declaration when required
George Corney 7 年之前
父節點
當前提交
885a35b06f
共有 3 個文件被更改,包括 4 次插入4 次删除
  1. 1 1
      src/generators/genjs.ml
  2. 2 2
      std/js/_std/String.hx
  3. 1 1
      std/js/_std/Type.hx

+ 1 - 1
src/generators/genjs.ml

@@ -1490,7 +1490,7 @@ let generate com =
 	let vars = if has_feature ctx "has_enum"
 		then ("$estr = function() { return " ^ (ctx.type_accessor (TClassDecl { null_class with cl_path = ["js"],"Boot" })) ^ ".__string_rec(this,''); }") :: vars
 		else vars in
-	let vars = if enums_as_objects then "$hxEnums = $hxEnums || {}" :: vars else vars in
+	let vars = if (enums_as_objects && (has_feature ctx "has_enum" || has_feature ctx "Type.resolveEnum")) then "$hxEnums = $hxEnums || {}" :: vars else vars in
 	let vars,has_dollar_underscore =
 		if List.exists (function TEnumDecl { e_extern = false } -> true | _ -> false) com.types then
 			"$_" :: vars,true

+ 2 - 2
std/js/_std/String.hx

@@ -41,11 +41,11 @@
 	}
 
 	@:pure static inline function fromCharCode( code : Int ) : String {
-		return js.Syntax.code("String.fromCodePoint({0})",code); 
+		return untyped __define_feature__('String.fromCharCode', js.Syntax.code("String.fromCodePoint({0})", code));
 	}
 	
 	static function __init__() : Void {
-		js.Syntax.code("if( String.fromCodePoint == null ) String.fromCodePoint = function(c) { return c < 0x10000 ? String.fromCharCode(c) : String.fromCharCode((c>>10)+0xD7C0)+String.fromCharCode((c&0x3FF)+0xDC00); }");
+		untyped __feature__('String.fromCharCode', js.Syntax.code("if( String.fromCodePoint == null ) String.fromCodePoint = function(c) { return c < 0x10000 ? String.fromCharCode(c) : String.fromCharCode((c>>10)+0xD7C0)+String.fromCharCode((c&0x3FF)+0xDC00); }"));
 	}
 	
 }

+ 1 - 1
std/js/_std/Type.hx

@@ -83,7 +83,7 @@ enum ValueType {
 	}
 
 	public static inline function resolveEnum( name : String ) : Enum<Dynamic> {
-		return untyped $hxEnums[name];
+		return untyped __define_feature__("Type.resolveEnum", $hxEnums[name]);
 	}
 	#end