aurelia / template-lint

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

#119 occurs again in 0.9.12 #124

Closed bondib closed 7 years ago

MeirionHughes commented 8 years ago

can you be more specific please, with succinct example? The spec for #119 is passing. i.e.

<template>      
  <button ref="someName" click.delegate="someMethod(someName.attributes['expanded'].value)">
  </button>
</template>`;

So I suspect there is a different use case.

bondib commented 8 years ago

This fails:

<button click.delegate="someMethod(ddDashboardListButtonRef.attributes['aria-expanded'].value)" 
                        ref="ddDashboardListButtonRef" type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown">

with:

cannot find 'ddDashboardListButtonRef' in type 'TYPE_NAME' ....

bondib commented 8 years ago

Not sure related but this started when I upgraded to node 6

MeirionHughes commented 8 years ago

you might fix this temporarily by moving ref="ddDashboardListButtonRef" to be the first attribute after <button.

MeirionHughes commented 8 years ago

I cannot duplicate the error; however, if you use ddDashboardListButtonRef anywhere else (not a child of the button) then 0.9.12 will fail. Also if you use ddDashboardListButtonRef before the button declaration, then it won't be found either.

MeirionHughes commented 8 years ago

try 0.9.13.

if that still causes issues for you then you'll have to make failing test for me to reproduce.

  //#124
  it("ref variable not found", (done) => {
    let viewmodel = `
    export class Foo{
      someMethod(value){}
    }`;
    let view = `
    <template>  
      <button click.delegate="someMethod(ddDashboardListButtonRef.attributes['aria-expanded'].value)" 
         ref="ddDashboardListButtonRef" 
         type="button" 
         class="btn btn-sm btn-default dropdown-toggle" 
         data-toggle="dropdown">    
    </template>`;
    let reflection = new Reflection();
    let rule = new BindingRule(reflection);
    let linter = new Linter([rule]);
    reflection.add("./foo.ts", viewmodel);
    linter.lint(view, "./foo.html")
      .then((issues) => {
        try {
          expect(issues.length).toBe(0);
        }
        catch (err) { fail(err); }
        finally { done(); }
      });
  });
bondib commented 8 years ago

I'm on node 6.7.0 as well. Well, if I move the ref to be the first attribute - it passes. So the issue occurs if the ref part is after the use of it.

MeirionHughes commented 8 years ago

sorting the attributes so that ref is resolved first, should have been done since 0.9.9 and it does appear to work if I add this to the specs.

I've been having issues with npm and its cache too; so you may have to clear everything: User/{yourname}/AppData/Roaming/npm-cache then reinstall (after rimraf node_modules).