Skip to content

Commit c633b96

Browse files
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 6cadabf commit c633b96

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
@@ -684,7 +684,7 @@ function parser(text, json, $filter, csp){
684684
var argsFn = [];
685685
if (peekToken().text != ')') {
686686
do {
687-
argsFn.push(expression());
687+
argsFn.push(filterChain());
688688
} while (expect(','));
689689
}
690690
consume(')');

test/ng/parseSpec.js

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

314+
it('should parse filters as method parameters', function() {
315+
$filterProvider.register('substring', valueFn(function(input, start, end) {
316+
return input.substring(start, end);
317+
}));
318+
319+
scope.offset = 3;
320+
321+
scope.echo1 = function(substring) {
322+
return substring;
323+
};
324+
325+
expect(scope.$eval("echo1(('abcd'|substring:1:offset))")).toEqual("bc");
326+
expect(scope.$eval("echo1('abcd'|substring:1:offset)")).toEqual("bc");
327+
328+
scope.echo2 = function(lowercaseSubstring,uppercaseSubstring) {
329+
return lowercaseSubstring+uppercaseSubstring;
330+
};
331+
332+
expect(scope.$eval("echo2(('abcd'|substring:1:offset),('abcd'|substring:1:3|uppercase))")).toEqual("bcBC");
333+
expect(scope.$eval("echo2('abcd'|substring:1:offset,'abcd'|substring:1:3|uppercase)")).toEqual("bcBC");
334+
335+
expect(scope.$eval("echo2('',('abcd'|substring:1:3|uppercase))")).toEqual("BC");
336+
expect(scope.$eval("echo2('','abcd'|substring:1:3|uppercase)")).toEqual("BC");
337+
338+
expect(scope.$eval("echo2(null,('abcd'|substring:1:3|uppercase))")).toEqual("nullBC");
339+
expect(scope.$eval("echo2(null,'abcd'|substring:1:3|uppercase)")).toEqual("nullBC");
340+
341+
expect(scope.$eval("echo2(undefined,('abcd'|substring:1:3|uppercase))")).toEqual("undefinedBC");
342+
expect(scope.$eval("echo2(undefined,'abcd'|substring:1:3|uppercase)")).toEqual("undefinedBC");
343+
344+
expect(scope.$eval("echo2(('abcd'|substring:1:offset),null)")).toEqual("bcnull");
345+
expect(scope.$eval("echo2('abcd'|substring:1:offset,null)")).toEqual("bcnull");
346+
347+
expect(scope.$eval("echo2(('abcd'|substring:1:offset),undefined)")).toEqual("bcundefined");
348+
expect(scope.$eval("echo2('abcd'|substring:1:offset,undefined)")).toEqual("bcundefined");
349+
});
350+
314351
it('should access scope', function() {
315352
scope.a = 123;
316353
scope.b = {c: 456};

0 commit comments

Comments
 (0)