You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not clear why this is eaten up, the type of fields should be preserved.
Is there perhaps a smaller repro without JSX, e.g. whenever @string is inside a type definition or something?
@cknitt @mattdamon108 considering how brittle @string is, one possibility would be to:
1 Make a suggestion for alternative bindings that do not use this
2 Turn this use into a warning, or perhaps even an error
Thoughts?
In fact, longer term, review @int / @string in general see if it could be replaced completely or made more robust. For example, there's no reason one would not want the same kind of representation to be used when exporting to JS. The one-sided focus on importing does not seem to be justified.
If this is not possible to solve in the PPX (and I think it isn't?), then yes, only the two options described by @cristianoc remain:
Make this a warning or an error (I am leaning towards the latter). Include a suggestion for an alternative in the error message (just use [ | #default | #"light-content" | #"dark-content" ] in my above example). The problem with this approach is that, in order to upgrade to JSX v4, people will need to make sure that all of their project's dependencies have been updated accordingly.
Generalize @int / @string for polymorphic variants so that they work outside of external definitions, too. IMHO this would be the preferable solution, but I do not know how hard it would be to implement and if it would be doable in the scope of release 10.1.
A more elaborate (implementation-wise) version of 1 would be to auto-transform instead of (or in addition to) giving an error/warning. Bonus points: make this part of reformat so old style code gets reformatted to new style.
Slightly related: it would be nice to have a de-sugaring mode for debugging where all the transformations are performed at reformatting time, so one sees exactly what code gets generated (after JSX and other annotations are processed) without even leaving the editor.
I didn't look into the code related to @string and @int yet. Do we really need @string and @intinside even outside external? If it is possible to emit the expected js output with @as only, I think @string and @int don't need.
I always think the syntax needs to get more easier and easier for the newcomer and beginner. The fewer attributes make it more friendly to JS users.
There are several aspects about syntax, semantics, and backwards compatibility.
Conceptually, it seems like different aspects are mixed. One is the runtime representation of things, and this is one such example. Another aspect is the code generated, and things like @module are an example. The third one is FFI. Often these are mixed, as in this example, but they don't have to, in principle.
Attributes are not sticky: they are invisible things added on top, so it's easy to "lose" them. For example, if you add attributes to a type definition of a polymorphic variant type, such as the type for barStyle, they won't be propagated as every use of a polymorphic variant has its type inferred automatically. Contrast this with nominal type declarations such as records, where one can store arbitrary amount of information via attributes in a solid way.
In this case, attributes are picked up when attached to an external, as the external comes with a type declaration and no inference is performed. This gives a mechanism, but the mechanism is brittle, as it does not survive type aliasing.
What this means, is that it does not seem possible to salvage a mechanism such as this one for @string, associated with polymorphic variants, without making it fragile. So I think it should just be removed, as much as it is possible. Sometimes in future.
So there seems to be a bunch of exploration to be done beyond this specific issue.
What this means, is that it does not seem possible to salvage a mechanism such as this one for @string, associated with polymorphic variants, without making it fragile.
Ok, so then the only remaining cause of action is to produce an error when these attributes are used with JSX v4. This will avoid runtime errors and force library authors to update their libraries accordingly.
One needs to check carefully, but it is conceivable that they can just be deprecated and removed over time.
Right, there is no real need now anymore for this usage of @as (whether with @obj or with @react.component external definitions), except that maybe #lightContent is easier to type than #"light-content" (but I think for bindings it is preferable anyway to stay as close as possible to the JS original).
I guess for this issue, one can just start with a small step and remove them from component definitions.
I have not investigated all the uses of @string and @int for poly variants, but for the simples cases, both things are possible today:
letaa=#"this-or-that"letbb=#45
One needs to check carefully, but it is conceivable that they can just be deprecated and removed over time.
Frankly, I didn't know this usage yet #45. I think no need @string and @int, even @as for polymorphic variants. I'll look into it and remove it from external usage for component binding.
Activity
cristianoc commentedon Oct 8, 2022
Not clear why this is eaten up, the type of fields should be preserved.
Is there perhaps a smaller repro without JSX, e.g. whenever
@stringis inside a type definition or something?cknitt commentedon Oct 8, 2022
AFAIK this
@string/@asusage does not work as part of a normal type definition.It only works as part of an
externaldefinition, and JSX v3 is using@obj external makeProps ....cknitt commentedon Oct 8, 2022
See https://rescript-lang.org/try?code=C4TwDgpgBGBOD2YDOAoFABeAjAViiAHsBLAHYCGANlALbkDWEACgsgFxQAUKUUAflnKwAyqEoQO6JMFgBLUgHMeUANrLeAHygBiACYQAZuQCulYOqhb05JJwBElWQoAWwALQBjeKWI+7ASh1HF2AAYW9fc15NKGtbO10hek8IiD9AvSTwnzSoqABdAF4AfgAaZWNSWWBywMKAPhhWJChCqDs7NHFgKAJW2gZmZs4BIVEQcULM2HpsyNKuf380UEgoQRExaDapGXklNRi9QxMzZSsbe2DXFJz0oKdXOdzz2MuEpNvIgJ1EmeefCh8mhMLh8EQSBRqHRGCxEEgAEwcEYbcbiDiorYlBaVap1RpweH9DpdCA9ED9GFDeEIlFjLHTWapHwLThLFBAA
cristianoc commentedon Oct 8, 2022
This is how the result of processing looks like:
The type in question ends up as parameter to the type definition.
So it looks like a combination of:
@stringannotationSo that as soon as something changes this brittle usage breaks.
mununki commentedon Oct 9, 2022
Yes, I think this is why.
cristianoc commentedon Oct 9, 2022
@cknitt @mattdamon108 considering how brittle
@stringis, one possibility would be to:1 Make a suggestion for alternative bindings that do not use this
2 Turn this use into a warning, or perhaps even an error
Thoughts?
In fact, longer term, review
@int/@stringin general see if it could be replaced completely or made more robust. For example, there's no reason one would not want the same kind of representation to be used when exporting to JS. The one-sided focus on importing does not seem to be justified.cknitt commentedon Oct 9, 2022
If this is not possible to solve in the PPX (and I think it isn't?), then yes, only the two options described by @cristianoc remain:
Make this a warning or an error (I am leaning towards the latter). Include a suggestion for an alternative in the error message (just use
[ | #default | #"light-content" | #"dark-content" ]in my above example). The problem with this approach is that, in order to upgrade to JSX v4, people will need to make sure that all of their project's dependencies have been updated accordingly.Generalize
@int/@stringfor polymorphic variants so that they work outside ofexternaldefinitions, too. IMHO this would be the preferable solution, but I do not know how hard it would be to implement and if it would be doable in the scope of release 10.1.cristianoc commentedon Oct 9, 2022
A more elaborate (implementation-wise) version of 1 would be to auto-transform instead of (or in addition to) giving an error/warning. Bonus points: make this part of reformat so old style code gets reformatted to new style.
Slightly related: it would be nice to have a de-sugaring mode for debugging where all the transformations are performed at reformatting time, so one sees exactly what code gets generated (after JSX and other annotations are processed) without even leaving the editor.
mununki commentedon Oct 9, 2022
I didn't look into the code related to
@stringand@intyet. Do we really need@stringand@intinside even outside external? If it is possible to emit the expected js output with@asonly, I think@stringand@intdon't need.I always think the syntax needs to get more easier and easier for the newcomer and beginner. The fewer attributes make it more friendly to JS users.
cristianoc commentedon Oct 9, 2022
There are several aspects about syntax, semantics, and backwards compatibility.
Conceptually, it seems like different aspects are mixed. One is the runtime representation of things, and this is one such example. Another aspect is the code generated, and things like
@moduleare an example. The third one is FFI. Often these are mixed, as in this example, but they don't have to, in principle.Attributes are not sticky: they are invisible things added on top, so it's easy to "lose" them. For example, if you add attributes to a type definition of a polymorphic variant type, such as the type for
barStyle, they won't be propagated as every use of a polymorphic variant has its type inferred automatically. Contrast this with nominal type declarations such as records, where one can store arbitrary amount of information via attributes in a solid way.In this case, attributes are picked up when attached to an external, as the external comes with a type declaration and no inference is performed. This gives a mechanism, but the mechanism is brittle, as it does not survive type aliasing.
What this means, is that it does not seem possible to salvage a mechanism such as this one for
@string, associated with polymorphic variants, without making it fragile. So I think it should just be removed, as much as it is possible. Sometimes in future.So there seems to be a bunch of exploration to be done beyond this specific issue.
cristianoc commentedon Oct 9, 2022
I have not investigated all the uses of
@stringand@intfor poly variants, but for the simples cases, both things are possible today:One needs to check carefully, but it is conceivable that they can just be deprecated and removed over time.
cristianoc commentedon Oct 9, 2022
I guess for this issue, one can just start with a small step and remove them from component definitions.
cknitt commentedon Oct 9, 2022
Ok, so then the only remaining cause of action is to produce an error when these attributes are used with JSX v4. This will avoid runtime errors and force library authors to update their libraries accordingly.
Right, there is no real need now anymore for this usage of
@as(whether with@objor with@react.componentexternal definitions), except that maybe#lightContentis easier to type than#"light-content"(but I think for bindings it is preferable anyway to stay as close as possible to the JS original).If you are talking about rescript-react-native in particular, I have already done this, see rescript-react-native/rescript-react-native#770.
mununki commentedon Oct 9, 2022
Frankly, I didn't know this usage yet
#45. I think no need@stringand@int, even@asfor polymorphic variants. I'll look into it and remove it from external usage for component binding.EDIT: not remove it deprecate it first 😉
cknitt commentedon Oct 10, 2022
I think the following would be ideal:
cknitt commentedon Oct 10, 2022
BTW, regarding deprecating
@stringin externals altogether later on, there is also the usage for event listeners which will still be required: https://rescript-lang.org/docs/manual/latest/bind-to-js-function#special-case-event-listenersEmit an error when a @string or @int attribute is used in V4.
cknitt commentedon Oct 12, 2022
@cristianoc What about
? Don't we want to do that? Or do we do it later (in 11.0)?
cristianoc commentedon Oct 12, 2022
Forgot about this, but I guess we can deprecate all uses in 11.0, whether or not in a component.