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

Commit fabc6ab

Browse files
committed
fix($injector): workaround for MS Edge class detection
Fix for MS Edge class detection Closes: #13697
1 parent 93c7251 commit fabc6ab

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

src/auto/injector.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,10 @@ function createInjector(modulesToLoad, strictDi) {
826826
if (msie <= 11) {
827827
return false;
828828
}
829+
// Workaround for MS Edge.
830+
// Check https://connect.microsoft.com/IE/Feedback/Details/2211653
829831
return typeof func === 'function'
830-
&& /^class\s/.test(Function.prototype.toString.call(func));
832+
&& /^(?:class\s|constructor\()/.test(Function.prototype.toString.call(func));
831833
}
832834

833835
function invoke(fn, self, locals, serviceName) {

test/auto/injectorSpec.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
/* globals support: false */
4+
35
describe('injector', function() {
46
var providers;
57
var injector;
@@ -247,42 +249,47 @@ describe('injector', function() {
247249
});
248250

249251

250-
// Only Chrome and Firefox support this syntax.
251-
if (/chrome|firefox/i.test(navigator.userAgent)) {
252-
describe('es6', function() {
253-
/*jshint -W061 */
252+
describe('es6', function() {
253+
/*jshint -W061 */
254+
if (support.ES6Function) {
254255
// The functions are generated using `eval` as just having the ES6 syntax can break some browsers.
255256
it('should be possible to annotate functions that are declared using ES6 syntax', function() {
256257
expect(annotate(eval('({ fn(x) { return; } })').fn)).toEqual(['x']);
257258
});
259+
}
258260

259261

262+
if (support.fatArrow) {
260263
it('should create $inject for arrow functions', function() {
261264
expect(annotate(eval('(a, b) => a'))).toEqual(['a', 'b']);
262265
});
266+
}
263267

264268

269+
if (support.fatArrow) {
265270
it('should create $inject for arrow functions with no parenthesis', function() {
266271
expect(annotate(eval('a => a'))).toEqual(['a']);
267272
});
273+
}
268274

269275

276+
if (support.fatArrow) {
270277
it('should take args before first arrow', function() {
271278
expect(annotate(eval('a => b => b'))).toEqual(['a']);
272279
});
280+
}
273281

282+
if (support.classes) {
274283
it('should be possible to instantiate ES6 classes', function() {
275-
// Only Chrome (not even the FF we use) supports ES6 classes.
276-
if (!/chrome/i.test(navigator.userAgent)) return;
277284
providers('a', function() { return 'a-value'; });
278285
var clazz = eval('(class { constructor(a) { this.a = a; } aVal() { return this.a; } })');
279286
var instance = injector.instantiate(clazz);
280287
expect(instance).toEqual({a: 'a-value'});
281288
expect(instance.aVal()).toEqual('a-value');
282289
});
283-
/*jshint +W061 */
284-
});
285-
}
290+
}
291+
/*jshint +W061 */
292+
});
286293

287294

288295
it('should publish annotate API', function() {

test/helpers/testabilityPatch.js

+22
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@ if (window._jQuery) _jQuery.event.special.change = undefined;
1111

1212
if (window.bindJQuery) bindJQuery();
1313

14+
var supportTests = {
15+
classes: '(class {})',
16+
fatArrow: 'a => a',
17+
ES6Function: '({ fn(x) { return; } })'
18+
};
19+
20+
var support = {};
21+
22+
for (var prop in supportTests) {
23+
if (supportTests.hasOwnProperty(prop)) {
24+
/*jshint -W061 */
25+
try {
26+
eval(supportTests[prop]);
27+
support[prop] = true;
28+
} catch (e) {
29+
support[prop] = false;
30+
}
31+
/*jshint +W061 */
32+
}
33+
}
34+
35+
1436
beforeEach(function() {
1537

1638
// all this stuff is not needed for module tests, where jqlite and publishExternalAPI and jqLite are not global vars

0 commit comments

Comments
 (0)