-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($injector): add workaround for class stringification in Chrome v50/51 #14531
fix($injector): add workaround for class stringification in Chrome v50/51 #14531
Conversation
…0/51 Partially fixes angular#14240.
@@ -283,6 +283,14 @@ describe('injector', function() { | |||
it('should take args before first arrow', function() { | |||
expect(annotate(eval('a => b => b'))).toEqual(['a']); | |||
}); | |||
|
|||
// Support: Chrome 50-51 only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 :-)
Assuming the CI build passes this LGTM |
@@ -849,7 +853,7 @@ function createInjector(modulesToLoad, strictDi) { | |||
if (!isBoolean(result)) { | |||
// Workaround for MS Edge. | |||
// Check https://connect.microsoft.com/IE/Feedback/Details/2211653 | |||
result = func.$$ngIsClass = /^(?:class\s|constructor\()/.test(Function.prototype.toString.call(func)); | |||
result = func.$$ngIsClass = /^(?:class\s|constructor\()/.test(stringifyFn(func)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the regex, let's replace \s
with \b
. Otherwise it doesn't work in the situations like following:
class{ ... }
class/* foo */ Bar { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to do it as part of this PR, but forgot.
I will submit a new one.
@@ -849,7 +853,7 @@ function createInjector(modulesToLoad, strictDi) { | |||
if (!isBoolean(result)) { | |||
// Workaround for MS Edge. | |||
// Check https://connect.microsoft.com/IE/Feedback/Details/2211653 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could change the comment at the same time to:
// Support: Edge 12-13 only
// See https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/6156135/
It's fixed in the Edge preview and the bug has moved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too late 😛
Will do in a follow-up PR.
Follow-up: #14533 |
Mentioned in #14531 (comment). Closes #14533
Mentioned in #14531 (comment). Closes #14533
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.
What is the current behavior? (You can also link to an open issue here)
In Chrome v50, the
$injector
fails to properly detect classes and throws when trying toinvoke
a class.See #14240 (especially #14240 (comment) and #14240 (comment)).
What is the new behavior (if this is a feature change)?
Classes are detected and
$injetor.invoke
d correctly.Does this PR introduce a breaking change?
No
Please check if the PR fulfills these requirements
Tests for the changes have been added (for bug fixes / features)Docs have been added / updated (for bug fixes / features)Other information:
Everything works correctly on v52 without the fix. Not sure about v51.
We can't run the tests on CI, because the problem appears only when creating a class directly (not through
eval()
). I added a couple of commented out tests, so it is easy to test once Chrome v52 is released (as stable). (I left a TODO note to remove them.)Partially fixes #14240.