Improve template errors detection during compile time.
slavap opened this issue · 2 comments
Not sure it's even possible, but would be nice to have. First the code:
public enum JqmButtonSize {
SMALL("sm"), LARGE("lg");
private final String bsSize;
private JqmButtonSize(String bsSize) {
this.bsSize = bsSize;
}
@JsMethod public String getBsSize() {
return bsSize;
}
}
@Component
public class JqmButton extends VueComponent {
@Prop @JsProperty JqmButtonSize size;
@Computed public String getCalcSize() {
return size != null ? size.getBsSize() : "";
}
}
And then it's used like:
<vue-gwt:import class="com.vx.JqmButtonSize" />
<jqm-button variant="primary" :size="JqmButtonSize.LARGE">Abc</jqm-button>
Probably there is a way to eliminate a need for manual vue-gwt:import, but anyway it works.
Then let's pretend we did some mistakes in template.
In case :size="aaa" we are getting error "Couldn't find variable/method "aaa" in the Component." during compile time, which is good.
But in case :size="222" we are not getting any error during compile time, but getting it in runtime, like "[Vue warn]: Error in render: "TypeError: this.size.getBsSize is not a function", which is too late and not very informative. IMO it would be nice to improve template generator to catch as much as possible Java types errors during compile time.
Yes the @Prop
binding is not yet validated at compile time. This is one of the issues that we want to fix.
It will be possible to fix it for locally imported Components, because we can access the imported Component class and get the type of the prop. Then we can simply use this type as the return type of the method generated for the template expression of that prop and it will break at compile time if you are passing something invalid.
Sadly for globally registered components (registered with Vue.component("my-component", MyComponent.class)
), or components from a JS library, that won't be possible as we won't have the class in the annotation processor.
@adrienbaron Tested in beta6-snapshot, works fine, in case of :size="222" now gives: [ERROR] Line 39: Type mismatch: cannot convert from int to JqmButtonSize