|
@@ -65,12 +65,6 @@ class ExampleJSGenerator {
|
|
|
print(api.generateValue(e));
|
|
|
}
|
|
|
|
|
|
- @:macro static function fprint( e : Expr ) {
|
|
|
- var pos = haxe.macro.Context.currentPos();
|
|
|
- var ret = haxe.macro.Format.format(e);
|
|
|
- return { expr : ECall({ expr : EConst(CIdent("print")), pos : pos },[ret]), pos : pos };
|
|
|
- }
|
|
|
-
|
|
|
function field(p) {
|
|
|
return api.isKeyword(p) ? '["' + p + '"]' : "." + p;
|
|
|
}
|
|
@@ -84,10 +78,10 @@ class ExampleJSGenerator {
|
|
|
continue;
|
|
|
packages.set(full, true);
|
|
|
if( prev == null )
|
|
|
- fprint("if(typeof $x=='undefined') $x = {}");
|
|
|
+ print('if(typeof $x==\'undefined\') $x = {}');
|
|
|
else {
|
|
|
var p = prev + field(x);
|
|
|
- fprint("if(!$p) $p = {}");
|
|
|
+ print('if(!$p) $p = {}');
|
|
|
}
|
|
|
newline();
|
|
|
}
|
|
@@ -105,7 +99,7 @@ class ExampleJSGenerator {
|
|
|
function genClassField( c : ClassType, p : String, f : ClassField ) {
|
|
|
checkFieldName(c, f);
|
|
|
var field = field(f.name);
|
|
|
- fprint("$p.prototype$field = ");
|
|
|
+ print('$p.prototype$field = ');
|
|
|
var e = f.expr();
|
|
|
if( e == null )
|
|
|
print("null");
|
|
@@ -120,11 +114,11 @@ class ExampleJSGenerator {
|
|
|
var field = field(f.name);
|
|
|
var e = f.expr();
|
|
|
if( e == null ) {
|
|
|
- fprint("$p$field = null");
|
|
|
+ print('$p$field = null');
|
|
|
newline();
|
|
|
} else switch( f.kind ) {
|
|
|
case FMethod(_):
|
|
|
- fprint("$p$field = ");
|
|
|
+ print('$p$field = ');
|
|
|
genExpr(e);
|
|
|
newline();
|
|
|
default:
|
|
@@ -136,20 +130,20 @@ class ExampleJSGenerator {
|
|
|
genPackage(c.pack);
|
|
|
api.setCurrentClass(c);
|
|
|
var p = getPath(c);
|
|
|
- fprint("$p = $$hxClasses['$p'] = ");
|
|
|
+ print('$p = $$hxClasses[\'$p\'] = ');
|
|
|
if( c.constructor != null )
|
|
|
genExpr(c.constructor.get().expr());
|
|
|
else
|
|
|
print("function() { }");
|
|
|
newline();
|
|
|
var name = p.split(".").map(api.quoteString).join(",");
|
|
|
- fprint("$p.__name__ = [$name]");
|
|
|
+ print('$p.__name__ = [$name]');
|
|
|
newline();
|
|
|
if( c.superClass != null ) {
|
|
|
var psup = getPath(c.superClass.t.get());
|
|
|
- fprint("$p.__super__ = $psup");
|
|
|
+ print('$p.__super__ = $psup');
|
|
|
newline();
|
|
|
- fprint("for(var k in $psup.prototype ) $p.prototype[k] = $psup.prototype[k]");
|
|
|
+ print('for(var k in $psup.prototype ) $p.prototype[k] = $psup.prototype[k]');
|
|
|
newline();
|
|
|
}
|
|
|
for( f in c.statics.get() )
|
|
@@ -162,12 +156,12 @@ class ExampleJSGenerator {
|
|
|
}
|
|
|
genClassField(c, p, f);
|
|
|
}
|
|
|
- fprint("$p.prototype.__class__ = $p");
|
|
|
+ print('$p.prototype.__class__ = $p');
|
|
|
newline();
|
|
|
if( c.interfaces.length > 0 ) {
|
|
|
var me = this;
|
|
|
var inter = c.interfaces.map(function(i) return me.getPath(i.t.get())).join(",");
|
|
|
- fprint("$p.__interfaces__ = [$inter]");
|
|
|
+ print('$p.__interfaces__ = [$inter]');
|
|
|
newline();
|
|
|
}
|
|
|
}
|
|
@@ -177,28 +171,28 @@ class ExampleJSGenerator {
|
|
|
var p = getPath(e);
|
|
|
var names = p.split(".").map(api.quoteString).join(",");
|
|
|
var constructs = e.names.map(api.quoteString).join(",");
|
|
|
- fprint("$p = $$hxClasses['$p'] = { __ename__ : [$names], __constructs__ : [$constructs] }");
|
|
|
+ print('$p = $$hxClasses[\'$p\'] = { __ename__ : [$names], __constructs__ : [$constructs] }');
|
|
|
newline();
|
|
|
for( c in e.constructs.keys() ) {
|
|
|
var c = e.constructs.get(c);
|
|
|
var f = field(c.name);
|
|
|
- fprint("$p$f = ");
|
|
|
+ print('$p$f = ');
|
|
|
switch( c.type ) {
|
|
|
case TFun(args, _):
|
|
|
var sargs = args.map(function(a) return a.name).join(",");
|
|
|
- fprint('function($sargs) { var $$x = ["${c.name}",${c.index},$sargs]; $$x.__enum__ = $p; $$x.toString = $$estr; return $$x; }');
|
|
|
+ print('function($sargs) { var $$x = ["${c.name}",${c.index},$sargs]; $$x.__enum__ = $p; $$x.toString = $$estr; return $$x; }');
|
|
|
default:
|
|
|
print("[" + api.quoteString(c.name) + "," + c.index + "]");
|
|
|
newline();
|
|
|
- fprint("$p$f.toString = $$estr");
|
|
|
+ print('$p$f.toString = $$estr');
|
|
|
newline();
|
|
|
- fprint("$p$f.__enum__ = $p");
|
|
|
+ print('$p$f.__enum__ = $p');
|
|
|
}
|
|
|
newline();
|
|
|
}
|
|
|
var meta = api.buildMetaData(e);
|
|
|
if( meta != null ) {
|
|
|
- fprint("$p.__meta__ = ");
|
|
|
+ print('$p.__meta__ = ');
|
|
|
genExpr(meta);
|
|
|
newline();
|
|
|
}
|
|
@@ -208,7 +202,7 @@ class ExampleJSGenerator {
|
|
|
function genStaticValue( c : ClassType, cf : ClassField ) {
|
|
|
var p = getPath(c);
|
|
|
var f = field(cf.name);
|
|
|
- fprint("$p$f = ");
|
|
|
+ print('$p$f = ');
|
|
|
genExpr(cf.expr());
|
|
|
newline();
|
|
|
}
|