Skip to content

Commit 852d723

Browse files
committed
fix(hint): do not crash
Somewhere between v0.14.4 and v4.0.0, `EventEmitter2` started being inconsistent wrt to the arguments passed to the `onAny()` listener; sometimes the `eventType` is passed as the first argument, sometimes it isn't. This caused batarang to crash. This commit fixes it, by accounting for the fact that `eventType` might or might not be passed as a first argument. Fixes angular#310
1 parent 60342ed commit 852d723

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

dist/hint.js

100755100644
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@
77
require('./loader.js');
88
require('angular-hint');
99

10-
angular.hint.onAny(function (data, severity) {
10+
angular.hint.onAny(function (event, data, severity) {
11+
// EventEmitter2 usually omits the event type for the argument list (assigning it to `this.event`
12+
// instead), but under certain circumstances it may include it.
13+
if (this.event !== event) {
14+
severity = data;
15+
data = event;
16+
event = this.event;
17+
}
18+
1119
window.postMessage({
1220
__fromBatarang: true,
13-
module: this.event.split(':')[0],
14-
event: this.event,
21+
module: event.split(':')[0],
22+
event: event,
1523
data: data,
1624
severity: severity
1725
}, '*');

hint.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
*/
66
require('./loader.js');
77
require('angular-hint');
8+
9+
angular.hint.onAny(function (event, data, severity) {
10+
// EventEmitter2 usually omits the event type for the argument list (assigning it to `this.event`
11+
// instead), but under certain circumstances it may include it.
12+
if (this.event !== event) {
13+
severity = data;
14+
data = event;
15+
event = this.event;
16+
}
817

9-
angular.hint.onAny(function (data, severity) {
1018
window.postMessage({
11-
__fromBatarang: true,
12-
module: this.event.split(':')[0],
13-
event: this.event,
19+
__fromBatarang: true,
20+
module: event.split(':')[0],
21+
event: event,
1422
data: data,
1523
severity: severity
1624
}, '*');

0 commit comments

Comments
 (0)