This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
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
Closed
gkalpak
wants to merge
1
commit into
angular:master
from
gkalpak:fix-injector-cope-with-Chrome-stringification-bug-2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,12 +70,16 @@ var FN_ARG = /^\s*(_?)(\S+?)\1\s*$/; | |
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; | ||
var $injectorMinErr = minErr('$injector'); | ||
|
||
function extractArgs(fn) { | ||
function stringifyFn(fn) { | ||
// Support: Chrome 50-51 only | ||
// Creating a new string by adding `' '` at the end, to hack around some bug in Chrome v50/51 | ||
// (See https://github.com/angular/angular.js/issues/14487.) | ||
// TODO (gkalpak): Remove workaround when Chrome v52 is released | ||
var fnText = Function.prototype.toString.call(fn).replace(STRIP_COMMENTS, '') + ' ', | ||
return Function.prototype.toString.call(fn) + ' '; | ||
} | ||
|
||
function extractArgs(fn) { | ||
var fnText = stringifyFn(fn).replace(STRIP_COMMENTS, ''), | ||
args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS); | ||
return args; | ||
} | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. In the regex, let's replace
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant to do it as part of this PR, but forgot. |
||
} | ||
return result; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. +1 :-) |
||
// TODO (gkalpak): Remove when Chrome v52 is relased. | ||
// it('should be able to inject fat-arrow function', function() { | ||
// inject(($injector) => { | ||
// expect($injector).toBeDefined(); | ||
// }); | ||
// }); | ||
} | ||
|
||
if (support.classes) { | ||
|
@@ -293,6 +301,19 @@ describe('injector', function() { | |
expect(instance).toEqual(new Clazz('a-value')); | ||
expect(instance.aVal()).toEqual('a-value'); | ||
}); | ||
|
||
// Support: Chrome 50-51 only | ||
// TODO (gkalpak): Remove when Chrome v52 is relased. | ||
// it('should be able to invoke classes', function() { | ||
// class Test { | ||
// constructor($injector) { | ||
// this.$injector = $injector; | ||
// } | ||
// } | ||
// var instance = injector.invoke(Test, null, null, 'Test'); | ||
|
||
// expect(instance.$injector).toBe(injector); | ||
// }); | ||
} | ||
/*jshint +W061 */ | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.