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

Commit 046b771

Browse files
welborniobtford
authored andcommitted
chore: update property chain check for ng-events
1 parent e7fa5ed commit 046b771

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/modules/events.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,19 @@ function ngEventDirectivesDecorator(ngEventAttrName) {
4848
return function ngEventHandler(scope, element, attrs) {
4949
var boundFuncs = getFunctionNames(attrs[ngEventAttrName]);
5050
boundFuncs.forEach(function(boundFn) {
51-
if ($parse(boundFn)(scope) === undefined) {
52-
angular.hint.log(MODULE_NAME, boundFn + ' is undefined');
51+
var property, propChain, lastProp = '';
52+
while((property = boundFn.match(/^.+?([^\.\[])*/)) !== null) {
53+
property = property[0];
54+
propChain = lastProp + property;
55+
if ($parse(propChain)(scope) === undefined) {
56+
angular.hint.log(MODULE_NAME, propChain + ' is undefined');
57+
}
58+
boundFn = boundFn.replace(property, '');
59+
lastProp += property;
60+
if(boundFn.charAt(0) === '.') {
61+
lastProp += '.';
62+
boundFn = boundFn.substr(1);
63+
}
5364
}
5465
});
5566

test/events.spec.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,28 @@ describe('hintEvents', function() {
2626
});
2727

2828
// TODO: implement this
29-
xit('should log a message if the path to handle an ng-event is not found', function() {
29+
it('should log a message if the path to handle an ng-event is not found', function() {
3030
var elt = angular.element('<button ng-click="a.b.c()">Fake Increment</button>');
3131
$compile(elt)($rootScope);
3232
$rootScope.a = {};
3333

3434
$rootScope.$digest();
3535
elt.triggerHandler('click');
36+
// expect(angular.hint.log).not.toHaveBeenCalledWith('Events', 'a is undefined');
3637
expect(angular.hint.log).toHaveBeenCalledWith('Events', 'a.b is undefined');
38+
expect(angular.hint.log).toHaveBeenCalledWith('Events', 'a.b.c is undefined');
39+
});
40+
41+
it('should log a message if the path to handle an ng-event with array syntax is not found', function() {
42+
var elt = angular.element('<button ng-click="a[\'b\'].c()">Fake Increment</button>');
43+
$compile(elt)($rootScope);
44+
$rootScope.a = {};
45+
46+
$rootScope.$digest();
47+
elt.triggerHandler('click');
48+
// expect(angular.hint.log).not.toHaveBeenCalledWith('Events', 'a is undefined');
49+
expect(angular.hint.log).toHaveBeenCalledWith('Events', 'a[\'b\'] is undefined');
50+
expect(angular.hint.log).toHaveBeenCalledWith('Events', 'a[\'b\'].c is undefined');
3751
});
3852

3953

0 commit comments

Comments
 (0)