template-lint
template-lint copied to clipboard
report invalid references from `@computedFrom`
Following
export class Foo{
field1: number;
field2: number;
@computedFrom("field1", "missingField1", "field2", "missingField2")
get computedField(){
return this.field1 + this.field2;
}
}
<template>
\${computedField}
</template>
should report that missingField1 and missingField2 can't be found in type Foo
I'll send a PR with test soon
The PR is ready to be merged - it currently works with simple expressions (such as @computedFrom("field1", "missingField1")), but ignores expressions containing ., such as @computedFrom("item.field") - I think it could be left to another PR
okay, that is good enough; I'll mark it for revisit at a later date. thx,
@MeirionHughes, I just started investigating how to check "item.field" - any hints? I probably need to create AccessMember expression out of string "item.field", as it is done here, or how would You approach it?
You're probably be better off passing it through the attribute one instead; the text node approach would require interpolation. (you could wrap the string with ${_expression_} to make it work) either way is a little hacky.
let info: any = this.bindingLanguage.inspectAttribute(this.resources, "none", "bind", value); if (info) instruction = this.bindingLanguage.createAttributeInstruction(this.resources, { tagName: "none"}, info, undefined);
Disabled this as of 0.9.18. will reimplement in reworked code.
This line https://github.com/MeirionHughes/aurelia-template-lint/blob/develop/source/rules/binding.ts#L504 results in errors if the property is part of a class that is imported by the view-model.
In reworked code its easier to break this up into two processes: firstly to check that that view->viewmodel link is valid, in html file checks; and secondly to check the @computedFrom decorators, when processing source files.