Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d713ad1

Browse files
committed
fix(ngRepeat): allow aliasAs identifiers which contain but do not match reserved words
Currently if a reserved word occurs anywhere within the aliasAs identifier, we throw. This CL fixes this behaviour by allowing these identifiers, since they are technically perfectly valid. Closes #8729
1 parent 066c049 commit d713ad1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Diff for: src/ng/directive/ngRepeat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
267267
var keyIdentifier = match[2];
268268

269269
if (aliasAs && (!/^[$a-zA-Z_][$a-zA-Z0-9_]*$/.test(aliasAs) ||
270-
/^null|undefined|this|\$index|\$first|\$middle|\$last|\$even|\$odd|\$parent$/.test(aliasAs))) {
270+
/^(null|undefined|this|\$index|\$first|\$middle|\$last|\$even|\$odd|\$parent)$/.test(aliasAs))) {
271271
throw ngRepeatMinErr('badident', "alias '{0}' is invalid --- must be a valid JS identifier which is not a reserved name.",
272272
aliasAs);
273273
}

Diff for: test/ng/directive/ngRepeatSpec.js

+30
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,36 @@ describe('ngRepeat', function() {
418418
});
419419

420420

421+
it('should support alias identifiers containing reserved words', inject(function($exceptionHandler) {
422+
scope.x = 'bl';
423+
scope.items = [
424+
{ name : 'red' },
425+
{ name : 'blue' },
426+
{ name : 'green' },
427+
{ name : 'black' },
428+
{ name : 'orange' },
429+
{ name : 'blonde' }
430+
];
431+
forEach([
432+
'null2',
433+
'qthis',
434+
'qthisq',
435+
'fundefined',
436+
'$$parent'
437+
], function(name) {
438+
var expr = 'item in items | filter:x as ' + name + ' track by $index';
439+
element = $compile('<div><div ng-repeat="' + expr + '"></div></div>')(scope);
440+
scope.$digest();
441+
expect(scope[name]).toEqual([
442+
{ name: 'blue' },
443+
{ name: 'black' },
444+
{ name: 'blonde' }
445+
]);
446+
dealoc(element);
447+
});
448+
}));
449+
450+
421451
it('should throw if alias identifier is not a simple identifier', inject(function($exceptionHandler) {
422452
scope.x = 'bl';
423453
scope.items = [

0 commit comments

Comments
 (0)