Skip to content

Commit

Permalink
fix(allow-template-call-expression): allow $any in expressions (#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattlewis92 authored and mgechev committed Jan 30, 2019
1 parent 0ed079f commit a75c204
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/noTemplateCallExpressionRule.ts
Expand Up @@ -33,14 +33,18 @@ class TemplateVisitor extends BasicTemplateAstVisitor {
}

class ExpressionVisitor extends RecursiveAngularExpressionVisitor {
private allowedMethodNames = ['$any'];

visitFunctionCall(node: e.FunctionCall, context: any) {
this.addFailureFromStartToEnd(node.span.start, node.span.end, Rule.FAILURE_STRING);

super.visitFunctionCall(node, context);
}

visitMethodCall(node: e.MethodCall, context: any) {
this.addFailureFromStartToEnd(node.span.start, node.span.end, Rule.FAILURE_STRING);
if (this.allowedMethodNames.indexOf(node.name) === -1) {
this.addFailureFromStartToEnd(node.span.start, node.span.end, Rule.FAILURE_STRING);
}

super.visitMethodCall(node, context);
}
Expand Down
10 changes: 10 additions & 0 deletions test/noTemplateCallExpressionRule.spec.ts
Expand Up @@ -21,6 +21,16 @@ describe('no-template-call-expression', () => {
`;
assertSuccess('no-template-call-expression', source);
});

it('should allow $any to wrap unknown variables', () => {
let source = `
@Component({
template: '{{$any(info)}}'
})
class Bar {}
`;
assertSuccess('no-template-call-expression', source);
});
});

describe('failure', () => {
Expand Down

0 comments on commit a75c204

Please sign in to comment.