Skip to content

Commit 5f0c0db

Browse files
esarbanisEfthymis Sarbanis
authored and
Efthymis Sarbanis
committed
fix(parse): changed the functionCall method to parse filters
Added a condition to allow the parser to understand whether the parameter is a filter Closes angular#4168
1 parent 1f6a5a1 commit 5f0c0db

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/ng/parse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ Parser.prototype = {
698698
var argsFn = [];
699699
if (this.peekToken().text !== ')') {
700700
do {
701-
argsFn.push(this.expression());
701+
argsFn.push(this.filterChain());
702702
} while (this.expect(','));
703703
}
704704
this.consume(')');

test/ng/parseSpec.js

+37
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,43 @@ describe('parser', function() {
339339
expect(scope.$eval("'abcd'|substring:1:3|uppercase")).toEqual("BC");
340340
});
341341

342+
it('should parse filters as method parameters', function() {
343+
$filterProvider.register('substring', valueFn(function(input, start, end) {
344+
return input.substring(start, end);
345+
}));
346+
347+
scope.offset = 3;
348+
349+
scope.echo1 = function(substring) {
350+
return substring;
351+
};
352+
353+
expect(scope.$eval("echo1(('abcd'|substring:1:offset))")).toEqual("bc");
354+
expect(scope.$eval("echo1('abcd'|substring:1:offset)")).toEqual("bc");
355+
356+
scope.echo2 = function(lowercaseSubstring,uppercaseSubstring) {
357+
return lowercaseSubstring+uppercaseSubstring;
358+
};
359+
360+
expect(scope.$eval("echo2(('abcd'|substring:1:offset),('abcd'|substring:1:3|uppercase))")).toEqual("bcBC");
361+
expect(scope.$eval("echo2('abcd'|substring:1:offset,'abcd'|substring:1:3|uppercase)")).toEqual("bcBC");
362+
363+
expect(scope.$eval("echo2('',('abcd'|substring:1:3|uppercase))")).toEqual("BC");
364+
expect(scope.$eval("echo2('','abcd'|substring:1:3|uppercase)")).toEqual("BC");
365+
366+
expect(scope.$eval("echo2(null,('abcd'|substring:1:3|uppercase))")).toEqual("nullBC");
367+
expect(scope.$eval("echo2(null,'abcd'|substring:1:3|uppercase)")).toEqual("nullBC");
368+
369+
expect(scope.$eval("echo2(undefined,('abcd'|substring:1:3|uppercase))")).toEqual("undefinedBC");
370+
expect(scope.$eval("echo2(undefined,'abcd'|substring:1:3|uppercase)")).toEqual("undefinedBC");
371+
372+
expect(scope.$eval("echo2(('abcd'|substring:1:offset),null)")).toEqual("bcnull");
373+
expect(scope.$eval("echo2('abcd'|substring:1:offset,null)")).toEqual("bcnull");
374+
375+
expect(scope.$eval("echo2(('abcd'|substring:1:offset),undefined)")).toEqual("bcundefined");
376+
expect(scope.$eval("echo2('abcd'|substring:1:offset,undefined)")).toEqual("bcundefined");
377+
});
378+
342379
it('should access scope', function() {
343380
scope.a = 123;
344381
scope.b = {c: 456};

0 commit comments

Comments
 (0)