Browse Source

[js] Avoid optimizing Std.is away in api_inline. (#12133)

This allows deprecation checks to run.
Codegen does not change as Std.is is inline and calls Std.isOfType
which is still special-cased.
(Std.isOfType itself still needs to be special-cased despite calling js.Boot.__instanceof because otherwise exception codegen changes slightly)
Added a codegen test and a test to verify the deprecation warning triggers.
Zeta 3 tháng trước cách đây
mục cha
commit
e73e7cf25d

+ 1 - 1
src/optimization/inline.ml

@@ -125,7 +125,7 @@ let api_inline (scom : SafeCom.t) c field params p =
 	let tint = scom.basic.tint in
 	let tint = scom.basic.tint in
 
 
 	match c.cl_path, field, params with
 	match c.cl_path, field, params with
-	| ([],"Std"),("is" | "isOfType"),[o;t] | (["js"],"Boot"),"__instanceof",[o;t] when scom.platform = Js ->
+	| ([],"Std"),"isOfType",[o;t] | (["js"],"Boot"),"__instanceof",[o;t] when scom.platform = Js ->
 		let is_trivial e =
 		let is_trivial e =
 			match e.eexpr with
 			match e.eexpr with
 			| TConst _ | TLocal _ -> true
 			| TConst _ | TLocal _ -> true

+ 3 - 0
tests/misc/js/projects/Issue10870/Main.hx

@@ -0,0 +1,3 @@
+function main() {
+	Std.is("", String);
+}

+ 3 - 0
tests/misc/js/projects/Issue10870/compile.hxml

@@ -0,0 +1,3 @@
+-m Main
+-js out.js
+--no-output

+ 1 - 0
tests/misc/js/projects/Issue10870/compile.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:2: characters 2-20 : Warning : (WDeprecated) Std.is is deprecated. Use Std.isOfType instead.

+ 8 - 0
tests/optimization/src/TestJs.hx

@@ -742,6 +742,14 @@ class TestJs {
 			offset = 3;
 			offset = 3;
 		} while (notFalse);
 		} while (notFalse);
 	}
 	}
+
+	@:js('
+		return typeof("") == "string";
+	')
+	@:haxe.warning("-WDeprecated")
+	static function testIs() {
+		return Std.is("", String);
+	}
 }
 }
 
 
 class Issue9227 {
 class Issue9227 {