fix($compile): workaround for IE11 MutationObserver

Backport #11796 to 1.2 branch.
IE11 MutationObserver breaks consecutive text nodes into several text nodes.
This patch merges consecutive text nodes into a single node before looking for interpolations.
Also had to modify npm-shrinkwrap.json because i@0.3.2 was unpublished from npm.

Closes #11781
Closes #12613
This commit is contained in:
Scott Davidson
2015-08-18 14:01:56 +01:00
committed by Martin Staffa
parent b041b66475
commit fccce96d44
3 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -3705,7 +3705,7 @@
"version": "0.2.1"
},
"i": {
"version": "0.3.2"
"version": "0.3.3"
},
"mkdirp": {
"version": "0.4.0"
+7
View File
@@ -1088,6 +1088,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}
break;
case 3: /* Text Node */
if (msie === 11) {
// Workaround for #11781
while (node.parentNode && node.nextSibling && node.nextSibling.nodeType === 3 /* Text Node */) {
node.nodeValue = node.nodeValue + node.nextSibling.nodeValue;
node.parentNode.removeChild(node.nextSibling);
}
}
addTextInterpolateDirective(directives, node.nodeValue);
break;
case 8: /* Comment */
+17
View File
@@ -2214,6 +2214,23 @@ describe('$compile', function() {
'</select>');
}));
it('should handle consecutive text elements as a single text element', inject(function($rootScope, $compile) {
// No point it running the test, if there is no MutationObserver
if (!window.MutationObserver) return;
// Create and register the MutationObserver
var observer = new window.MutationObserver(noop);
observer.observe(document.body, {childList: true, subtree: true});
// Run the actual test
var base = jqLite('<div>&mdash; {{ "This doesn\'t." }}</div>');
element = $compile(base)($rootScope);
$rootScope.$digest();
expect(element.text()).toBe("— This doesn't.");
// Unregister the MutationObserver (and hope it doesn't mess up with subsequent tests)
observer.disconnect();
}));
it('should support custom start/end interpolation symbols in template and directive template',
function() {