darklua
darklua copied to clipboard
Generic type parameter values with parenthese types cause invalid syntax
When processing a type like this:
type _fieldDefStack = Array<GraphQLField<any, any>? | NULL>
Darklua currently adds parentheses around GraphQLField<any, any>?
which creates invalid syntax:
type _fieldDefStack = Array<(GraphQLField<any, any>?) | NULL> -- invalid in Luau!
This is odd because the syntax defines type params as:
TypeParams = (Type | TypePack | VariadicTypePack | GenericTypePack) [',' TypeParams]
Which makes ``(GraphQLField<any, any>?) | NULL` a valid type. Luau also agrees that this is correct syntax, as it accepts this type declaration:
type _fieldDefStack = (GraphQLField<any, any>?) | NULL
It seems like the fix for this would be to wrap the type params values in a parenthese when they contain a type union or intersection where the left side type is a parenthese type. Weirdly specific thing to add, but I think it'll do it.