DoclerLabs / hexMachina

Releases, issues, documentation, website of hexMachina, framework written in Haxe
http://hexmachina.org
MIT License
44 stars 8 forks source link

Strong restrictions to what is allowed in anonymous objects. #294

Closed back2dos closed 6 years ago

back2dos commented 6 years ago

Currently it seems like something of this kind is not possible:

foo = new Foo({
   bar: Std.string(5)
});

With:

class Foo {
    public function new(o:{ bar: String }) {}
}

Seems that's because for EObjectDecl the field expressions are passed through parseProperty which appears to be very restricted.

Would be nice if anything that is a valid "value" in flow (i.e. can be on the right side of a declaration) would be valid in an anonymous object too.

FrancisBourre commented 6 years ago

I cover many more new cases. Check example below. Don't hesitate to report some missing ones.

@context( name = 'applicationContext' )
{
    @public
    foo = new hex.mock.ConstructorWithAnonStruct( { s: Std.string(5) } );

    @public
    o = { s: Std.string(5) };

    @public
    o2 = { s: foo.getString() };

    @public
    foo2 = new hex.mock.ConstructorWithAnonStruct( { s: foo.getString() } );

    @public
    foo3 = new hex.mock.ConstructorWithAnonStruct( { s: closure() } );

    closure = foo.getString.bind();
}