From 61f9fe9e664ada53518679e8060deba2839793c7 Mon Sep 17 00:00:00 2001 From: mgechev Date: Sun, 7 May 2017 19:21:15 -0700 Subject: [PATCH] fix: ignore re-defined variables Fix #220 --- src/templatesUsePublicRule.ts | 5 +++++ test/templatesUsePublicRule.spec.ts | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/templatesUsePublicRule.ts b/src/templatesUsePublicRule.ts index d62886f40..6c1997fc3 100644 --- a/src/templatesUsePublicRule.ts +++ b/src/templatesUsePublicRule.ts @@ -34,6 +34,11 @@ class SymbolAccessValidator extends RecursiveAngularExpressionVisitor { } ast = 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) { diff --git a/test/templatesUsePublicRule.spec.ts b/test/templatesUsePublicRule.spec.ts index a54863988..c91eeff1b 100644 --- a/test/templatesUsePublicRule.spec.ts +++ b/test/templatesUsePublicRule.spec.ts @@ -180,7 +180,6 @@ describe('templates-use-public', () => { assertSuccess('templates-use-public', source); }); - it('should succeed on public nested props', () => { let source = ` @Component({ @@ -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: \` +
+ +
+ \` + }) + class Test { + smile: any; + }`; + assertSuccess('templates-use-public', source); + }); }); });