Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'templates-use-public' throws error when attempting to access a property of a property with the [] syntax #315

Closed
TomCaserta opened this issue Jun 6, 2017 · 2 comments
Assignees
Labels

Comments

@TomCaserta
Copy link

TomCaserta commented Jun 6, 2017

Rule: templates-use-public
Codealyzer Version: 3.0.1
Angular Version: 4.1.3

Minimal Snippet

Interface:

interface Something {
    a;
    b;
}

@Component({
    template: '<span>{{ something[0].a }}</span>'
})
export class DemoComponent {
    public something: Something[] = [{ a: 1, b: 2 }];
}

Class:

class Something {
    public a = 1;
    public b = 2;
}

@Component({
    template: '<span>{{ something[0].a }}</span>'
})
export class DemoComponent {
    public something: Something[] = [new Something()];
}

No class/interface definition:

@Component({
    template: '<span>{{ something["a"].b }}</span>'
})
export class DemoComponent {
    public something: { a: any } = { a: { b: 1 } };
}

Error Displayed

Cannot parse the template of DemoComponent TypeError: Cannot read property 'name' of undefined
    at SymbolAccessValidator.doCheck (/path/to/project/node_modules/codelyzer/templatesUsePublicRule.js:36:37)
    at SymbolAccessValidator.visitPropertyRead (/path/to/project/node_modules/codelyzer/templatesUsePublicRule.js:24:21)
    at PropertyRead.visit (/path/to/project/node_modules/@angular/compiler/@angular/compiler.es5.js:2540:15)
    at SymbolAccessValidator.RecursiveAngularExpressionVisitor.visit (/path/to/project/node_modules/codelyzer/angular/templates/recursiveAngularExpressionVisitor.js:18:13)
    at /path/to/project/node_modules/codelyzer/angular/templates/recursiveAngularExpressionVisitor.js:46:64
    at Array.forEach (native)
    at SymbolAccessValidator.RecursiveAngularExpressionVisitor.visitInterpolation (/path/to/project/node_modules/codelyzer/angular/templates/recursiveAngularExpressionVisitor.js:46:25)
    at Interpolation.visit (/path/to/project/node_modules/@angular/compiler/@angular/compiler.es5.js:2758:23)
    at SymbolAccessValidator.RecursiveAngularExpressionVisitor.visit (/path/to/project/node_modules/codelyzer/angular/templates/recursiveAngularExpressionVisitor.js:18:13)
    at BasicTemplateAstVisitor.visitNgTemplateAST (/path/to/project/node_modules/codelyzer/angular/templates/basicTemplateAstVisitor.js:67:25)
    at BasicTemplateAstVisitor.visitBoundText (/path/to/project/node_modules/codelyzer/angular/templates/basicTemplateAstVisitor.js:111:18)
    at BoundTextAst.visit (/path/to/project/node_modules/@angular/compiler/bundles/compiler.umd.js:87:24)
    at BasicTemplateAstVisitor.visit (/path/to/project/node_modules/codelyzer/angular/templates/basicTemplateAstVisitor.js:71:14)
    at /path/to/project/node_modules/codelyzer/angular/templates/basicTemplateAstVisitor.js:89:62
    at Array.forEach (native)
    at BasicTemplateAstVisitor.visitElement (/path/to/project/node_modules/codelyzer/angular/templates/basicTemplateAstVisitor.js:89:26)
@mgechev
Copy link
Owner

mgechev commented Jun 6, 2017

Thanks for reporting the issue. Will fix it as soon as possible and release a fix.

@mgechev mgechev self-assigned this Jun 7, 2017
@mgechev mgechev added this to the 3.1.0 - Alan Turing milestone Jun 7, 2017
@mgechev
Copy link
Owner

mgechev commented Jun 9, 2017

@TomCaserta cannot reproduce the issue #318

@mgechev mgechev closed this as completed Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants