Browse Source

[macro] add TypeTools.toBaseType() (#11153)

Rudy Ges 2 years ago
parent
commit
9a9571439a
1 changed files with 12 additions and 0 deletions
  1. 12 0
      std/haxe/macro/TypeTools.hx

+ 12 - 0
std/haxe/macro/TypeTools.hx

@@ -398,6 +398,18 @@ class TypeTools {
 		#end
 	}
 
+	/**
+		Converts type `t` to `haxe.macro.Type.BaseType`.
+	**/
+	static public function toBaseType(t:Type):BaseType {
+		return switch toModuleType(t) {
+			case TClassDecl(_.get() => c): c;
+			case TEnumDecl(_.get() => e): e;
+			case TTypeDecl(_.get() => t): t;
+			case TAbstract(_.get() => a): a;
+		};
+	}
+
 	/**
 		Calls `f` for each missing `TypeParameter` within Type `type`.
 		The `Type` returned from `f` fills the vacant parameter in a