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

Commit c855c3f

Browse files
committed
fix($injector): fix class detection RegExp
Mentioned in #14531 (comment). Closes #14533
1 parent f6c3b35 commit c855c3f

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/auto/injector.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,9 @@ function createInjector(modulesToLoad, strictDi) {
855855
}
856856
var result = func.$$ngIsClass;
857857
if (!isBoolean(result)) {
858-
// Workaround for MS Edge.
859-
// Check https://connect.microsoft.com/IE/Feedback/Details/2211653
860-
result = func.$$ngIsClass = /^(?:class\s|constructor\()/.test(stringifyFn(func));
858+
// Support: Edge 12-13 only
859+
// See: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/6156135/
860+
result = func.$$ngIsClass = /^(?:class\b|constructor\()/.test(stringifyFn(func));
861861
}
862862
return result;
863863
}

test/auto/injectorSpec.js

+20
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,26 @@ describe('injector', function() {
302302
expect(instance.aVal()).toEqual('a-value');
303303
});
304304

305+
if (/chrome/.test(navigator.userAgent)) {
306+
they('should detect ES6 classes regardless of whitespace/comments ($prop)', [
307+
'class Test {}',
308+
'class Test{}',
309+
'class //<--ES6 stuff\nTest {}',
310+
'class//<--ES6 stuff\nTest {}',
311+
'class {}',
312+
'class{}',
313+
'class //<--ES6 stuff\n {}',
314+
'class//<--ES6 stuff\n {}',
315+
'class/* Test */{}',
316+
'class /* Test */ {}'
317+
], function(classDefinition) {
318+
var Clazz = eval('(' + classDefinition + ')');
319+
var instance = injector.invoke(Clazz);
320+
321+
expect(instance).toEqual(jasmine.any(Clazz));
322+
});
323+
}
324+
305325
// Support: Chrome 50-51 only
306326
// TODO (gkalpak): Remove when Chrome v52 is relased.
307327
// it('should be able to invoke classes', function() {

0 commit comments

Comments
 (0)