Now I need to pinch myself. Is it really true that calling an non-existing ppx by writing
@asdadasda
does not cause compilation error?!! Wut…
Now I need to pinch myself. Is it really true that calling an non-existing ppx by writing
@asdadasda
does not cause compilation error?!! Wut…
if you mean the @ident
syntax.
They are not ppx annotations. they are annotations (or attributes, decorators).
Annotations let you add information to different items in your code. they can be processed/used by the compiler (@unboxed
, @unwrap
…) or other exetrnal tools (gentype, reanalyze, …).
You can even make internal tools (used by your team) to make use of annotations.
Oookay. I see. And fwiw I think it’s very cool it’s possible to define custom annotations. But the compiler should surely know what annotations it can handle and what not, right?
I just caught a bug in my code where I used React-Intl like this (no error):
module Messages = {
@@intl.messages
let title = { .. }
}
I’m just saying that if critical code is generated with annotations (e.g. @react.component
, @genType
, @intl.messages
, etc etc), it will be a colossal source of bugs if typos in those are not caught in compile time. Or am I missing something relevant here?
in case of @gentype
and @react.component
you’d get type erros at usage time.
for example if you mis-type @react.component
on top of your make function you will get error when you try to use the component.
module Foo = {
@react.comonen
let make = () => React.null
}
let a = <Foo />
gentype has similiar story.
I don’t remember if there was a way to whitelist annotations. it’s not a bad idea to have this feature , maybe via configuration (though it might get complicated since they can accpet arguments).
anyway it’s an advanced feature and should be used with care.
Yeah, you’re right that some typos get immediately caught because immediate problems follow from them (like with @react.component
. But it would be dangerous to assume that’s always the case.
Now I wonder what is the role of ppx-flags
in bsconfig. I assumed that was the white list. It wasn’t? Or has it changed in ReScript?
According to the configuration-schema docs, the ppx-flags
option is used to hook up ppx binaries:
PPXes only search the AST for their specific decorators. There is no tracked list of all hooked up decorators in the compiler afaik (and I think this is also not really possible, bc ppxes are independent binaries).
ppx
's usually operate on extension points such as %graphql("...")
. If they are not being handled there is an error. Annotations are not required to be handled by a ppx