refactor($parse): change 'this' to a $parse keyword instead of scope field

BREAKING CHANGE:
- $scope['this'] no longer exits on the $scope object
- $parse-ed expressions no longer allow chaining 'this' such as this['this'] or $parent['this']
- 'this' in $parse-ed expressions can no longer be overriden, if a variable named 'this' is put on the scope it must be accessed using this['this']

Closes #9105
This commit is contained in:
Jason Bedard
2014-09-13 11:51:30 -07:00
committed by Igor Minar
parent 4a6c7cf8ce
commit 5572b40b15
3 changed files with 25 additions and 4 deletions

View File

@@ -51,8 +51,25 @@ describe('Scope', function() {
describe('this', function() {
it('should have a \'this\'', inject(function($rootScope) {
expect($rootScope['this']).toEqual($rootScope);
it('should evaluate \'this\' to be the scope', inject(function($rootScope) {
var child = $rootScope.$new();
expect($rootScope.$eval('this')).toEqual($rootScope);
expect(child.$eval('this')).toEqual(child);
}));
it('\'this\' should not be recursive', inject(function($rootScope) {
expect($rootScope.$eval('this.this')).toBeUndefined();
expect($rootScope.$eval('$parent.this')).toBeUndefined();
}));
it('should not be able to overwrite the \'this\' keyword', inject(function($rootScope) {
$rootScope['this'] = 123;
expect($rootScope.$eval('this')).toEqual($rootScope);
}));
it('should be able to access a variable named \'this\'', inject(function($rootScope) {
$rootScope['this'] = 42;
expect($rootScope.$eval('this[\'this\']')).toBe(42);
}));
});