2
0
Эх сурвалжийг харах

moved haxe.macro.Tools.includeFile to haxe.macro.Compiler and enabled 'using' usage of haxe.macro.Tools

Simon Krajewski 12 жил өмнө
parent
commit
2cfddbe2a2

+ 21 - 0
std/haxe/macro/Compiler.hx

@@ -268,6 +268,27 @@ class Compiler {
 	public static function setCustomJSGenerator( callb : JSGenApi -> Void ) {
 		load("custom_js",1)(callb);
 	}
+	
+	#if (js || macro)
+	/**
+		Embed an on-disk javascript file (can be called into an __init__ method)
+	**/
+	@:macro public static function includeFile( fileName : Expr ) {
+		var str = switch( fileName.expr ) {
+		case EConst(c):
+			switch( c ) {
+			case CString(str): str;
+			default: null;
+			}
+		default: null;
+		}
+		if( str == null ) Context.error("Should be a constant string", fileName.pos);
+		var f = try sys.io.File.getContent(Context.resolvePath(str)) catch( e : Dynamic ) Context.error(Std.string(e), fileName.pos);
+		var p = Context.currentPos();
+		return { expr : EUntyped( { expr : ECall( { expr : EConst(CIdent("__js__")), pos : p }, [ { expr : EConst(CString(f)), pos : p } ]), pos : p } ), pos : p };
+	}
+	#end
+	
 
 	static function load( f, nargs ) : Dynamic {
 		#if macro

+ 5 - 28
std/haxe/macro/Tools.hx

@@ -20,34 +20,11 @@
  * DEALINGS IN THE SOFTWARE.
  */
 package haxe.macro;
-#if macro
-import haxe.macro.Expr;
-#end
 
 /**
-	Some macro utility methods that can be used on different platforms
+	This class can be added via 'using haxe.macro.Tools' in order to enable
+	'using' functionality on all macro tool classes listed below.
 **/
-#if !macro extern #end
-class Tools {
-
-	#if (js || macro)
-	/**
-		Embed an on-disk javascript file (can be called into an __init__ method)
-	**/
-	@:macro public static function includeFile( fileName : Expr ) {
-		var str = switch( fileName.expr ) {
-		case EConst(c):
-			switch( c ) {
-			case CString(str): str;
-			default: null;
-			}
-		default: null;
-		}
-		if( str == null ) Context.error("Should be a constant string", fileName.pos);
-		var f = try sys.io.File.getContent(Context.resolvePath(str)) catch( e : Dynamic ) Context.error(Std.string(e), fileName.pos);
-		var p = Context.currentPos();
-		return { expr : EUntyped( { expr : ECall( { expr : EConst(CIdent("__js__")), pos : p }, [ { expr : EConst(CString(f)), pos : p } ]), pos : p } ), pos : p };
-	}
-	#end
-
-}
+typedef TExprTools = ExprTools;
+typedef TComplexTypeTools = ComplexTypeTools;
+typedef TTypeTools = TypeTools;