Skip to content

Commit

Permalink
fix: proper check for public members
Browse files Browse the repository at this point in the history
Fix #206
  • Loading branch information
mgechev committed Dec 31, 2016
1 parent 5a012d7 commit cc3ed9a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/templatesUsePublicRule.ts
Expand Up @@ -37,10 +37,8 @@ class SymbolAccessValidator extends RecursiveAngularExpressionVisitor {
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) {
let isPublic = !member.modifiers;
if (member.modifiers) {
isPublic = member.modifiers.some(m => m.kind === SyntaxKind.current().PublicKeyword);
}
let isPublic = !member.modifiers || !member.modifiers
.some(m => m.kind === SyntaxKind.current().PrivateKeyword || m.kind === SyntaxKind.current().ProtectedKeyword);
const width = ast.name.length;
if (!isPublic) {
const failureString = 'You can bind only to public class members.';
Expand Down
21 changes: 21 additions & 0 deletions test/noAccessMissingMemberRule.spec.ts
Expand Up @@ -723,6 +723,27 @@ describe('no-access-missing-member', () => {
}`;
assertSuccess('no-access-missing-member', source);
});


// it('should succeed with array element access', () => {
// let source = `
// @Component({
// template: '<div *ngIf="context"></div>'
// })
// class Test {
// }`;
// assertFailure('no-access-missing-member', source, {
// message: 'The property "context" that you\'re trying to access does not exist in the class declaration.',
// startPosition: {
// line: 2,
// character: 23
// },
// endPosition: {
// line: 2,
// character: 24
// }
// });
// });
// TODO
// it('should work with getters', () => {
// let source = `
Expand Down
13 changes: 13 additions & 0 deletions test/templatesUsePublicRule.spec.ts
Expand Up @@ -209,5 +209,18 @@ describe('templates-use-public', () => {
}`;
assertSuccess('templates-use-public', source);
});


it('should succeed on public nested props', () => {
let source = `
@Component({
selector: 'foobar',
template: '<div>{{ foo }}</div>
})
class Test {
readonly foo: any;
}`;
assertSuccess('templates-use-public', source);
});
});
});

0 comments on commit cc3ed9a

Please sign in to comment.