aurelia / template-lint

Sanity check of Aurelia-flavor template HTML
Apache License 2.0
56 stars 17 forks source link

report invalid references from `@computedFrom` #128

Open atsu85 opened 7 years ago

atsu85 commented 7 years ago

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

atsu85 commented 7 years ago

I'll send a PR with test soon

atsu85 commented 7 years ago

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

MeirionHughes commented 7 years ago

okay, that is good enough; I'll mark it for revisit at a later date. thx,

atsu85 commented 7 years ago

@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?

MeirionHughes commented 7 years ago

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);

MeirionHughes commented 7 years ago

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.