-
-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[js] enum-as-object cleanup wishlist #7165
Comments
Yes $ prefix is a better escaping sequence for JS output since it's not a valid Haxe identifier |
Another thing - since we have |
…ses (see #7165) also, inline Type.resolve(Enum|Class)
… (see #7165) so we don't repeat it twice
It's better now: var E = $hxEnums["E"] = { __ename__ : true, __constructs__ : ["A","B"] };
E.A = {_hx_index:0,__enum__:"E",toString:$estr};
E.B = ($_=function(v) { return {_hx_index:1,v:v,__enum__:"E",toString:$estr}; },$_.__params__ = ["v"],$_); still need to rename the fields ( another idea is to merge the declarations into one object, so we don't repeat the type name at all: var E = {
__constructs__: ["A", "B"],
A: {$index: 0, $enum: "E"},
B: ($_=function(v) { return {$index: 1, $enum: "E", v:v} },$_.__params__=["v"],$_),
} |
$enum and $index is good for me. and yes the litteral declaration seems better |
Do you still want to do something here for 4.0? |
I wanted to unify impl fields to use |
Also I don't like the fact that So if there are no arguments against changing this, I'll do this at some point when I have time for it :) |
So I diffed the output with the new object-based enums and it looks great, however it increases code size in real-world cases quite a bit and I think we can do something about it:
generates
could be optimized to
Basically we don't want to repat the type/ctor name too much because in real code it would be something like
rambo_ResourceChangeReason.ClanwarAttackMaterialPurchase
.Another thing that makes me uncomfortable is the naming inconsistency here. We have
_hx_index
, but also__enum__
and$hxEnums
. I feel like it would be better to use the$ident
scheme for everything as this would also exclude the possibility of name clashes coming from weirdly-named identifiers in Haxe code.So something like
E.A = {$enum: "E", $index: 0, toString: $estr};
. I think it would also look better when using the enum objects from plain JavaScript, as the$
-fields look like special tag fields while non-$
-fields contain data.Thoughts?
The text was updated successfully, but these errors were encountered: