Skip to content

Commit

Permalink
fix($injector): fix class detection RegExp
Browse files Browse the repository at this point in the history
  • Loading branch information
gkalpak committed Apr 28, 2016
1 parent afcedff commit 03b9807
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/auto/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,10 @@ function createInjector(modulesToLoad, strictDi) {
}
var result = func.$$ngIsClass;
if (!isBoolean(result)) {
// Support: Edge 12-13 only
// Workaround for MS Edge.
// Check https://connect.microsoft.com/IE/Feedback/Details/2211653
result = func.$$ngIsClass = /^(?:class\s|constructor\()/.test(stringifyFn(func));
// See: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/6156135/
result = func.$$ngIsClass = /^(?:class\b|constructor\()/.test(stringifyFn(func));
}
return result;
}
Expand Down
13 changes: 13 additions & 0 deletions test/auto/injectorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@ describe('injector', function() {
expect(instance.aVal()).toEqual('a-value');
});

they('should detect ES6 classes regardless of whitespace/comments ($prop)', [
'class Test {}',
'class Test{}',
'class {}',
'class{}',
'class/* Test */{}'
], function(classDefinition) {
var Clazz = eval('(' + classDefinition + ')');
var instance = injector.invoke(Clazz);

expect(instance).toEqual(jasmine.any(Clazz));
});

// Support: Chrome 50-51 only
// TODO (gkalpak): Remove when Chrome v52 is relased.
// it('should be able to invoke classes', function() {
Expand Down

0 comments on commit 03b9807

Please sign in to comment.