Skip to content

Commit

Permalink
fix: ignore re-defined variables
Browse files Browse the repository at this point in the history
Fix #220
  • Loading branch information
mgechev committed May 8, 2017
1 parent 0fcdcd1 commit 61f9fe9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/templatesUsePublicRule.ts
Expand Up @@ -34,6 +34,11 @@ class SymbolAccessValidator extends RecursiveAngularExpressionVisitor {
}
ast = <e.PropertyRead>receiver;
}
// We have the variable re-declared in the template
// which makes it automatically public.
if (this.preDefinedVariables[ast.name]) {
return;
}
const allMembers = getDeclaredMethods(this.context.controller).concat(getDeclaredProperties(this.context.controller));
const member = allMembers.filter((m: any) => m.name && m.name.text === ast.name).pop();
if (member) {
Expand Down
17 changes: 16 additions & 1 deletion test/templatesUsePublicRule.spec.ts
Expand Up @@ -180,7 +180,6 @@ describe('templates-use-public', () => {
assertSuccess('templates-use-public', source);
});


it('should succeed on public nested props', () => {
let source = `
@Component({
Expand All @@ -192,5 +191,21 @@ describe('templates-use-public', () => {
}`;
assertSuccess('templates-use-public', source);
});

it.only('should succeed shadowed variable', () => {
let source = `
@Component({
selector: 'foobar',
template: \`
<div *ngFor="let smile of smile">
<smile-cmp [smile]="smile"></smile-cmp>
</div>
\`
})
class Test {
smile: any;
}`;
assertSuccess('templates-use-public', source);
});
});
});

0 comments on commit 61f9fe9

Please sign in to comment.